使用 Kinect C# 从红外位图中裁剪人脸图像

Crop face image from infrared bitmap using Kinect C#

我正在尝试从 Kinect 获取 Head/Face png 格式的图像,以便稍后处理面部图像。 我可以通过使用类似的东西来计算颜色的面部坐标:

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);

我使用返回值裁剪 colorBitmap 并将其存储在我的驱动器上。

var Headbounds = ComputeHeadBounds();
var CroppedImage = colorBitmap.Crop(Headbounds);
//Save 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);
}

我尝试了很多方法,包括锁定位图,但也没有用。 最后,我发现一旦我将红外图像保存在驱动器上并稍后尝试裁剪它,它就会成功。我保存了程序生成的所有图像以及用于裁剪的坐标,然后 运行 一个单独的过程来裁剪它们。