コード例 #1
0
ファイル: BodyTexture.cs プロジェクト: novogrammer/ofxKyonyu
        public BodyTexture(Microsoft.Research.Kinect.Nui.Runtime nui,Microsoft.Research.Kinect.Nui.SkeletonData skeleton,byte[] latestVideoBytes)
        {
            this.skeleton = skeleton;
            this.latestVideoBytes = latestVideoBytes;
            this.nui = nui;
            byte[] thumbBitsLeft = new byte[imgWidth * imgHeight * 4];
            byte[] thumbBitsRight = new byte[imgWidth * imgHeight * 4];

            this.calcPositions();

            for (int y = 0; y < imgHeight; y++)
            {
                for (int x = 0; x < imgWidth; x++)
                {
                    float screenXLeft = 0;
                    float screenYLeft = 0;
                    float screenXRight = 0;
                    float screenYRight = 0;
                    getPosition2D((float)x * 0.5f, y, ref screenXLeft, ref screenYLeft);
                    getPosition2D((float)(x + imgWidth) * 0.5f, y, ref screenXRight, ref screenYRight);

                    if (screenXRight > 1 || screenXRight < 0) screenXRight = 0;
                    if (screenYRight > 1 || screenYRight < 0) screenYRight = 0;
                    if (screenXLeft > 1 || screenXLeft < 0) screenXLeft = 0;
                    if (screenYLeft > 1 || screenYLeft < 0) screenYLeft = 0;

                    int origIndexLeft = ((int)(screenXLeft * (float)origWidth) + (int)(screenYLeft * (float)origHeight) * origWidth) * 4;
                    int origIndexRight = ((int)(screenXRight * (float)origWidth) + (int)(screenYRight * (float)origHeight) * origWidth) * 4;

                    int newIndex = (x + y * imgWidth) * 4;

                    byte[] leftBytesOrig = {
                                               latestVideoBytes[origIndexLeft + 0],
                                               latestVideoBytes[origIndexLeft + 1],
                                               latestVideoBytes[origIndexLeft + 2],
                                               latestVideoBytes[origIndexLeft + 3],
                                           };
                    byte[] rightBytesOrig = {
                                               latestVideoBytes[origIndexRight + 0],
                                               latestVideoBytes[origIndexRight + 1],
                                               latestVideoBytes[origIndexRight + 2],
                                               latestVideoBytes[origIndexRight + 3],
                                           };
                    byte[] leftBytes = getColorAdjustedRGBA(leftBytesOrig, (double)y / (double)imgHeight);
                    byte[] rightBytes = getColorAdjustedRGBA(rightBytesOrig, (double)y / (double)imgHeight);

                    thumbBitsLeft[newIndex + 0] = leftBytes[0];
                    thumbBitsLeft[newIndex + 1] = leftBytes[1];
                    thumbBitsLeft[newIndex + 2] = leftBytes[2];
                    thumbBitsLeft[newIndex + 3] = leftBytes[3];

                    thumbBitsRight[newIndex + 0] = rightBytes[0];
                    thumbBitsRight[newIndex + 1] = rightBytes[1];
                    thumbBitsRight[newIndex + 2] = rightBytes[2];
                    thumbBitsRight[newIndex + 3] = rightBytes[3];
                }
            }
            ImageSourceLeft = BitmapSource.Create(imgWidth, imgHeight, 96, 96, PixelFormats.Bgr32, null, thumbBitsLeft, imgWidth * 4);
            ImageSourceRight = BitmapSource.Create(imgWidth, imgHeight, 96, 96, PixelFormats.Bgr32, null, thumbBitsRight, imgWidth * 4);
        }
コード例 #2
0
        /// <summary>
        /// Checks the gesture.
        /// </summary>
        /// <param name="skeleton">The skeleton.</param>
        /// <returns>GesturePartResult based on if the gesture part has been completed</returns>
        public GesturePartResult CheckGesture(Microsoft.Research.Kinect.Nui.SkeletonData skeleton)
        {
            // //Right hand in front of right Shoulder
            if (skeleton.Joints[JointID.HandRight].Position.Z < skeleton.Joints[JointID.ElbowRight].Position.Z && skeleton.Joints[JointID.HandLeft].Position.Y < skeleton.Joints[JointID.HipCenter].Position.Y)
            {
                // Debug.WriteLine("GesturePart 2 - Right hand in front of right shoulder - PASS");
                // //right hand below shoulder height but above hip height
                if (skeleton.Joints[JointID.HandRight].Position.Y <skeleton.Joints[JointID.Head].Position.Y && skeleton.Joints[JointID.HandRight].Position.Y> skeleton.Joints[JointID.HipCenter].Position.Y)
                {
                    // Debug.WriteLine("GesturePart 2 - right hand below shoulder height but above hip height - PASS");
                    // //right hand left of left Shoulder
                    if (skeleton.Joints[JointID.HandRight].Position.X < skeleton.Joints[JointID.ShoulderLeft].Position.X)
                    {
                        // Debug.WriteLine("GesturePart 2 - right hand left of left Shoulder - PASS");
                        return(GesturePartResult.Suceed);
                    }

                    // Debug.WriteLine("GesturePart 2 - right hand left of right Shoulder - UNDETERMINED");
                    return(GesturePartResult.Pausing);
                }

                // Debug.WriteLine("GesturePart 2 - right hand below shoulder height but above hip height - FAIL");
                return(GesturePartResult.Fail);
            }

            // Debug.WriteLine("GesturePart 2 - Right hand in front of right Shoulder - FAIL");
            return(GesturePartResult.Fail);
        }
コード例 #3
0
        /// <summary>
        /// Checks the gesture.
        /// </summary>
        /// <param name="skeleton">The skeleton.</param>
        /// <returns>GesturePartResult based on if the gesture part has been completed</returns>
        public GesturePartResult CheckGesture(Microsoft.Research.Kinect.Nui.SkeletonData skeleton)
        {
            // Left and right hands below hip
            if (skeleton.Joints[JointID.HandLeft].Position.Y < skeleton.Joints[JointID.HipCenter].Position.Y && skeleton.Joints[JointID.HandRight].Position.Y < skeleton.Joints[JointID.HipCenter].Position.Y)
            {
                // left hand 0.3 to left of center hip
                if (skeleton.Joints[JointID.HandLeft].Position.X < skeleton.Joints[JointID.HipCenter].Position.X - 0.3)
                {
                    // left hand 0.2 to left of left elbow
                    if (skeleton.Joints[JointID.HandLeft].Position.X < skeleton.Joints[JointID.ElbowLeft].Position.X - 0.2)
                    {
                        return(GesturePartResult.Suceed);
                    }
                }

                return(GesturePartResult.Pausing);
            }

            return(GesturePartResult.Fail);
        }