Color tracking using EMGUcv

 ̄綄美尐妖づ 提交于 2019-12-10 09:45:59

问题


I am trying to make an colored object tracker which uses a binary image and blob detector to follow the target sort of like this: https://www.youtube.com/watch?v=9qky6g8NRmI . However I can not figure out how the ThresholdBinary() method work and if it is even the right one.

Here is a relevant bit of the code:

cam._SmoothGaussian(3);

blobDetector.Update(cam);
Image<Bgr,byte> binaryImage = cam.ThresholdBinary(new Bgr(145,0,145),new Bgr(0,0,0));
Image<Gray,byte> binaryImageGray = binaryImage.Conver<Gray,byte>();

blobTracker.Process(cam, binaryImageGray);

foreach (MCvBlob blob in blobTracker)
{
   cam.Draw((Rectangle)blob, new Bgr(0,0,255),2);
}

When I display the binaryImage I do not even get blobs. I just get a black image.


回答1:


Typically, the colored blob detection part of such an application works along the lines of:

  1. Convert the image to HSV (hue, saturation, value) color space.
  2. Filter the hue channel for all pixels with a hue value near the target value. Thresholding will typically give you all pixels with a value above or below the threshold. You are interested in the pixels near some target value.
  3. Filter the obtained mask some more, possibly using the saturation/value channels or by removing small blobs. Ideally only the target blob remains.

Some sample code that aims to find a green object (hue ~50) such as the green ball shown in the video:

// 1. Convert the image to HSV
using (Image<Hsv, byte> hsv = original.Convert<Hsv, byte>())
{
    // 2. Obtain the 3 channels (hue, saturation and value) that compose the HSV image
    Image<Gray, byte>[] 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();
    }
}


来源:https://stackoverflow.com/questions/24018650/color-tracking-using-emgucv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!