我刚开始使用 EmguCV 进行 Kinect 图像处理,从深度流创建 EmguCV 图像时出现 ArgumentException,如下所示:
private void DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
DepthImageFrame df = e.OpenDepthImageFrame();
if (df != null)
{
short[] data = new short[df.PixelDataLength];
df.CopyPixelDataTo(data);
Bitmap b = data.ToBitMap(df.Width, df.Height, System.Drawing.Imaging.PixelFormat.Format16bppGrayScale);
Image<Gray, short> im = new Image<Gray, short>(b); //run-time exception here
ToBitmap 扩展方法完全复制自 Kinect SDK 教程示例:
public static Bitmap ToBitmap(this short[] data, int width, int height, System.Drawing.Imaging.PixelFormat format)
{
var bitmap = new Bitmap(width, height, format);
var bitmapData = bitmap.LockBits(
new System.Drawing.Rectangle(0, 0, bitmap.Width,
bitmap.Height),
ImageLockMode.WriteOnly,
bitmap.PixelFormat);
Marshal.Copy(data, 0, bitmapData.Scan0, data.Length);
bitmap.UnlockBits(bitmapData);
return bitmap;
}
我检查了它b
有一个有效的值,而不是空值。我想知道为什么会出现这个异常,是图像格式问题吗?