我遇到了EmguCV的问题。我使用了一个演示应用程序,并将其编辑为我的需要。 它包括以下功能:Emgucv转换<Hsv, Byte>()图片
public override Image<Gray, byte> DetectSkin(Image<Bgr, byte> Img, IColor min, IColor max)
{
Image<Hsv, Byte> currentHsvFrame = Img.Convert<Hsv, Byte>();
Image<Gray, byte> skin = new Image<Gray, byte>(Img.Width, Img.Height);
skin = currentHsvFrame.InRange((Hsv)min,(Hsv)max);
return skin;
}
在演示应用程序,图片来自于视频。该框架是从这样的视频中捕获:
Image<Bgr, Byte> currentFrame;
grabber = new Emgu.CV.Capture(@".\..\..\..\M2U00253.MPG");
grabber.QueryFrame();
currentFrame = grabber.QueryFrame();
在我的应用程序中,图像来自microsoft kinect流。
我用下面的功能:
private void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
{
using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
{
if (colorFrame != null)
{
// Copy the pixel data from the image to a temporary array
colorFrame.CopyPixelDataTo(this.colorPixels);
// Write the pixel data into our bitmap
this.colorBitmap.WritePixels(
new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
this.colorPixels,
this.colorBitmap.PixelWidth * sizeof(int),
0);
Bitmap b = BitmapFromWriteableBitmap(this.colorBitmap);
currentFrame = new Image<Bgr, byte>(b);
currentFrameCopy = currentFrame.Copy();
skinDetector = new YCrCbSkinDetector();
Image<Gray, Byte> skin = skinDetector.DetectSkin(currentFrame, YCrCb_min, YCrCb_max);
}
}
}
private static System.Drawing.Bitmap BitmapFromWriteableBitmap(WriteableBitmap writeBmp)
{
System.Drawing.Bitmap bmp;
using (System.IO.MemoryStream outStream = new System.IO.MemoryStream())
{
BitmapEncoder enc = new BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create((BitmapSource)writeBmp));
enc.Save(outStream);
bmp = new System.Drawing.Bitmap(outStream);
}
return bmp;
}
现在,演示应用程序的工作,而我没有。矿给出了以下异常:
而且,这里的图像,包含以下内容:
我真的不明白这一点例外。而且,现在,当我运行演示程序时,工作应用程序图像包含:
在我眼里,这是完全一样的。我真的不明白这一点。帮助非常欢迎!
非常感谢您的评论。我仍然无法解决如何解决它。当我使用你的代码时,我得到了一些我似乎无法解决的错误(可能是因为我缺乏知识)。但是,这里是我使用的代码:https://dl.dropboxusercontent.com/u/71972424/codeHandTracker.zip – Arnout
我得到了您的代码工作,但它仍然给我同样的错误。 – Arnout
如果有兴趣,这里是包括演示在内的完整解决方案的链接。 https://dl.dropboxusercontent.com/u/71972424/HandGestureRecognition.rar – Arnout