コード例 #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
                    );
            }
        }
    }
コード例 #2
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);
        }
    }