public async UniTask <Result> InvokeAsync(Texture inputTex, PoseDetect.Result pose, bool useFilter, CancellationToken cancellationToken, PlayerLoopTiming timing)
        {
            var options = (inputTex is WebCamTexture)
                ? resizeOptions.GetModifedForWebcam((WebCamTexture)inputTex)
                : resizeOptions;

            cropMatrix = CalcCropMatrix(ref pose, ref options);
            RenderTexture rt = resizer.Resize(
                inputTex, options.width, options.height, true,
                cropMatrix,
                TextureResizer.GetTextureST(inputTex, options));

            await ToTensorAsync(rt, input0, false, cancellationToken);

            await UniTask.SwitchToThreadPool();

            interpreter.SetInputTensorData(0, input0);
            interpreter.Invoke();
            interpreter.GetOutputTensorData(0, output0);
            interpreter.GetOutputTensorData(1, output1);

            var result = GetResult(useFilter);
            await UniTask.SwitchToMainThread(timing, cancellationToken);

            return(result);
        }
コード例 #2
0
        public async UniTask <Result> InvokeAsync(Texture inputTex, PoseDetect.Result pose, CancellationToken cancellationToken, PlayerLoopTiming timing)
        {
            cropMatrix = CalcCropMatrix(ref pose, ref resizeOptions);
            RenderTexture rt = resizer.Resize(
                inputTex, resizeOptions.width, resizeOptions.height, true,
                cropMatrix,
                TextureResizer.GetTextureST(inputTex, resizeOptions));

            await ToTensorAsync(rt, input0, false, cancellationToken);

            await UniTask.SwitchToThreadPool();

            interpreter.SetInputTensorData(0, input0);
            interpreter.Invoke();
            interpreter.GetOutputTensorData(0, output0);
            interpreter.GetOutputTensorData(1, output1);
            if (options.useWorldLandmarks)
            {
                interpreter.GetOutputTensorData(3, output3);
                interpreter.GetOutputTensorData(4, output4);
            }
            var result = GetResult();
            await UniTask.SwitchToMainThread(timing, cancellationToken);

            return(result);
        }
コード例 #3
0
        public void Invoke(Texture inputTex, PoseDetect.Result pose)
        {
            var options = (inputTex is WebCamTexture)
                ? resizeOptions.GetModifedForWebcam((WebCamTexture)inputTex)
                : resizeOptions;

            // float rotation = CalcRotationDegree(ref pose);
            var rect = AlignmentPointsRect(ref pose);

            cropMatrix = RectTransformationCalculator.CalcMatrix(new RectTransformationCalculator.Options()
            {
                rect                 = rect,
                rotationDegree       = 180,
                shift                = PoseShift,
                scale                = PoseScale,
                cameraRotationDegree = -options.rotationDegree,
                mirrorHorizontal     = options.mirrorHorizontal,
                mirrorVertiacal      = options.mirrorVertical,
            });

            RenderTexture rt = resizer.Resize(
                inputTex, options.width, options.height, true,
                cropMatrix,
                TextureResizer.GetTextureST(inputTex, options));

            ToTensor(rt, input0, false);

            interpreter.SetInputTensorData(0, input0);
            interpreter.Invoke();
            interpreter.GetOutputTensorData(0, output0);
            interpreter.GetOutputTensorData(1, output1);

            // interpreter.GetOutputTensorData(2, output2);// not in use
        }
コード例 #4
0
        private static float CalcRotationDegree(ref PoseDetect.Result pose)
        {
            // Calc rotation based on
            // Center of Hip and Center of shoulder
            const float RAD_90 = 90f * Mathf.PI / 180f;
            var         vec    = pose.keypoints[0] - pose.keypoints[2];

            return(-(RAD_90 + Mathf.Atan2(vec.y, vec.x)) * Mathf.Rad2Deg);
        }
コード例 #5
0
        // AlignmentPointsRectsCalculator from MediaPipe
        private static Rect AlignmentPointsRect(ref PoseDetect.Result pose)
        {
            float2 center  = pose.keypoints[2];
            float2 scale   = pose.keypoints[3];
            float  boxSize = Mathf.Sqrt(
                (scale.x - center.x) * (scale.x - center.x)
                + (scale.y - center.y) * (scale.y - center.y)
                ) * 2f;

            return(new Rect(
                       center.x - boxSize / 2,
                       center.y - boxSize / 2,
                       boxSize,
                       boxSize));
        }
コード例 #6
0
        public void Invoke(Texture inputTex, PoseDetect.Result pose)
        {
            var options = (inputTex is WebCamTexture)
                ? resizeOptions.GetModifedForWebcam((WebCamTexture)inputTex)
                : resizeOptions;

            cropMatrix = CalcCropMatrix(ref pose, ref options);

            RenderTexture rt = resizer.Resize(
                inputTex, options.width, options.height, true,
                cropMatrix,
                TextureResizer.GetTextureST(inputTex, options));

            ToTensor(rt, input0, false);

            interpreter.SetInputTensorData(0, input0);
            interpreter.Invoke();
            interpreter.GetOutputTensorData(0, output0);
            interpreter.GetOutputTensorData(1, output1);
            // interpreter.GetOutputTensorData(2, output2);// not in use
        }
コード例 #7
0
        public void Invoke(Texture inputTex, PoseDetect.Result pose)
        {
            cropMatrix = CalcCropMatrix(ref pose, ref resizeOptions);

            RenderTexture rt = resizer.Resize(
                inputTex, resizeOptions.width, resizeOptions.height, true,
                cropMatrix,
                TextureResizer.GetTextureST(inputTex, resizeOptions));

            ToTensor(rt, input0, false);

            interpreter.SetInputTensorData(0, input0);
            interpreter.Invoke();
            interpreter.GetOutputTensorData(0, output0);
            interpreter.GetOutputTensorData(1, output1);
            // interpreter.GetOutputTensorData(2, output2);// not in use
            if (options.useWorldLandmarks)
            {
                interpreter.GetOutputTensorData(3, output3);
                interpreter.GetOutputTensorData(4, output4);
            }
        }