Beispiel #1
0
        public void Invoke(Texture inputTex, PalmDetect.Result palm)
        {
            var options = (inputTex is WebCamTexture)
                ? resizeOptions.GetModifedForWebcam((WebCamTexture)inputTex)
                : resizeOptions;

            cropMatrix = RectTransformationCalculator.CalcMatrix(new RectTransformationCalculator.Options()
            {
                rect                 = palm.rect,
                rotationDegree       = CalcHandRotation(ref palm) * Mathf.Rad2Deg,
                shift                = PalmShift,
                scale                = PalmScale,
                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);
        }
Beispiel #2
0
        public async UniTask <Result> InvokeAsync(Texture inputTex, PalmDetect.Result palm, CancellationToken cancellationToken)
        {
            cropMatrix = RectTransformationCalculator.CalcMatrix(new RectTransformationCalculator.Options()
            {
                rect                 = palm.rect,
                rotationDegree       = CalcHandRotation(ref palm) * Mathf.Rad2Deg,
                shift                = PalmShift,
                scale                = PalmScale,
                cameraRotationDegree = -resizeOptions.rotationDegree,
                mirrorHorizontal     = resizeOptions.mirrorHorizontal,
                mirrorVertiacal      = resizeOptions.mirrorVertical,
            });

            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);

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

            return(result);
        }
Beispiel #3
0
        private static float CalcHandRotation(ref PalmDetect.Result detection)
        {
            // Rotation based on Center of wrist - Middle finger
            const float RAD_90 = 90f * Mathf.Deg2Rad;
            var         vec    = detection.keypoints[0] - detection.keypoints[2];

            return(-(RAD_90 + Mathf.Atan2(vec.y, vec.x)));
        }