Andrew Johnson

Andrew Johnson

  • 2.2k
  • 1
  • 3.6k

Kinect Face Tracking, Positioning a Rectangle

Jun 13 2013 11:26 AM
Hey guys have used this site a good few times and find it very helpful, usually I can fix my own problems and just don't like to bug people.  However I have just began using the Kinect SDK and have managed to get the depth and color streams displaying in a VS2012 WPF program in an Image.

That was fine, now usually I have used windows forms and have had it fairly easy drawing a rectangle over the image.  With a transition to WPF I've had to learn a few things, firstly I swapped the display of the depth stream over to the background of a canvas and was hoping to use the FaceTrackFrame.FaceRect to directly position and proportion a Rectangle object over the face.  Sounds simple enough right?  Well I have created the rectangle, added it to the canvas 'canvas.Children.Add(rect2);'  now my sizing and positioning code is as so

rect2.Width = faceFrame.FaceRect.Width;
rect2.Height = faceFrame.FaceRect.Height;

Canvas.SetTop(rect2, faceFrame.FaceRect.Top);

Which should really just be drawing the otherwise unseen FaceRect right?  however it seems to draw in a slightly off position, the offset isn't consistent as I move around the room when I am at the far right of the resulting depth stream the rectangle is almost correctly positioned however when I am near the center or especially the far left the rectangle is clearly in the wrong place.  Please see the image in the link to explain better.

I really cannot see what is going on here and would be greatful for some help it has been driving me INSANE!
Andrew Johnson
(making a robot for a project)

EDIT (fixed, kinda)

Due to the positioning of the cameras the rectangle is only true when overlayed on the colour video stream.  So my next question is how would I obtain the correct area on the depth camera stream?  That is so that I could cut a rectangle from the video and depth relating to a persons face?  I see there is a MapColorFrameToDepthFrame method for converting the whole color frame but cannot see how to use it.