예제 #1
0
    void DrawResults(FaceDetect.Result detection, FaceMesh.Result face)
    {
        cameraView.rectTransform.GetWorldCorners(rtCorners);
        Vector3 min = rtCorners[0];
        Vector3 max = rtCorners[2];

        // Draw Face Detection
        {
            draw.color = Color.blue;
            Rect rect = MathTF.Lerp(min, max, detection.rect, true);
            draw.Rect(rect, 0.05f);
            foreach (Vector2 p in detection.keypoints)
            {
                draw.Point(MathTF.Lerp(min, max, new Vector3(p.x, 1f - p.y, 0)), 0.1f);
            }
        }
        draw.Apply();

        // Draw face
        draw.color = Color.green;
        float zScale = (max.x - min.x) / 2;

        for (int i = 0; i < face.keypoints.Length; i++)
        {
            Vector3 p = MathTF.Lerp(min, max, face.keypoints[i]);
            p.z = face.keypoints[i].z * zScale;
            faceKeypoints[i] = p;
            draw.Point(p, 0.05f);
        }
        draw.Apply();

        // Update Mesh
        FaceMeshBuilder.UpdateMesh(faceMeshFilter.sharedMesh, faceKeypoints);
    }
예제 #2
0
    private void DrawResult(MoveNet.Result[] results)
    {
        if (results == null || results.Length == 0)
        {
            return;
        }

        var rect = cameraView.GetComponent <RectTransform>();

        rect.GetWorldCorners(rtCorners);
        Vector3 min = rtCorners[0];
        Vector3 max = rtCorners[2];

        var connections = PoseNet.Connections;
        int len         = connections.GetLength(0);

        for (int i = 0; i < len; i++)
        {
            var a = results[(int)connections[i, 0]];
            var b = results[(int)connections[i, 1]];
            if (a.confidence >= threshold && b.confidence >= threshold)
            {
                draw.Line3D(
                    MathTF.Lerp(min, max, new Vector3(a.x, 1f - a.y, 0)),
                    MathTF.Lerp(min, max, new Vector3(b.x, 1f - b.y, 0)),
                    1
                    );
            }
        }

        draw.Apply();
    }
    void DrawResult()
    {
        var rect = cameraView.GetComponent <RectTransform>();

        rect.GetWorldCorners(corners);
        Vector3 min = corners[0];
        Vector3 max = corners[2];

        var connections = PoseNet.Connections;
        int len         = connections.GetLength(0);

        for (int i = 0; i < len; i++)
        {
            var a = results[(int)connections[i, 0]];
            var b = results[(int)connections[i, 1]];
            if (a.confidence >= threshold && b.confidence >= threshold)
            {
                draw.Line3D(
                    MathTF.Lerp(min, max, new Vector3(a.x, 1f - a.y, 0)),
                    MathTF.Lerp(min, max, new Vector3(b.x, 1f - b.y, 0)),
                    lineThickness
                    );
            }
        }

        draw.Apply();
    }
예제 #4
0
    void OnGLDraw()
    {
        var rect = cameraView.GetComponent <RectTransform>();

        rect.GetWorldCorners(corners);
        Vector3 min = corners[0];
        Vector3 max = corners[2];

        GL.Begin(GL.LINES);

        GL.Color(Color.green);
        var connections = PoseNet.Connections;
        int len         = connections.GetLength(0);

        for (int i = 0; i < len; i++)
        {
            var a = results[(int)connections[i, 0]];
            var b = results[(int)connections[i, 1]];
            if (a.confidence >= threshold && b.confidence >= threshold)
            {
                GL.Vertex(MathTF.Leap3(min, max, new Vector3(a.x, 1f - a.y, 0)));
                GL.Vertex(MathTF.Leap3(min, max, new Vector3(b.x, 1f - b.y, 0)));
            }
        }

        GL.End();
    }
예제 #5
0
    void DrawJoints(Vector3[] joints)
    {
        var rt = cameraView.transform as RectTransform;

        rt.GetWorldCorners(rtCorners);
        Vector3 min    = rtCorners[0];
        Vector3 max    = rtCorners[2];
        float   zScale = max.x - min.x;

        var rotation = Quaternion.identity;
        var scale    = Vector3.one * 0.1f;

        for (int i = 0; i < HandLandmarkDetect.JOINT_COUNT; i++)
        {
            var p = joints[i];

#if !UNITY_EDITOR
            p.x = 1.0f - p.x; // FIXME: bug flipping on iPhone
#endif
            p    = MathTF.Leap3(min, max, p);
            p.z += (joints[i].z - 0.5f) * zScale;
            var mtx = Matrix4x4.TRS(p, rotation, scale);
            jointMatrices[i] = mtx;
        }
        Graphics.DrawMeshInstanced(jointMesh, 0, jointMaterial, jointMatrices);
    }
    void DrawFrame(ref PoseDetect.Result pose)
    {
        Vector3 min = rtCorners[0];
        Vector3 max = rtCorners[2];

        draw.color = Color.green;
        draw.Rect(MathTF.Lerp(min, max, pose.rect, true), 0.02f, min.z);

        foreach (var kp in pose.keypoints)
        {
            draw.Point(MathTF.Lerp(min, max, (Vector3)kp, true), 0.05f);
        }
        draw.Apply();
    }
예제 #7
0
    void DrawFrames(List <PalmDetect.Result> palms)
    {
        Vector3 min = rtCorners[0];
        Vector3 max = rtCorners[2];

        draw.color = Color.green;
        foreach (var palm in palms)
        {
            draw.Rect(MathTF.Lerp(min, max, palm.rect, true), 0.02f, min.z);

            foreach (var kp in palm.keypoints)
            {
                draw.Point(MathTF.Lerp(min, max, (Vector3)kp, true), 0.05f);
            }
        }
        draw.Apply();
    }
    void DrawResults(List <FaceDetect.Result> results)
    {
        Vector3 min = rtCorners[0];
        Vector3 max = rtCorners[2];

        draw.color = Color.blue;

        foreach (var result in results)
        {
            Rect rect = MathTF.Lerp(min, max, result.rect, true);
            draw.Rect(rect, 0.05f);
            foreach (Vector2 p in result.keypoints)
            {
                draw.Point(MathTF.Lerp(min, max, new Vector3(p.x, 1f - p.y, 0)), 0.1f);
            }
        }
        draw.Apply();
    }
    private void DrawFaceDetection(FaceDetect.Result detection, Vector3 min, Vector3 max, Color color, float pntSize)
    {
        // Draw Face Detection
        m_drawPrimitive.color = color;
        UnityEngine.Rect rect = MathTF.Lerp(min, max, detection.rect, true);
        m_drawPrimitive.Rect(rect, 0.03f);

        float zScale = (max.x - min.x) / 2;

        for (int i = 0; i < detection.keypoints.Length; i++)
        {
            Vector3 p = MathTF.Lerp(min, max, new Vector3(detection.keypoints[i].x, 1f - detection.keypoints[i].y, 0));
            //Debug.Log("Detection Pnts: " +  detection.keypoints.Length + "\n");
            m_drawPrimitive.Point(p, pntSize);
        }

        m_drawPrimitive.Apply();
    }
예제 #10
0
    void DrawJoints(Camera camera)
    {
        if (landmarkResult == null || landmarkResult.score < 0.2f)
        {
            return;
        }

        // Get world position of the joints
        var joints = landmarkResult.joints;
        var rt     = cameraView.transform as RectTransform;

        rt.GetWorldCorners(rtCorners);
        Vector3 min    = rtCorners[0];
        Vector3 max    = rtCorners[2];
        float   zScale = max.x - min.x;

        for (int i = 0; i < joints.Length; i++)
        {
            var p = joints[i];
            p    = MathTF.Leap3(min, max, p);
            p.z += (joints[i].z - 0.5f) * zScale;

            worldJoints[i] = p;
        }

        // Draw
        for (int i = 0; i < worldJoints.Length; i++)
        {
            draw.Cube(worldJoints[i], 0.1f);
        }
        var connections = PoseLandmarkDetect.CONNECTIONS;

        for (int i = 0; i < connections.Length; i += 2)
        {
            draw.Line(
                worldJoints[connections[i]],
                worldJoints[connections[i + 1]],
                0.05f);
        }
    }
예제 #11
0
    private void LerpPointArray(Vector3[] keypoints, Vector3 min, Vector3 max, float zScale, float pntSize, Color32 color, string detectionType)
    {
        for (int i = 0; i < keypoints.Length; i++)
        {
            Vector3 p = MathTF.Lerp(min, max, new Vector3(keypoints[i].x, keypoints[i].y, keypoints[i].z));
            p.z = keypoints[i].z * zScale;

            switch (detectionType)
            {
            case ("FACE"):
                m_faceKeypoints[i] = p;
                break;

            case ("EyeR"):
                m_irisRightResult.eyelandmark[i] = p;
                break;

            case ("EyeL"):
                m_irisLeftResult.eyelandmark[i] = p;
                break;

            case ("IrisR"):
                m_irisRightResult.irislandmark[i] = p;
                break;

            case ("IrisL"):
                m_irisLeftResult.irislandmark[i] = p;
                break;
            }

            m_drawPrimitive.Point(p, pntSize);
        }

        m_drawPrimitive.color = color;

        m_drawPrimitive.Apply();
    }