I am trying to get Head/Face images in png from Kinect so I can process face images later. I am able to compute Face co-ordinates in color by using something like:
var face = faceFrame.FaceBoundingBoxInColorSpace;
double x = face.Left;
double y = face.Top;
double w = face.Right - face.Left;
double h = face.Bottom - face.Top;
..additional padding to get face bounds
return new Rect(x, y, w, h);
I use returned values to crop colorBitmap and store it on my drive.
var Headbounds = ComputeHeadBounds();
var CroppedImage = colorBitmap.Crop(Headbounds);
//Save Image..
When I try similar to get Infrared face image, it does not work correctly. I get a black coloured image.
var face = faceFrame.FaceBoundingBoxInInfraredSpace;
double x = face.Left;
double y = face.Top;
double w = face.Right - face.Left;
double h = face.Bottom - face.Top;
var coordinates = ComputeInfraredHeadBounds();
var InfraCroppedImage = infraBitmap.Crop(coordinates);
//Saving FaceImage
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(InfraCroppedImage));
using (var fs = new FileStream(projectDirectory + filename + ".png", FileMode.Create, FileAccess.Write))
{
encoder.Save(fs);
}
I tried to many things including locking the bitmap but that also did not work. Finally, I figured that once I save infrared image on drive and later try to crop it, it works successfully. I saved the all images generated by the program with co-ordinates for cropping and later ran a separate process to crop them.