使用EMGUcv进行颜色跟踪

我正在尝试制作一个彩色对象跟踪器,它使用二进制图像和斑点检测器来跟踪目标类型: https : //www.youtube.com/watch?v = 9qky6g8NRmI 。 但是我无法弄清楚ThresholdBinary()方法是如何工作的,以及它是否是正确的。

以下是代码的相关部分:

cam._SmoothGaussian(3); blobDetector.Update(cam); Image binaryImage = cam.ThresholdBinary(new Bgr(145,0,145),new Bgr(0,0,0)); Image binaryImageGray = binaryImage.Conver(); blobTracker.Process(cam, binaryImageGray); foreach (MCvBlob blob in blobTracker) { cam.Draw((Rectangle)blob, new Bgr(0,0,255),2); } 

当我显示binaryImage时,我甚至没有得到blob。 我只是得到一个黑色的图像。

通常,此类应用程序的彩色斑点检测部分的工作原理如下:

  1. 将图像转换为HSV (色调,饱和度,值)颜色空间。
  2. 使用色调值接近目标值的所有像素过滤色调通道。 阈值处理通常会为所有像素提供高于低于阈值的值。 您对某些目标值附近的像素感兴趣。
  3. 过滤所获得的蒙版,可能使用饱和度/值通道或移除小斑点。 理想情况下,只有目标blob保留。

一些示例代码旨在找到绿色对象(hue~50),例如video中显示的绿球:

 // 1. Convert the image to HSV using (Image hsv = original.Convert()) { // 2. Obtain the 3 channels (hue, saturation and value) that compose the HSV image Image[] channels = hsv.Split(); try { // 3. Remove all pixels from the hue channel that are not in the range [40, 60] CvInvoke.cvInRangeS(channels[0], new Gray(40).MCvScalar, new Gray(60).MCvScalar, channels[0]); // 4. Display the result imageBox1.Image = channels[0]; } finally { channels[1].Dispose(); channels[2].Dispose(); } }