Beispiel #1
0
        public void Invoke(Texture inputTex, int[] indxs, FaceDetect.Result face, FaceMesh.Result meshResult, int side)
        {
            CalcEyeRoi(face, meshResult, indxs[0], indxs[1]);

            var options = (inputTex is WebCamTexture)
                ? resizeOptions.GetModifedForWebcam((WebCamTexture)inputTex)
                : resizeOptions;

            cropMatrix = RectTransformationCalculator.CalcMatrix(new RectTransformationCalculator.Options()
            {
                rect                 = face.rectEye,
                rotationDegree       = CalcFaceRotation(ref face) * Mathf.Rad2Deg,
                shift                = FaceShift,
                scale                = FaceScale,
                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 void Invoke(Texture inputTex, FaceDetect.Result face)
        {
            cropMatrix = RectTransformationCalculator.CalcMatrix(new RectTransformationCalculator.Options()
            {
                rect                 = face.rect,
                rotationDegree       = CalcFaceRotation(ref face) * Mathf.Rad2Deg,
                shift                = FaceShift,
                scale                = FaceScale,
                cameraRotationDegree = -resizeOptions.rotationDegree,
                mirrorHorizontal     = resizeOptions.mirrorHorizontal,
                mirrorVertiacal      = resizeOptions.mirrorVertical,
            });

            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);
        }
Beispiel #3
0
        private void CalcEyeRoi(FaceDetect.Result face, FaceMesh.Result meshResult, int idx0, int idx1)
        {
            float x0 = meshResult.keypoints[idx0].x;
            float y0 = meshResult.keypoints[idx0].y;
            float x1 = meshResult.keypoints[idx1].x;
            float y1 = meshResult.keypoints[idx1].y;

            float cx = (x0 + x1) / 2.0f;
            float cy = (y0 + y1) / 2.0f;
            float w  = Mathf.Abs(x1 - x0);
            float h  = Mathf.Abs(y1 - y0);

            {
                float long_side = Mathf.Max(w, h);
                w = h = long_side;
            }
            {
                float scale = 1f;
                w *= scale;
                h *= scale;
            }

            float dx = w / 2.0f;
            float dy = h / 2.0f;

            Vector2[] eye_pos = new Vector2[4];

            eye_pos[0].x = -dx; eye_pos[0].y = -dy;
            eye_pos[1].x = +dx; eye_pos[1].y = -dy;
            eye_pos[2].x = +dx; eye_pos[2].y = +dy;
            eye_pos[3].x = -dx; eye_pos[3].y = +dy;

            float rotation = 0.0f;

            for (int i = 0; i < 4; i++)
            {
                float sx = eye_pos[i].x;
                float sy = eye_pos[i].y;
                eye_pos[i].x = sx * Mathf.Cos(rotation) - sy * Mathf.Sin(rotation);
                eye_pos[i].y = sx * Mathf.Sin(rotation) + sy * Mathf.Cos(rotation);

                eye_pos[i].x += cx;
                eye_pos[i].y += cy;
            }

            face.rectEye.x      = cx - w / 2;
            face.rectEye.y      = (1f - cy) - h / 2;
            face.rectEye.width  = w;
            face.rectEye.height = h;
        }
Beispiel #4
0
        private static float CalcFaceRotation(ref FaceDetect.Result detection)
        {
            var vec = detection.rightEye - detection.leftEye;

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