c#-如何在Emgu CV中使用CvInRange
作者:互联网
我正在学习使用Emgu CV,偶然发现了这个Open CV示例:http://aishack.in/tutorials/tracking-colored-objects-in-opencv/
我想通过创建以下代码在Emgu中重新创建CvInRange函数:
// create upper & lower limit (HSV)
MCvScalar botLimit = new MCvScalar(20, 100, 100);
MCvScalar uprLimit = new MCvScalar(30, 255, 255);
// prepare the destination
Image<Hsv, byte> imageHSVDest = new Image<Hsv, byte>(imageWidth, imageHeight);
//
CvInvoke.cvInRange(imageHSV, botLimit, uprLimit, imageHSVDest);
CvInvoke.cvInRange()产生此错误消息(在vs2010中):
Error 1 The best overloaded method match for ‘Emgu.CV.CvInvoke.cvInRange(System.IntPtr, System.IntPtr, System.IntPtr, System.IntPtr)’ has some invalid arguments
Error 2 Argument 2: cannot convert from ‘Emgu.CV.Structure.MCvScalar’ to ‘System.IntPtr’
Error 3 Argument 3: cannot convert from ‘Emgu.CV.Structure.MCvScalar’ to ‘System.IntPtr’
似乎存在不匹配的数据类型.我搜索了如何将Emgu MCvScalar转换为IntPtr,但无济于事.
我通过转换示例中的OpenCV cvScalar(20,100,100)使用了MCvScalar.错了吗
解决方法:
请改使用内置的Emgu CV函数InRange.然后,它看起来像这样:
Hsv lowerLimit = new Hsv(20, 100, 100);
Hsv upperLimit = new Hsv(30, 255, 255);
Image<Gray, byte> imageHSVDest = imageHSV.InRange(lowerLimit, upperLimit);
请注意,imageHSVDest是二进制图像,其值为0(黑色)和255(白色).
标签:emgucv,c 来源: https://codeday.me/bug/20191030/1971691.html