Asked by:
Restricted Pixel Area
Question

All replies

hi,
the SkeletalViewer How To (Get depth data) will help you. Every pixel is in pBufferRun and has 16 bits (highest 3 for player index and lowest 13 for depth).

public bool CheckForOpenHand(DepthImageFrame depth, Skeleton first) { float RightHandPX = (first.Joints[JointType.HandRight].Position.X * depth.Width / 2); float RightHandPY = (first.Joints[JointType.HandRight].Position.Y * depth.Height / 2); float RightWristPX = (first.Joints[JointType.WristRight].Position.X * depth.Width / 2); float RightWristPY = (first.Joints[JointType.WristRight].Position.Y * depth.Height / 2); RightHandPX = CalcPixelX(RightHandPX, depth); RightWristPX = CalcPixelX(RightWristPX, depth); RightHandPY = CalcPixelY(RightHandPY, depth); RightWristPY = CalcPixelY(RightWristPY, depth); float RefDistanceY = Math.Abs(RightHandPY  RightWristPY); float RefDistanceX = Math.Abs(RightWristPX  RightHandPX); int RefDistance = (int) Math.Round(Math.Max(RefDistanceX, RefDistanceY)); short[] rawDepthData = new short[depth.PixelDataLength]; depth.CopyPixelDataTo(rawDepthData); for (int depthIndexY = (int)Math.Round(RightHandPY)  RefDistance; depthIndexY < (int)Math.Round(RightHandPY) + RefDistance; depthIndexY++) { for (int depthIndexX = (int)Math.Round(RightHandPX)  RefDistance; depthIndexX < (int)Math.Round(RightHandPX) + RefDistance; depthIndexX++) { int dist = rawDepthData[depthIndexY * depthIndexX]; if ((dist < ((first.Joints[JointType.HandRight].Position.Z * 1000) + 50)) && (dist > ((first.Joints[JointType.HandRight].Position.Z * 1000)  100))) { count++; } } } if (count > RefDistance * 2 * RefDistance * 2 * 20 / 100) { count = 0; return true; } else { count = 0; return false; } }
this is my code to check if the hand are open or close.
it just test a area near the hand defined by the distance between the hand joint and the wrist joint. it test every pixel.
if the distance of one pixel match with the intervel that i insert it increase the counter. at last i compare the counter with the number of pixels in my area if counter is greater than 20% of the total number of pixels it will return true.
I had tried somethings, and i think is in the "dist" i think it doesn't giv the right value..
i am new in that kind of language and amateur in programation.
my english is to bad.. i hope you can help me.

Please see my answer in this post: http://social.msdn.microsoft.com/Forums/enUS/kinectsdknuiapi/thread/3f168159e4e54dba97e1543e863d51de
John
K4W Dev
 Proposed as answer by John Elsbree [MSFT] Friday, May 4, 2012 5:44 PM