我刚刚开始使用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
有一个有效值,而不是null。我想知道为什么会出现这种异常,是否存在图像格式问题?
答案 0 :(得分:0)
尝试使用:
Image<Gray, byte> im = new Image<Gray, byte>(b);