Exemple #1
0
    void DrawResult(Camera camera)
    {
        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.Line(
                    MathTF.Leap3(min, max, new Vector3(a.x, 1f - a.y, 0)),
                    MathTF.Leap3(min, max, new Vector3(b.x, 1f - b.y, 0)),
                    lineThickness
                    );
            }
        }
    }
Exemple #2
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);
    }
Exemple #3
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();
    }
    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);
        }
    }