KinectInterop is a class that contains utility and interop functions and deals with different kinds of sensor interfaces.
        // Initialize the filter with a set of TransformSmoothParameters.
        public void Init(KinectInterop.SmoothParameters smoothParameters)
        {
            this.smoothParameters = smoothParameters;

            this.Reset();
            this.init = true;
        }
        /// <summary>
        /// Invoked if a gesture is cancelled.
        /// </summary>
        /// <returns>true</returns>
        /// <c>false</c>
        /// <param name="userId">User ID</param>
        /// <param name="userIndex">User index</param>
        /// <param name="gesture">Gesture type</param>
        /// <param name="joint">Joint type</param>
        public bool GestureCancelled(long userId, int userIndex, KinectGestures.Gestures gesture,
                                      KinectInterop.JointType joint)
        {
            // the gestures are allowed for the primary user only
            KinectManager manager = KinectManager.Instance;
            if (!manager || (userId != manager.GetPrimaryUserID()))
                return false;

            if (progressDisplayed)
            {
                progressDisplayed = false;

                /*if (gestureInfo != null)
                {
                    gestureInfo.GetComponent<GUIText>().text = String.Empty;
                }*/
            }

            return true;
        }
Esempio n. 3
0
        public Vector2 MapSpacePointToDepthCoords(KinectInterop.SensorData sensorData, Vector3 spacePos)
        {
            float fDepthX, fDepthY, fDepthZ;
            NuiTransformSkeletonToDepthImage(spacePos, out fDepthX, out fDepthY, out fDepthZ);

            fDepthX = Mathf.RoundToInt(fDepthX * sensorData.depthImageWidth);
            fDepthY = Mathf.RoundToInt(fDepthY * sensorData.depthImageHeight);
            fDepthZ = Mathf.RoundToInt(fDepthZ);

            Vector3 point = new Vector3(fDepthX, fDepthY, fDepthZ);

            return point;
        }
Esempio n. 4
0
        public Vector2 MapDepthPointToColorCoords(KinectInterop.SensorData sensorData, Vector2 depthPos, ushort depthVal)
        {
            int cx, cy;
            NuiImageGetColorPixelCoordinatesFromDepthPixelAtResolution(
                Constants.ColorImageResolution,
                Constants.DepthImageResolution,
                ref pcViewArea,
                (int)depthPos.x, (int)depthPos.y, (ushort)(depthVal << 3),
                out cx, out cy);

            return new Vector2(cx, cy);
        }
Esempio n. 5
0
 public bool MapColorFrameToDepthCoords(KinectInterop.SensorData sensorData, ref Vector2[] vDepthCoords)
 {
     return false;
 }
Esempio n. 6
0
        public bool InitBackgroundRemoval(KinectInterop.SensorData sensorData, bool isHiResPrefered)
        {
            int hr = InitBackgroundRemovalNative();

            if (hr < 0)
            {
                Debug.LogError(string.Format("Error initializing BackgroundRemoval: hr=0x{0:X}", hr));
            }

            bBackgroundRemovalInited = (hr >= 0);

            return bBackgroundRemovalInited;
        }
Esempio n. 7
0
        // returns the next joint in the hierarchy, as to the given joint
        public KinectInterop.JointType GetNextJoint(KinectInterop.JointType joint)
        {
            switch (joint)
            {
                case KinectInterop.JointType.SpineBase:
                    return KinectInterop.JointType.SpineMid;
                case KinectInterop.JointType.SpineMid:
                    return KinectInterop.JointType.Neck;
                case KinectInterop.JointType.Neck:
                    return KinectInterop.JointType.Head;

                case KinectInterop.JointType.ShoulderLeft:
                    return KinectInterop.JointType.ElbowLeft;
                case KinectInterop.JointType.ElbowLeft:
                    return KinectInterop.JointType.WristLeft;
                case KinectInterop.JointType.WristLeft:
                    return KinectInterop.JointType.HandLeft;

                case KinectInterop.JointType.ShoulderRight:
                    return KinectInterop.JointType.ElbowRight;
                case KinectInterop.JointType.ElbowRight:
                    return KinectInterop.JointType.WristRight;
                case KinectInterop.JointType.WristRight:
                    return KinectInterop.JointType.HandRight;

                case KinectInterop.JointType.HipLeft:
                    return KinectInterop.JointType.KneeLeft;
                case KinectInterop.JointType.KneeLeft:
                    return KinectInterop.JointType.AnkleLeft;
                case KinectInterop.JointType.AnkleLeft:
                    return KinectInterop.JointType.FootLeft;

                case KinectInterop.JointType.HipRight:
                    return KinectInterop.JointType.KneeRight;
                case KinectInterop.JointType.KneeRight:
                    return KinectInterop.JointType.AnkleRight;
                case KinectInterop.JointType.AnkleRight:
                    return KinectInterop.JointType.FootRight;
            }

            return joint;  // in case of end joint - Head, HandLeft, HandRight, FootLeft, FootRight
        }
Esempio n. 8
0
        // returns the index of the given joint in joint's array or -1 if joint is not applicable
        public int GetJointIndex(KinectInterop.JointType joint)
        {
            switch (joint)
            {
                case KinectInterop.JointType.SpineBase:
                    return (int)NuiSkeletonPositionIndex.HipCenter;
                case KinectInterop.JointType.SpineMid:
                    return (int)NuiSkeletonPositionIndex.Spine;
                case KinectInterop.JointType.SpineShoulder:
                case KinectInterop.JointType.Neck:
                    return (int)NuiSkeletonPositionIndex.ShoulderCenter;
                case KinectInterop.JointType.Head:
                    return (int)NuiSkeletonPositionIndex.Head;

                case KinectInterop.JointType.ShoulderLeft:
                    return (int)NuiSkeletonPositionIndex.ShoulderLeft;
                case KinectInterop.JointType.ElbowLeft:
                    return (int)NuiSkeletonPositionIndex.ElbowLeft;
                case KinectInterop.JointType.WristLeft:
                    return (int)NuiSkeletonPositionIndex.WristLeft;
                case KinectInterop.JointType.HandLeft:
                    return (int)NuiSkeletonPositionIndex.HandLeft;

                case KinectInterop.JointType.ShoulderRight:
                    return (int)NuiSkeletonPositionIndex.ShoulderRight;
                case KinectInterop.JointType.ElbowRight:
                    return (int)NuiSkeletonPositionIndex.ElbowRight;
                case KinectInterop.JointType.WristRight:
                    return (int)NuiSkeletonPositionIndex.WristRight;
                case KinectInterop.JointType.HandRight:
                    return (int)NuiSkeletonPositionIndex.HandRight;

                case KinectInterop.JointType.HipLeft:
                    return (int)NuiSkeletonPositionIndex.HipLeft;
                case KinectInterop.JointType.KneeLeft:
                    return (int)NuiSkeletonPositionIndex.KneeLeft;
                case KinectInterop.JointType.AnkleLeft:
                    return (int)NuiSkeletonPositionIndex.AnkleLeft;
                case KinectInterop.JointType.FootLeft:
                    return (int)NuiSkeletonPositionIndex.FootLeft;

                case KinectInterop.JointType.HipRight:
                    return (int)NuiSkeletonPositionIndex.HipRight;
                case KinectInterop.JointType.KneeRight:
                    return (int)NuiSkeletonPositionIndex.KneeRight;
                case KinectInterop.JointType.AnkleRight:
                    return (int)NuiSkeletonPositionIndex.AnkleRight;
                case KinectInterop.JointType.FootRight:
                    return (int)NuiSkeletonPositionIndex.FootRight;
            }

            return -1;
        }
Esempio n. 9
0
        public bool PollInfraredFrame(KinectInterop.SensorData sensorData)
        {
            uint infraredBufLen = (uint)(sensorData.infraredImage.Length * sizeof(ushort));

            var pInfraredData = GCHandle.Alloc(sensorData.infraredImage, GCHandleType.Pinned);
            bool newInfrared = GetInfraredFrameData(pInfraredData.AddrOfPinnedObject(), ref infraredBufLen, true);
            pInfraredData.Free();

            return newInfrared;
        }
Esempio n. 10
0
        public bool PollForegroundFrame(KinectInterop.SensorData sensorData, bool isHiResPrefered, Color32 defaultColor, bool bLimitedUsers, ICollection<int> alTrackedIndexes, ref byte[] foregroundImage)
        {
            uint frameLen = (uint)foregroundImage.Length;

            var pFrameData = GCHandle.Alloc(foregroundImage, GCHandleType.Pinned);
            bool newFrame = GetBackgroundRemovalFrameDataNative(pFrameData.AddrOfPinnedObject(), ref frameLen, true);
            pFrameData.Free();

            return newFrame;
        }
Esempio n. 11
0
        public bool PollDepthFrame(KinectInterop.SensorData sensorData)
        {
            uint depthBufLen = (uint)(sensorData.depthImage.Length * sizeof(ushort));

            var pDepthData = GCHandle.Alloc(sensorData.depthImage, GCHandleType.Pinned);
            bool newDepth = GetDepthFrameData(pDepthData.AddrOfPinnedObject(), ref depthBufLen, true);
            pDepthData.Free();

            if (newDepth)
            {
                uint depthLen = (uint)sensorData.depthImage.Length;

                for (int i = 0; i < depthLen; i++)
                {
                    if ((sensorData.depthImage[i] & 7) != 0)
                        sensorData.bodyIndexImage[i] = (byte)((sensorData.depthImage[i] & 7) - 1);
                    else
                        sensorData.bodyIndexImage[i] = 255;

                    sensorData.depthImage[i] = (ushort)(sensorData.depthImage[i] >> 3);
                }
            }

            return newDepth;
        }
Esempio n. 12
0
        public bool PollColorFrame(KinectInterop.SensorData sensorData)
        {
            uint videoBufLen = (uint)sensorData.colorImage.Length;

            var pColorData = GCHandle.Alloc(sensorData.colorImage, GCHandleType.Pinned);
            bool newColor = GetColorFrameData(pColorData.AddrOfPinnedObject(), ref videoBufLen, true);
            pColorData.Free();

            if (newColor)
            {
                for (int i = 0; i < videoBufLen; i += 4)
                {
                    byte btTmp = sensorData.colorImage[i];
                    sensorData.colorImage[i] = sensorData.colorImage[i + 2];
                    sensorData.colorImage[i + 2] = btTmp;
                    sensorData.colorImage[i + 3] = 255;
                }
            }

            return newColor;
        }
Esempio n. 13
0
        public bool PollBodyFrame(KinectInterop.SensorData sensorData, ref KinectInterop.BodyFrameData bodyFrame, ref Matrix4x4 kinectToWorld)
        {
            // get next body frame
            int hr = NuiSkeletonGetNextFrame(0, ref skeletonFrame);
            bool newSkeleton = (hr == 0);

            if (newSkeleton)
            {
                bodyFrame.liPreviousTime = bodyFrame.liRelativeTime;
                bodyFrame.liRelativeTime = skeletonFrame.liTimeStamp;

                hr = NuiTransformSmooth(ref skeletonFrame, ref smoothParameters);
                if (hr < 0)
                {
                    Debug.LogError("Skeleton Data Smoothing failed");
                }

                for (uint i = 0; i < sensorData.bodyCount; i++)
                {
                    NuiSkeletonData body = skeletonFrame.SkeletonData[i];

                    bodyFrame.bodyData[i].bIsTracked = (short)(body.eTrackingState == NuiSkeletonTrackingState.SkeletonTracked ? 1 : 0);

                    if (body.eTrackingState == NuiSkeletonTrackingState.SkeletonTracked)
                    {
                        // transfer body and joints data
                        bodyFrame.bodyData[i].liTrackingID = (long)body.dwTrackingID;

                        for (int j = 0; j < sensorData.jointCount; j++)
                        {
                            KinectInterop.JointData jointData = bodyFrame.bodyData[i].joint[j];

                            //jointData.jointType = (KinectInterop.JointType)j;
                            jointData.trackingState = (KinectInterop.TrackingState)body.eSkeletonPositionTrackingState[j];

                            if (jointData.trackingState != KinectInterop.TrackingState.NotTracked)
                            {
                                jointData.kinectPos = body.SkeletonPositions[j];
                                jointData.position = kinectToWorld.MultiplyPoint3x4(jointData.kinectPos);
                            }

                            jointData.orientation = Quaternion.identity;
                            //							Windows.Kinect.Vector4 vQ = body.JointOrientations[jointData.jointType].Orientation;
                            //							jointData.orientation = new Quaternion(vQ.X, vQ.Y, vQ.Z, vQ.W);

                            if (j == 0)
                            {
                                bodyFrame.bodyData[i].position = jointData.position;
                                bodyFrame.bodyData[i].orientation = jointData.orientation;
                            }

                            bodyFrame.bodyData[i].joint[j] = jointData;
                        }

                        // tranfer hand states
                        uint intCount = GetInteractorsCount();
                        string sDebug = string.Empty;

                        for (uint intIndex = 0; intIndex < intCount; intIndex++)
                        {
                            uint skeletonId = GetSkeletonTrackingID(intIndex);

                            if (skeletonId == body.dwTrackingID)
                            {
                                uint leftHandState = GetLeftHandState(intIndex);
                                InteractionHandEventType leftHandEvent = GetLeftHandEvent(intIndex);

                                uint rightHandState = GetRightHandState(intIndex);
                                InteractionHandEventType rightHandEvent = GetRightHandEvent(intIndex);

                                //							sDebug += string.Format("{0}-L:{1},{2};R:{3},{4}    ", skeletonId,
                                //							                        (int)leftHandState, (int)leftHandEvent,
                                //							                        (int)rightHandState, (int)rightHandEvent);

                                GetHandStateAndConf(skeletonId, false, leftHandState, leftHandEvent,
                                                    ref lastLeftHandEvent,
                                                    ref bodyFrame.bodyData[i].leftHandState,
                                                    ref bodyFrame.bodyData[i].leftHandConfidence);

                                GetHandStateAndConf(skeletonId, true, rightHandState, rightHandEvent,
                                                    ref lastRightHandEvent,
                                                    ref bodyFrame.bodyData[i].rightHandState,
                                                    ref bodyFrame.bodyData[i].rightHandConfidence);
                            }
                        }

                        if (intCount > 0 && sDebug.Length > 0)
                        {
                            Debug.Log(sDebug);
                        }
                    }
                }

                if (sensorData.hintHeightAngle)
                {
                    // get the floor plane
                    Vector4 vFloorPlane = skeletonFrame.vFloorClipPlane;
                    Vector3 floorPlane = new Vector3(vFloorPlane.x, vFloorPlane.y, vFloorPlane.z);

                    sensorData.sensorRotDetected = Quaternion.FromToRotation(floorPlane, Vector3.up);
                    sensorData.sensorHgtDetected = vFloorPlane.w;
                }
            }

            return newSkeleton;
        }
Esempio n. 14
0
        public bool IsBodyTurned(ref KinectInterop.BodyData bodyData)
        {
            //face = On: Face (357.0/1.0)
            //face = Off
            //|   Head_px <= -0.02
            //|   |   Neck_dx <= 0.08: Face (46.0/1.0)
            //|   |   Neck_dx > 0.08: Back (3.0)
            //|   Head_px > -0.02
            //|   |   SpineShoulder_px <= -0.02: Face (4.0)
            //|   |   SpineShoulder_px > -0.02: Back (64.0/1.0)

            bool bBodyTurned = false;

            if (bFaceTrackingInited)
            {
                bool bFaceOn = IsFaceTracked(bodyData.liTrackingID);

                if (bFaceOn)
                {
                    bBodyTurned = false;
                }
                else
                {
                    // face = Off
                    if (bodyData.joint[(int)KinectInterop.JointType.Head].posRel.x <= -0.02f)
                    {
                        bBodyTurned = (bodyData.joint[(int)KinectInterop.JointType.Neck].posDrv.x > 0.08f);
                    }
                    else
                    {
                        // Head_px > -0.02
                        bBodyTurned = (bodyData.joint[(int)KinectInterop.JointType.SpineShoulder].posRel.x > -0.02f);
                    }
                }
            }

            return bBodyTurned;
        }
Esempio n. 15
0
 public bool InitBackgroundRemoval(KinectInterop.SensorData sensorData, bool isHiResPrefered)
 {
     return KinectInterop.InitBackgroundRemoval(sensorData, isHiResPrefered);
 }
Esempio n. 16
0
 public int GetForegroundFrameLength(KinectInterop.SensorData sensorData, bool isHiResPrefered)
 {
     return GetBackgroundRemovalFrameLengthNative();
 }
Esempio n. 17
0
 public Rect GetForegroundFrameRect(KinectInterop.SensorData sensorData, bool isHiResPrefered)
 {
     return new Rect(0f, 0f, sensorData.depthImageWidth, sensorData.depthImageHeight);
 }
Esempio n. 18
0
 public bool UpdateBackgroundRemoval(KinectInterop.SensorData sensorData, bool isHiResPrefered, Color32 defaultColor)
 {
     int hr = UpdateBackgroundRemovalNative();
     return (hr >= 0);
 }
Esempio n. 19
0
 public bool GetMultiSourceFrame(KinectInterop.SensorData sensorData)
 {
     return false;
 }
Esempio n. 20
0
 public bool UpdateSensorData(KinectInterop.SensorData sensorData)
 {
     int hr = UpdateKinectSensor();
     return (hr == 0);
 }
Esempio n. 21
0
        //    // returns the joint at given index
        //    public KinectInterop.JointType GetJointAtIndex(int index)
        //    {
        //        switch(index)
        //        {
        //        case (int)NuiSkeletonPositionIndex.HipCenter:
        //            return KinectInterop.JointType.SpineBase;
        //        case (int)NuiSkeletonPositionIndex.Spine:
        //            return KinectInterop.JointType.SpineMid;
        //        case (int)NuiSkeletonPositionIndex.ShoulderCenter:
        //            return KinectInterop.JointType.Neck;
        //        case (int)NuiSkeletonPositionIndex.Head:
        //            return KinectInterop.JointType.Head;
        //            
        //        case (int)NuiSkeletonPositionIndex.ShoulderLeft:
        //            return KinectInterop.JointType.ShoulderLeft;
        //        case (int)NuiSkeletonPositionIndex.ElbowLeft:
        //            return KinectInterop.JointType.ElbowLeft;
        //        case (int)NuiSkeletonPositionIndex.WristLeft:
        //            return KinectInterop.JointType.WristLeft;
        //        case (int)NuiSkeletonPositionIndex.HandLeft:
        //            return KinectInterop.JointType.HandLeft;
        //            
        //        case (int)NuiSkeletonPositionIndex.ShoulderRight:
        //            return KinectInterop.JointType.ShoulderRight;
        //        case (int)NuiSkeletonPositionIndex.ElbowRight:
        //            return KinectInterop.JointType.ElbowRight;
        //        case (int)NuiSkeletonPositionIndex.WristRight:
        //            return KinectInterop.JointType.WristRight;
        //        case (int)NuiSkeletonPositionIndex.HandRight:
        //            return KinectInterop.JointType.HandRight;
        //            
        //        case (int)NuiSkeletonPositionIndex.HipLeft:
        //            return KinectInterop.JointType.HipLeft;
        //        case (int)NuiSkeletonPositionIndex.KneeLeft:
        //            return KinectInterop.JointType.KneeLeft;
        //        case (int)NuiSkeletonPositionIndex.AnkleLeft:
        //            return KinectInterop.JointType.AnkleLeft;
        //        case (int)NuiSkeletonPositionIndex.FootLeft:
        //            return KinectInterop.JointType.FootLeft;
        //            
        //        case (int)NuiSkeletonPositionIndex.HipRight:
        //            return KinectInterop.JointType.HipRight;
        //        case (int)NuiSkeletonPositionIndex.KneeRight:
        //            return KinectInterop.JointType.KneeRight;
        //        case (int)NuiSkeletonPositionIndex.AnkleRight:
        //            return KinectInterop.JointType.AnkleRight;
        //        case (int)NuiSkeletonPositionIndex.FootRight:
        //            return KinectInterop.JointType.FootRight;
        //        }
        //        
        //        return (KinectInterop.JointType)(-1);
        //    }
        // returns the parent joint of the given joint
        public KinectInterop.JointType GetParentJoint(KinectInterop.JointType joint)
        {
            switch (joint)
            {
                case KinectInterop.JointType.SpineBase:
                    return KinectInterop.JointType.SpineBase;

                case KinectInterop.JointType.ShoulderLeft:
                case KinectInterop.JointType.ShoulderRight:
                    return KinectInterop.JointType.Neck;

                case KinectInterop.JointType.HipLeft:
                case KinectInterop.JointType.HipRight:
                    return KinectInterop.JointType.SpineBase;
            }

            return (KinectInterop.JointType)((int)joint - 1);
        }
Esempio n. 22
0
        private void GetHandStateAndConf(uint skeletonId, bool isRightHand, uint handState, InteractionHandEventType handEvent,
                                         ref Dictionary<uint, InteractionHandEventType> lastHandEvent,
                                         ref KinectInterop.HandState refHandState,
                                         ref KinectInterop.TrackingConfidence refHandConf)
        {
            bool bHandPrimary = (handState & (uint)NuiHandpointerState.Active) != 0;
            refHandConf = bHandPrimary ? KinectInterop.TrackingConfidence.High : KinectInterop.TrackingConfidence.Low;

            if (!lastHandEvent.ContainsKey(skeletonId))
            {
                lastHandEvent[skeletonId] = InteractionHandEventType.Release;
            }

            if (handEvent == InteractionHandEventType.Grip ||
               handEvent == InteractionHandEventType.Release)
            {
                if (lastHandEvent[skeletonId] != handEvent)
                {
                    //Debug.Log(string.Format("{0} - {1}, event: {2}", skeletonId, !isRightHand ? "left" : "right", handEvent));
                    lastHandEvent[skeletonId] = handEvent;
                }
            }

            if (bHandPrimary)
            {
                switch (lastHandEvent[skeletonId])
                {
                    case InteractionHandEventType.Grip:
                        refHandState = KinectInterop.HandState.Closed;
                        break;

                    case InteractionHandEventType.Release:
                        refHandState = KinectInterop.HandState.Open;
                        break;
                }
            }
            else
            {
                //			if(lastHandEvent[skeletonId] != InteractionHandEventType.Release)
                //			{
                //				Debug.Log(string.Format("{0} - old: {1}, NONE: {2}", skeletonId, lastHandEvent[skeletonId], InteractionHandEventType.Release));
                //				lastHandEvent[skeletonId] = InteractionHandEventType.Release;
                //			}

                refHandState = KinectInterop.HandState.NotTracked;
            }
        }
Esempio n. 23
0
 public bool IsBodyTurned(ref KinectInterop.BodyData bodyData)
 {
     return false;
 }
Esempio n. 24
0
 public void CloseSensor(KinectInterop.SensorData sensorData)
 {
     FinishKinectInteraction();
     ShutdownKinectSensor();
 }
Esempio n. 25
0
        public bool MapDepthFrameToColorCoords(KinectInterop.SensorData sensorData, ref Vector2[] vColorCoords)
        {
            // uncomment this block of code, if you need the user cut-out image (lowers the FPS a lot)

            //		if(sensorData.depthImage != null && sensorData.colorImage != null)
            //		{
            //			int i = 0, cx = 0, cy = 0;
            //
            //			for(int y = 0; y < sensorData.depthImageHeight; y++)
            //			{
            //				for(int x = 0; x < sensorData.depthImageWidth; x++)
            //				{
            //					ushort dv = sensorData.depthImage[i];
            //
            //					NuiImageGetColorPixelCoordinatesFromDepthPixelAtResolution(
            //						Constants.ColorImageResolution,
            //						Constants.DepthImageResolution,
            //						ref pcViewArea,
            //						x, y, (ushort)(dv << 3),
            //						out cx, out cy);
            //
            //					vColorCoords[i] = new Vector2(cx, cy);
            //					i++;
            //				}
            //			}
            //
            //			return true;
            //		}

            return false;
        }
Esempio n. 26
0
 public void FinishBackgroundRemoval(KinectInterop.SensorData sensorData)
 {
     FinishBackgroundRemovalNative();
     bBackgroundRemovalInited = false;
 }
Esempio n. 27
0
        public Vector3 MapDepthPointToSpaceCoords(KinectInterop.SensorData sensorData, Vector2 depthPos, ushort depthVal)
        {
            float fDepthX = depthPos.x / sensorData.depthImageWidth;
            float fDepthY = depthPos.y / sensorData.depthImageHeight;

            Vector3 point = NuiTransformDepthImageToSkeleton(fDepthX, fDepthY, depthVal);

            return point;
        }
Esempio n. 28
0
        public void FixJointOrientations(KinectInterop.SensorData sensorData, ref KinectInterop.BodyData bodyData)
        {
            // fix the hips-to-spine tilt (it is about 40 degrees to the back)
            int hipsIndex = (int)KinectInterop.JointType.SpineBase;

            Quaternion quat = bodyData.joint[hipsIndex].normalRotation;
            quat *= Quaternion.Euler(40f, 0f, 0f);
            bodyData.joint[hipsIndex].normalRotation = quat;

            Vector3 mirroredAngles = quat.eulerAngles;
            mirroredAngles.y = -mirroredAngles.y;
            mirroredAngles.z = -mirroredAngles.z;
            bodyData.joint[hipsIndex].mirroredRotation = Quaternion.Euler(mirroredAngles);

            bodyData.normalRotation = bodyData.joint[hipsIndex].normalRotation;
            bodyData.mirroredRotation = bodyData.joint[hipsIndex].mirroredRotation;
        }
Esempio n. 29
0
        public KinectInterop.SensorData OpenDefaultSensor(KinectInterop.FrameSource dwFlags, float sensorAngle, bool bUseMultiSource)
        {
            sourceFlags = dwFlags;

            NuiInitializeFlags nuiFlags = // NuiInitializeFlags.UsesNone;
                NuiInitializeFlags.UsesSkeleton | NuiInitializeFlags.UsesDepthAndPlayerIndex;

            if ((dwFlags & KinectInterop.FrameSource.TypeBody) != 0)
            {
                nuiFlags |= NuiInitializeFlags.UsesSkeleton;
            }

            if ((dwFlags & KinectInterop.FrameSource.TypeColor) != 0)
            {
                nuiFlags |= NuiInitializeFlags.UsesColor;
            }

            if ((dwFlags & KinectInterop.FrameSource.TypeDepth) != 0)
            {
                nuiFlags |= NuiInitializeFlags.UsesDepthAndPlayerIndex;
            }

            if ((dwFlags & KinectInterop.FrameSource.TypeBodyIndex) != 0)
            {
                nuiFlags |= NuiInitializeFlags.UsesDepthAndPlayerIndex;
            }

            if ((dwFlags & KinectInterop.FrameSource.TypeInfrared) != 0)
            {
                nuiFlags |= (NuiInitializeFlags.UsesColor | (NuiInitializeFlags)0x8000);
            }

            if ((dwFlags & KinectInterop.FrameSource.TypeAudio) != 0)
            {
                nuiFlags |= NuiInitializeFlags.UsesAudio;
            }

            FacetrackingManager[] faceManagers = GameObject.FindObjectsOfType(typeof(FacetrackingManager)) as FacetrackingManager[];
            if (faceManagers != null && faceManagers.Length > 0)
            {
                for (int i = 0; i < faceManagers.Length; i++)
                {
                    if (faceManagers[i].enabled)
                    {
                        //Debug.Log("Found FacetrackingManager => UsesColor");
                        nuiFlags |= NuiInitializeFlags.UsesColor;
                        break;
                    }
                }
            }

            SpeechManager[] speechManagers = GameObject.FindObjectsOfType(typeof(SpeechManager)) as SpeechManager[];
            if (speechManagers != null && speechManagers.Length > 0)
            {
                for (int i = 0; i < speechManagers.Length; i++)
                {
                    if (speechManagers[i].enabled)
                    {
                        //Debug.Log("Found SpeechManager => UsesAudio");
                        nuiFlags |= NuiInitializeFlags.UsesAudio;
                        break;
                    }
                }
            }

            int hr = InitKinectSensor(nuiFlags, true, (int)Constants.ColorImageResolution, (int)Constants.DepthImageResolution, Constants.IsNearMode);

            if (hr == 0)
            {
                // set sensor angle
                SetKinectElevationAngle((int)sensorAngle);

                // initialize Kinect interaction
                hr = InitKinectInteraction();
                if (hr != 0)
                {
                    Debug.LogError(string.Format("Error initializing KinectInteraction: hr=0x{0:X}", hr));
                }

                KinectInterop.SensorData sensorData = new KinectInterop.SensorData();

                sensorData.bodyCount = Constants.NuiSkeletonCount;
                sensorData.jointCount = Constants.JointCount;

                sensorData.depthCameraFOV = 46.6f;
                sensorData.colorCameraFOV = 48.6f;
                sensorData.depthCameraOffset = 0.01f;
                sensorData.faceOverlayOffset = 0.01f;

                NuiImageResolutionToSize(Constants.ColorImageResolution, out sensorData.colorImageWidth, out sensorData.colorImageHeight);
                //			sensorData.colorImageWidth = Constants.ColorImageWidth;
                //			sensorData.colorImageHeight = Constants.ColorImageHeight;

                if ((dwFlags & KinectInterop.FrameSource.TypeColor) != 0)
                {
                    //colorStreamHandle =  GetColorStreamHandle();
                    sensorData.colorImage = new byte[sensorData.colorImageWidth * sensorData.colorImageHeight * 4];
                }

                NuiImageResolutionToSize(Constants.DepthImageResolution, out sensorData.depthImageWidth, out sensorData.depthImageHeight);
                //			sensorData.depthImageWidth = Constants.DepthImageWidth;
                //			sensorData.depthImageHeight = Constants.DepthImageHeight;

                if ((dwFlags & KinectInterop.FrameSource.TypeDepth) != 0)
                {
                    //depthStreamHandle = GetDepthStreamHandle();
                    sensorData.depthImage = new ushort[sensorData.depthImageWidth * sensorData.depthImageHeight];
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeBodyIndex) != 0)
                {
                    sensorData.bodyIndexImage = new byte[sensorData.depthImageWidth * sensorData.depthImageHeight];
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeInfrared) != 0)
                {
                    sensorData.infraredImage = new ushort[sensorData.colorImageWidth * sensorData.colorImageHeight];
                }

                if ((dwFlags & KinectInterop.FrameSource.TypeBody) != 0)
                {
                    skeletonFrame = new NuiSkeletonFrame()
                    {
                        SkeletonData = new NuiSkeletonData[Constants.NuiSkeletonCount]
                    };

                    // default values used to pass to smoothing function
                    smoothParameters = new NuiTransformSmoothParameters();

                    smoothParameters.fSmoothing = 0.5f;
                    smoothParameters.fCorrection = 0.5f;
                    smoothParameters.fPrediction = 0.5f;
                    smoothParameters.fJitterRadius = 0.05f;
                    smoothParameters.fMaxDeviationRadius = 0.04f;
                }

                return sensorData;
            }
            else
            {
                Debug.LogError("InitKinectSensor failed: " + GetNuiErrorString(hr));
            }

            return null;
        }
Esempio n. 30
0
 public void FreeMultiSourceFrame(KinectInterop.SensorData sensorData)
 {
 }