Example #1
0
 void CaptureSkeletonsFromCameraFrame()
 {
     using (var frame = tracker.PopResult())
     {
         Debug.LogFormat("{0} bodies found.", frame.NumBodies);
         if (frame.NumBodies > 0)
         {
             var bodyId = frame.GetBodyId(0);
             this.skeleton = frame.GetSkeleton(0);
             skeletons.Add(this.skeleton);
             for (var i = 0; i < (int)JointId.Count; i++)
             {
                 var joint = this.skeleton.Joints[i];
                 var pos   = joint.Position;
                 // Debug.Log("pos: " + (JointId)i + " " + pos[0] + " " + pos[1] + " " + pos[2]);
                 var rot = joint.Orientation;
                 // Debug.Log("rot " + (JointId)i + " " + rot[0] + " " + rot[1] + " " + rot[2] + " " + rot[3]); // Length 4
                 var v   = new Vector3(pos[0], -pos[1], pos[2]) * 0.004f;
                 var r   = new Quaternion(rot[1], rot[2], rot[3], rot[0]);
                 var obj = blockmanArray[i];
                 obj.transform.SetPositionAndRotation(v, r);
             }
         }
     }
 }
Example #2
0
    void Update()
    {
        using (Capture capture = device.GetCapture())
        {
            tracker.EnqueueCapture(capture);
            var color = capture.Color;
            if (color.WidthPixels > 0)
            {
                Texture2D tex = new Texture2D(color.WidthPixels, color.HeightPixels, TextureFormat.BGRA32, false);
                tex.LoadRawTextureData(color.GetBufferCopy());
                tex.Apply();
                renderer.material.mainTexture = tex;
            }
        }

        using (var frame = tracker.PopResult())
        {
            //Debug.LogFormat("{0} bodies found.", frame.NumBodies);
            if (frame.NumBodies > 0)
            {
                var bodyId = frame.GetBodyId(0);
                //Debug.LogFormat("bodyId={0}", bodyId);
                this.skeleton = frame.GetSkeleton(0);
                Stack <string>  JointNames     = new Stack <string>();
                Stack <Vector3> JointLocations = new Stack <Vector3>();
                for (var i = 0; i < (int)JointId.Count; i++)
                {
                    var joint = this.skeleton.Joints[i];
                    var pos   = joint.Position;
                    var rot   = joint.Orientation;
                    var v     = new Vector3(pos[0], -pos[1], pos[2]) * 0.004f;
                    var r     = new Quaternion(rot[1], rot[2], rot[3], rot[0]);
                    var obj   = debugObjects[i];
                    obj.transform.SetPositionAndRotation(v, r);

                    JointNames.Push(obj.name.ToString());
                    JointLocations.Push(v);
                }

                //handler.UpdateJointLocations(JointNames, JointLocations);
                //if (handler.GetDataCount() == 5000)
                //{
                //    Debug.Log("Wrote JSON!");
                //    handler.WriteJSON();
                //    UnityEditor.EditorApplication.isPlaying = false;
                //}

                string sjl = handler.StreamJointLocations(JointNames, JointLocations);
                streamer.SendMessage(sjl);
            }
        }
    }
Example #3
0
    void Update()
    {
        if (canUpdate)
        {
            //this streams camera output as a texture to a plane in the scene
            using (Capture capture = device.GetCapture())
            {
                tracker.EnqueueCapture(capture);
                var color = capture.Color;
                if (color.WidthPixels > 0)
                {
                    Texture2D tex = new Texture2D(color.WidthPixels, color.HeightPixels, TextureFormat.BGRA32, false);
                    tex.LoadRawTextureData(color.GetBufferCopy());
                    tex.Apply();
                    renderer.material.mainTexture = tex;
                }
            }

            //this gets skeleton data from frames and pulls individual joint data from the skeleton to apply to blocks that represent joints
            using (var frame = tracker.PopResult())
            {
                Debug.LogFormat("{0} bodies found.", frame.NumBodies);
                if (frame.NumBodies > 0)
                {
                    var bodyId = frame.GetBodyId(0);
                    //Debug.LogFormat("bodyId={0}", bodyId);
                    this.skeleton = frame.GetSkeleton(0);
                    skeletons.Add(this.skeleton);
                    for (var i = 0; i < (int)JointId.Count; i++)
                    {
                        var joint = this.skeleton.Joints[i];
                        var pos   = joint.Position;
                        //Debug.Log("pos: " + (JointId)i + " " + pos[0] + " " + pos[1] + " " + pos[2]);
                        var rot = joint.Orientation;
                        //Debug.Log("rot " + (JointId)i + " " + rot[0] + " " + rot[1] + " " + rot[2] + " " + rot[3]); // Length 4
                        var v   = new Vector3(pos[0], -pos[1], pos[2]) * 0.004f;
                        var r   = new Quaternion(rot[1], rot[2], rot[3], rot[0]);
                        var obj = debugObjects[i];
                        obj.transform.SetPositionAndRotation(v, r);
                    }
                }
            }
            if (skeletons.Count > 4) // and the current scene is CaptureScene
            {
                Debug.Log("we have enough skeletons");
                GameManager.Instance.currentState = GameState.CaptureCompleted;
                //Disable this Update loop's logic from running
                canUpdate = false;
            }
        } //end if(canUpdate)
    }     //end Update()
Example #4
0
    void CaptureSkeletonsFromCameraFrame()
    {
        using (var frame = tracker.PopResult())
        {
            Debug.LogFormat("{0} bodies found.", frame.NumBodies);
            if (frame.NumBodies > 0)
            {
                var bodyId = frame.GetBodyId(0);
                this.skeleton = frame.GetSkeleton(0);
                skeletons.Add(this.skeleton);
                for (var i = 0; i < (int)JointId.Count; i++)
                {
                    var joint = this.skeleton.Joints[i];
                    var pos   = joint.Position;
                    var rot   = joint.Orientation;

                    var v = new Vector3(pos[0], -pos[1], pos[2]) * 0.004f;
                    var r = new Quaternion(rot[1], rot[2], rot[3], rot[0]);

                    string positionData = "pos " + (JointId)i + " " + pos[0] + " " + pos[1] + " " + pos[2];
                    string rotationData = "rot " + (JointId)i + " " + rot[0] + " " + rot[1] + " " + rot[2] + " " + rot[3];                     // Length 4

                    print(positionData);
                    //print("pos: " + (JointId)i + " " + v.ToString());
                    print(rotationData);
                    //print("rot " + (JointId)i + " " + r.ToString());

                    //pos: ClavicleLeft -107.0713 -74.07419 837.8539
                    //pos: ClavicleLeft (-107.1, 74.1, 837.9)
                    //rot ClavicleLeft 0.7239407 -0.6615711 -0.01385375 -0.1950423
                    //rot ClavicleLeft (-0.7, 0.0, -0.2, 0.7)

                    producerSendMessage(skeletons.Count + " " + positionData);
                    producerSendMessage(skeletons.Count + " " + rotationData);

                    var obj = blockmanArray[i];
                    obj.transform.SetPositionAndRotation(v, r);
                }
            }
        }
    }
Example #5
0
    void Update()
    {
        using (Capture capture = device.GetCapture())
        {
            tracker.EnqueueCapture(capture);
            // TODO  DO NOT USE IT!!! It causes memory leak!

            /*var color = capture.Color;
             * if (color != null && color.WidthPixels > 0)
             * {
             *  Texture2D tex = new Texture2D(color.WidthPixels, color.HeightPixels, TextureFormat.BGRA32, false);
             *  tex.LoadRawTextureData(color.GetBufferCopy());
             *  tex.Apply();
             *  renderer.material.mainTexture = tex;
             * }*/
        }

        using (BodyFrame frame = tracker.PopResult())
        {
            Debug.LogFormat("{0} bodies found.", frame.BodyCount);
            if (frame.BodyCount > 0)
            {
                var bodies = frame.Bodies;

                var body = bodies[0];
                for (JointType jt = 0; jt < JointType.Count; jt++)
                {
                    var joint       = body.Skeleton.Joints[(int)jt];
                    var pos         = joint.Position;
                    var orientation = joint.Orientation;
                    var v           = new Vector3(pos.X, -pos.Y, pos.Z) * 0.004f;
                    var r           = new Quaternion(orientation.X, orientation.Y, orientation.Z, orientation.W);
                    var obj         = debugObjects[(int)jt];
                    obj.transform.SetPositionAndRotation(v, r);
                }
            }
        }
    }
    void Update()
    {
        using (Capture capture = device.GetCapture())
        {
            tracker.EnqueueCapture(capture);
            var color = capture.Color;
            if (color.WidthPixels > 0)
            {
                Texture2D tex = new Texture2D(color.WidthPixels, color.HeightPixels, TextureFormat.BGRA32, false);
                tex.LoadRawTextureData(color.GetBufferCopy());
                tex.Apply();
                renderer.material.mainTexture = tex;
            }
        }

        using (var frame = tracker.PopResult())
        {
            Debug.LogFormat("{0} bodies found.", frame.NumBodies);
            if (frame.NumBodies > 0)
            {
                var bodyId = frame.GetBodyId(0);
                Debug.LogFormat("bodyId={0}", bodyId);
                this.skeleton = frame.GetSkeleton(0);
                for (var i = 0; i < (int)JointId.Count; i++)
                {
                    var joint = this.skeleton.Joints[i];
                    var pos   = joint.Position;
                    var rot   = joint.Orientation;
                    var v     = new Vector3(pos[0], -pos[1], pos[2]) * 0.004f;
                    var r     = new Quaternion(rot[1], rot[2], rot[3], rot[0]);
                    var obj   = debugObjects[i];
                    obj.transform.SetPositionAndRotation(v, r);
                }
            }
        }
    }