Beispiel #1
0
        SidePacket BuildSidePacket(ImageSource imageSource)
        {
            var sidePacket = new SidePacket();

            SetImageTransformationOptions(sidePacket, imageSource);
            sidePacket.Emplace("model_complexity", new IntPacket((int)modelComplexity));
            sidePacket.Emplace("smooth_landmarks", new BoolPacket(smoothLandmarks));

            return(sidePacket);
        }
Beispiel #2
0
        SidePacket BuildSidePacket(ImageSource imageSource)
        {
            var sidePacket = new SidePacket();

            SetImageTransformationOptions(sidePacket, imageSource);
            sidePacket.Emplace("allowed_labels", new StringPacket(GetAllowedLabels(category)));
            sidePacket.Emplace("max_num_objects", new IntPacket(maxNumObjects));

            return(sidePacket);
        }
Beispiel #3
0
        public void size_ShouldReturnSize_When_AfterPacketsAreEmplaced()
        {
            var sidePacket  = new SidePacket();
            var flagPacket  = new BoolPacket(true);
            var valuePacket = new FloatPacket(1.0f);

            sidePacket.Emplace("flag", flagPacket);
            sidePacket.Emplace("value", valuePacket);

            Assert.AreEqual(sidePacket.size, 2);
        }
Beispiel #4
0
        public void Clear_ShouldClearAllKeys_When_SizeIsNotZero()
        {
            var sidePacket = new SidePacket();

            sidePacket.Emplace("flag", new BoolPacket(true));
            sidePacket.Emplace("value", new FloatPacket(1.0f));
            Assert.AreEqual(sidePacket.size, 2);

            sidePacket.Clear();
            Assert.AreEqual(sidePacket.size, 0);
        }
Beispiel #5
0
        public void Emplace_ShouldIgnoreValue_When_KeyExists()
        {
            using (var sidePacket = new SidePacket())
            {
                var oldValuePacket = new FloatPacket(1.0f);
                sidePacket.Emplace("value", oldValuePacket);
                Assert.AreEqual(1.0f, sidePacket.At <FloatPacket, float>("value").Get());

                var newValuePacket = new FloatPacket(2.0f);
                sidePacket.Emplace("value", newValuePacket);
                Assert.AreEqual(1.0f, sidePacket.At <FloatPacket, float>("value").Get());
            }
        }
Beispiel #6
0
        public void Size_ShouldReturnSize_When_AfterPacketsAreEmplaced()
        {
            using (var sidePacket = new SidePacket())
            {
                var flagPacket  = new BoolPacket(true);
                var valuePacket = new FloatPacket(1.0f);
                sidePacket.Emplace("flag", flagPacket);
                sidePacket.Emplace("value", valuePacket);

                Assert.AreEqual(2, sidePacket.size);
                Assert.True(flagPacket.isDisposed);
                Assert.True(valuePacket.isDisposed);
            }
        }
Beispiel #7
0
        SidePacket BuildSidePacket(ImageSource imageSource)
        {
            var sidePacket = new SidePacket();

            SetImageTransformationOptions(sidePacket, imageSource, true);
            sidePacket.Emplace("output_rotation", new IntPacket((int)imageSource.rotation));
            sidePacket.Emplace("num_hands", new IntPacket(maxNumHands));

            if (configType == ConfigType.OpenGLES)
            {
                sidePacket.Emplace(destinationBufferName, outputGpuBufferPacket);
            }

            return(sidePacket);
        }
 public void ValidateRequiredSidePackets_ShouldReturnOk_When_AllTheRequiredSidePacketsAreGiven()
 {
     using (var config = new ValidatedGraphConfig())
     {
         config.Initialize(CalculatorGraphConfig.Parser.ParseFromTextFormat(_ObjectronConfigText)).AssertOk();
         using (var sidePacket = new SidePacket())
         {
             sidePacket.Emplace("allowed_labels", new StringPacket("cup"));
             sidePacket.Emplace("max_num_objects", new IntPacket(3));
             using (var status = config.ValidateRequiredSidePackets(sidePacket))
             {
                 Assert.True(status.Ok());
             }
         }
     }
 }
    public override Status StartRun(Texture texture)
    {
        Debug.Log("This graph is for testing official examples. You can customize the graph by editing `official_demo_android.txt` (default is `hand_tracking_mobile.pbtxt`)");

        sidePacket = new SidePacket();
        sidePacket.Emplace("num_hands", new IntPacket(2));

        destinationNativeTexturePtr = texture.GetNativeTexturePtr();
        destinationWidth            = texture.width;
        destinationHeight           = texture.height;

        gpuHelper.RunInGlContext(BuildDestination).AssertOk();
        sidePacket.Emplace(destinationBufferName, outputPacket);

        return(graph.StartRun(sidePacket));
    }
Beispiel #10
0
    public override Status StartRun()
    {
        handLandmarksStreamPoller = graph.AddOutputStreamPoller <List <NormalizedLandmarkList> >(handLandmarksStream).ConsumeValueOrDie();
        handLandmarksPacket       = new NormalizedLandmarkListVectorPacket();

        handednessStreamPoller = graph.AddOutputStreamPoller <List <ClassificationList> >(handednessStream).ConsumeValueOrDie();
        handednessPacket       = new ClassificationListVectorPacket();

        palmDetectionsStreamPoller = graph.AddOutputStreamPoller <List <Detection> >(palmDetectionsStream).ConsumeValueOrDie();
        palmDetectionsPacket       = new DetectionVectorPacket();

        palmRectsStreamPoller = graph.AddOutputStreamPoller <List <NormalizedRect> >(palmRectsStream).ConsumeValueOrDie();
        palmRectsPacket       = new NormalizedRectVectorPacket();

        handLandmarksPresenceStreamPoller = graph.AddOutputStreamPoller <bool>(handLandmarksPresenceStream).ConsumeValueOrDie();
        handLandmarksPresencePacket       = new BoolPacket();

        palmDetectionsPresenceStreamPoller = graph.AddOutputStreamPoller <bool>(palmDetectionsPresenceStream).ConsumeValueOrDie();
        palmDetectionsPresencePacket       = new BoolPacket();

        sidePacket = new SidePacket();
        sidePacket.Emplace("num_hands", new IntPacket(2));

        return(graph.StartRun(sidePacket));
    }
 public void ValidateRequiredSidePackets_ShouldReturnInvalidArgumentError_When_TheSidePacketValuesAreWrong()
 {
     using (var config = new ValidatedGraphConfig())
     {
         config.Initialize(CalculatorGraphConfig.Parser.ParseFromTextFormat(_ObjectronConfigText)).AssertOk();
         using (var sidePacket = new SidePacket())
         {
             sidePacket.Emplace("allowed_labels", new StringPacket("cup"));
             sidePacket.Emplace("max_num_objects", new StringPacket("3"));
             using (var status = config.ValidateRequiredSidePackets(sidePacket))
             {
                 Assert.AreEqual(Status.StatusCode.InvalidArgument, status.Code());
             }
         }
     }
 }
    public override Status StartRun(Texture texture)
    {
        Debug.Log("This graph is for testing official examples. You can customize the graph by editing `official_demo_*.txt` (default is `hand_tracking_desktop.pbtxt`)");

        stopwatch.Start();
        sidePacket = new SidePacket();
        sidePacket.Emplace("num_hands", new IntPacket(2));

#if UNITY_ANDROID && !UNITY_EDITOR
        SetupOutputPacket(texture);
        sidePacket.Emplace(destinationBufferName, outputPacket);

        return(graph.StartRun(sidePacket));
#else
        return(StartRun());
#endif
    }
    public override Status StartRun()
    {
        poseLandmarksStreamPoller = graph.AddOutputStreamPoller <NormalizedLandmarkList>(poseLandmarksStream).Value();
        poseLandmarksPacket       = new NormalizedLandmarkListPacket();

        poseRoiStreamPoller = graph.AddOutputStreamPoller <NormalizedRect>(poseRoiStream).Value();
        poseRoiPacket       = new NormalizedRectPacket();

        poseDetectionStreamPoller = graph.AddOutputStreamPoller <Detection>(poseDetectionStream).Value();
        poseDetectionPacket       = new DetectionPacket();

        faceLandmarksStreamPoller = graph.AddOutputStreamPoller <NormalizedLandmarkList>(faceLandmarksStream).Value();
        faceLandmarksPacket       = new NormalizedLandmarkListPacket();

        leftHandLandmarksStreamPoller = graph.AddOutputStreamPoller <NormalizedLandmarkList>(leftHandLandmarksStream).Value();
        leftHandLandmarksPacket       = new NormalizedLandmarkListPacket();

        rightHandLandmarksStreamPoller = graph.AddOutputStreamPoller <NormalizedLandmarkList>(rightHandLandmarksStream).Value();
        rightHandLandmarksPacket       = new NormalizedLandmarkListPacket();

        poseLandmarksPresenceStreamPoller = graph.AddOutputStreamPoller <bool>(poseLandmarksPresenceStream).Value();
        poseLandmarksPresencePacket       = new BoolPacket();

        poseRoiPresenceStreamPoller = graph.AddOutputStreamPoller <bool>(poseRoiPresenceStream).Value();
        poseRoiPresencePacket       = new BoolPacket();

        poseDetectionPresenceStreamPoller = graph.AddOutputStreamPoller <bool>(poseDetectionPresenceStream).Value();
        poseDetectionPresencePacket       = new BoolPacket();

        faceLandmarksPresenceStreamPoller = graph.AddOutputStreamPoller <bool>(faceLandmarksPresenceStream).Value();
        faceLandmarksPresencePacket       = new BoolPacket();

        leftHandLandmarksPresenceStreamPoller = graph.AddOutputStreamPoller <bool>(leftHandLandmarksPresenceStream).Value();
        leftHandLandmarksPresencePacket       = new BoolPacket();

        rightHandLandmarksPresenceStreamPoller = graph.AddOutputStreamPoller <bool>(rightHandLandmarksPresenceStream).Value();
        rightHandLandmarksPresencePacket       = new BoolPacket();

        sidePacket = new SidePacket();
        sidePacket.Emplace("enable_iris_detection", new BoolPacket(detectIris));
        sidePacket.Emplace("model_complexity", new IntPacket((int)modelComplexity));
        sidePacket.Emplace("smooth_landmarks", new BoolPacket(smoothLandmarks));

        return(graph.StartRun(sidePacket));
    }
Beispiel #14
0
        SidePacket BuildSidePacket(ImageSource imageSource)
        {
            var sidePacket = new SidePacket();

            SetImageTransformationOptions(sidePacket, imageSource, true);
            sidePacket.Emplace("num_hands", new IntPacket(maxNumHands));

            return(sidePacket);
        }
Beispiel #15
0
        SidePacket BuildSidePacket(ImageSource imageSource)
        {
            var sidePacket = new SidePacket();

            SetImageTransformationOptions(sidePacket, imageSource);
            sidePacket.Emplace("model_type", new IntPacket((int)modelType));

            return(sidePacket);
        }
Beispiel #16
0
        public void Erase_ShouldEraseKey_When_KeyExists()
        {
            var sidePacket = new SidePacket();

            sidePacket.Emplace("value", new BoolPacket(true));
            Assert.AreEqual(sidePacket.size, 1);

            sidePacket.Erase("value");
            Assert.AreEqual(sidePacket.size, 0);
        }
Beispiel #17
0
        public void Initialize_ShouldReturnInternalError_When_CalledWithConfigAndSidePacket_And_ConfigIsSet()
        {
            var graph      = new CalculatorGraph(validConfigText);
            var config     = CalculatorGraphConfig.Parser.ParseFromTextFormat(validConfigText);
            var sidePacket = new SidePacket();

            sidePacket.Emplace("flag", new BoolPacket(true));
            var status = graph.Initialize(config, sidePacket);

            Assert.AreEqual(status.code, Status.StatusCode.Internal);
        }
Beispiel #18
0
        public void Initialize_ShouldReturnOk_When_CalledWithConfigAndSidePacket_And_ConfigIsNotSet()
        {
            var graph      = new CalculatorGraph();
            var config     = CalculatorGraphConfig.Parser.ParseFromTextFormat(validConfigText);
            var sidePacket = new SidePacket();

            sidePacket.Emplace("flag", new BoolPacket(true));
            var status = graph.Initialize(config, sidePacket);

            Assert.True(status.ok);
        }
    public override Status StartRun()
    {
        Debug.Log("This graph is for testing official examples. You can customize the graph by editing `official_demo_cpu.txt` (default is `hand_tracking_desktop.pbtxt`)");

        graph.ObserveOutputStream <ImageFramePacket, ImageFrame>(outputStream, OutputVideoCallback, out outputVideoCallbackHandle).AssertOk();

        sidePacket = new SidePacket();
        sidePacket.Emplace("num_hands", new IntPacket(2));

        return(graph.StartRun(sidePacket));
    }
Beispiel #20
0
        SidePacket BuildSidePacket(ImageSource imageSource)
        {
            var sidePacket = new SidePacket();

            SetImageTransformationOptions(sidePacket, imageSource);
            var outputRotation = imageSource.isHorizontallyFlipped ? imageSource.rotation.Reverse() : imageSource.rotation;

            sidePacket.Emplace("output_rotation", new IntPacket((int)outputRotation));

            return(sidePacket);
        }
Beispiel #21
0
        public void Erase_ShouldEraseKey_When_KeyExists()
        {
            using (var sidePacket = new SidePacket())
            {
                sidePacket.Emplace("value", new BoolPacket(true));
                Assert.AreEqual(1, sidePacket.size);

                var count = sidePacket.Erase("value");
                Assert.AreEqual(0, sidePacket.size);
                Assert.AreEqual(1, count);
            }
        }
Beispiel #22
0
    public override Status StartRun(Texture texture)
    {
        Debug.Log("This graph is for testing official examples. You can customize the graph by editing `official_demo_dekstop_gpu.txt` (default is `hand_tracking_mobile.pbtxt`)");

        outputStreamPoller = graph.AddOutputStreamPoller <ImageFrame>(outputStream).ConsumeValueOrDie();
        outputPacket       = new ImageFramePacket();

        sidePacket = new SidePacket();
        sidePacket.Emplace("num_hands", new IntPacket(2));

        return(graph.StartRun(sidePacket));
    }
    public override Status StartRun(Texture texture)
    {
        Debug.Log("This graph is for testing official examples. You can customize the graph by editing `official_demo_*.txt` (default is `hand_tracking_desktop.pbtxt`)");

        stopwatch.Start();

        sidePacket = new SidePacket();
        sidePacket.Emplace("num_hands", new IntPacket(2));

#if UNITY_ANDROID && !UNITY_EDITOR
        // Tell MediaPipe the target texture
        destinationNativeTexturePtr = texture.GetNativeTexturePtr();
        destinationWidth            = texture.width;
        destinationHeight           = texture.height;

        gpuHelper.RunInGlContext(BuildDestination).AssertOk();
        sidePacket.Emplace(destinationBufferName, outputPacket);

        return(graph.StartRun(sidePacket));
#else
        return(StartRun());
#endif
    }
 public void ValidateRequiredSidePackets_ShouldReturnOk_When_TheConfigDoesNotRequireSidePackets_And_SidePacketIsNotEmpty()
 {
     using (var config = new ValidatedGraphConfig())
     {
         config.Initialize(CalculatorGraphConfig.Parser.ParseFromTextFormat(_PassThroughConfigText)).AssertOk();
         using (var sidePacket = new SidePacket())
         {
             sidePacket.Emplace("in", new IntPacket(0));
             using (var status = config.ValidateRequiredSidePackets(sidePacket))
             {
                 Assert.True(status.Ok());
             }
         }
     }
 }
Beispiel #25
0
        public void Emplace_ShouldInsertAndDisposePacket()
        {
            using (var sidePacket = new SidePacket())
            {
                Assert.AreEqual(0, sidePacket.size);
                Assert.IsNull(sidePacket.At <FloatPacket, float>("value"));

                var flagPacket = new FloatPacket(1.0f);
                sidePacket.Emplace("value", flagPacket);

                Assert.AreEqual(1, sidePacket.size);
                Assert.AreEqual(1.0f, sidePacket.At <FloatPacket, float>("value").Get());
                Assert.True(flagPacket.isDisposed);
            }
        }
Beispiel #26
0
        public void Emplace_ShouldInsertAndDisposePacket()
        {
            var sidePacket = new SidePacket();

            Assert.AreEqual(sidePacket.size, 0);
            Assert.IsNull(sidePacket.At <FloatPacket>("value"));

            var flagPacket = new FloatPacket(1.0f);

            sidePacket.Emplace("value", flagPacket);

            Assert.AreEqual(sidePacket.size, 1);
            Assert.AreEqual(sidePacket.At <FloatPacket>("value").Get(), 1.0f);
            Assert.True(flagPacket.isDisposed);
        }
 public void ValidateRequiredSidePackets_ShouldReturnInvalidArgumentError_When_AllTheRequiredSidePacketsAreNotGiven()
 {
     using (var config = new ValidatedGraphConfig())
     {
         config.Initialize(CalculatorGraphConfig.Parser.ParseFromTextFormat(_ObjectronConfigText)).AssertOk();
         using (var sidePacket = new SidePacket())
         {
             sidePacket.Emplace("max_num_objects", new IntPacket(3));
             using (var status = config.ValidateRequiredSidePackets(sidePacket))
             {
                 Assert.AreEqual(Status.StatusCode.InvalidArgument, status.Code());
             }
         }
     }
 }
Beispiel #28
0
    public override Status StartRun(Texture texture)
    {
        stopwatch.Start();

        sidePacket = new SidePacket();
        sidePacket.Emplace("allowed_labels", new StringPacket(GetAllowedLabels(category)));
        sidePacket.Emplace("model_scale", new FloatArrayPacket(GetModelScale(category)));
        sidePacket.Emplace("model_transformation", new FloatArrayPacket(GetModelTransformation(category)));
        sidePacket.Emplace("box_texture", new ImageFramePacket(GetImageFrameFromImage(boxTextureAsset)));
        sidePacket.Emplace("max_num_objects", new IntPacket(maxNumObjects));
        sidePacket.Emplace("box_asset_name", new StringPacket("box.obj.bytes"));
        sidePacket.Emplace("obj_texture", new ImageFramePacket(GetImageFrameFromImage(objTextureAsset)));
        sidePacket.Emplace("obj_asset_name", new StringPacket(GetObjAssetName(category)));

#if UNITY_ANDROID && !UNITY_EDITOR
        SetupOutputPacket(texture);
        sidePacket.Emplace(destinationBufferName, outputPacket);

        return(graph.StartRun(sidePacket));
#else
        return(StartRun());
#endif
    }
    public override Status StartRun()
    {
        poseLandmarksStreamPoller = graph.AddOutputStreamPoller <NormalizedLandmarkList>(poseLandmarksStream).ConsumeValueOrDie();
        poseLandmarksPacket       = new NormalizedLandmarkListPacket();

        poseRoiStreamPoller = graph.AddOutputStreamPoller <NormalizedRect>(poseRoiStream).ConsumeValueOrDie();
        poseRoiPacket       = new NormalizedRectPacket();

        poseDetectionStreamPoller = graph.AddOutputStreamPoller <Detection>(poseDetectionStream).ConsumeValueOrDie();
        poseDetectionPacket       = new DetectionPacket();

        faceLandmarksStreamPoller = graph.AddOutputStreamPoller <NormalizedLandmarkList>(faceLandmarksStream).ConsumeValueOrDie();
        faceLandmarksPacket       = new NormalizedLandmarkListPacket();

        leftHandLandmarksStreamPoller = graph.AddOutputStreamPoller <NormalizedLandmarkList>(leftHandLandmarksStream).ConsumeValueOrDie();
        leftHandLandmarksPacket       = new NormalizedLandmarkListPacket();

        rightHandLandmarksStreamPoller = graph.AddOutputStreamPoller <NormalizedLandmarkList>(rightHandLandmarksStream).ConsumeValueOrDie();
        rightHandLandmarksPacket       = new NormalizedLandmarkListPacket();

        poseLandmarksPresenceStreamPoller = graph.AddOutputStreamPoller <bool>(poseLandmarksPresenceStream).ConsumeValueOrDie();
        poseLandmarksPresencePacket       = new BoolPacket();

        poseRoiPresenceStreamPoller = graph.AddOutputStreamPoller <bool>(poseRoiPresenceStream).ConsumeValueOrDie();
        poseRoiPresencePacket       = new BoolPacket();

        poseDetectionPresenceStreamPoller = graph.AddOutputStreamPoller <bool>(poseDetectionPresenceStream).ConsumeValueOrDie();
        poseDetectionPresencePacket       = new BoolPacket();

        faceLandmarksPresenceStreamPoller = graph.AddOutputStreamPoller <bool>(faceLandmarksPresenceStream).ConsumeValueOrDie();
        faceLandmarksPresencePacket       = new BoolPacket();

        leftHandLandmarksPresenceStreamPoller = graph.AddOutputStreamPoller <bool>(leftHandLandmarksPresenceStream).ConsumeValueOrDie();
        leftHandLandmarksPresencePacket       = new BoolPacket();

        rightHandLandmarksPresenceStreamPoller = graph.AddOutputStreamPoller <bool>(rightHandLandmarksPresenceStream).ConsumeValueOrDie();
        rightHandLandmarksPresencePacket       = new BoolPacket();

        sidePacket = new SidePacket();
        var irisFlag = new BoolPacket(detectIris);

        sidePacket.Emplace("enable_iris_detection", irisFlag);

        return(graph.StartRun(sidePacket));
    }
    public override Status StartRun()
    {
        multiFaceLandmarksStreamPoller = graph.AddOutputStreamPoller <List <NormalizedLandmarkList> >(multiFaceLandmarksStream).ConsumeValueOrDie();
        multiFaceLandmarksPacket       = new NormalizedLandmarkListVectorPacket();

        faceRectsFromLandmarksStreamPoller = graph.AddOutputStreamPoller <List <NormalizedRect> >(faceRectsFromLandmarksStream).ConsumeValueOrDie();
        faceRectsFromLandmarksPacket       = new NormalizedRectVectorPacket();

        faceDetectionsStreamPoller = graph.AddOutputStreamPoller <List <Detection> >(faceDetectionsStream).ConsumeValueOrDie();
        faceDetectionsPacket       = new DetectionVectorPacket();

        multiFacelandmarksPresenceStreamPoller = graph.AddOutputStreamPoller <bool>(multiFaceLandmarksPresenceStream).ConsumeValueOrDie();
        multiFaceLandmarksPresencePacket       = new BoolPacket();

        faceDetectionsPresenceStreamPoller = graph.AddOutputStreamPoller <bool>(faceDetectionsPresenceStream).ConsumeValueOrDie();
        faceDetectionsPresencePacket       = new BoolPacket();

        sidePacket = new SidePacket();
        sidePacket.Emplace("num_faces", new IntPacket(numFaces));

        return(graph.StartRun(sidePacket));
    }