1

我正在尝试通过单个网络摄像头同时跟踪具有不同颜色的多个对象。现在我可以用单一阈值对单一颜色做到这一点:

IplImage* GetThresholdedImage(IplImage* imgHSV)
{       
    IplImage* imgThresh=cvCreateImage(cvGetSize(imgHSV),IPL_DEPTH_8U, 1);
    cvInRangeS(imgHSV, cvScalar(170,160,60), cvScalar(180,2556,256), imgThresh); 
    return imgThresh;
}

我正在寻找一些提示来做各种阈值。如果可能的话,它需要多少个窗口?我需要为不同的颜色分配不同的窗口吗?

4

1 回答 1

0

最简单的方法是为您希望跟踪的每种颜色创建一个阈值图像。您可以修改函数以将它们作为参数,而不是对阈值范围进行硬编码。这使您可以将函数重新用于不同的对象。

修改后的函数可能如下所示:

IplImage* GetThresholdedImage(IplImage* imgHSV, CvScalar lower, CvScalar upper)
{       
    IplImage* imgThresh=cvCreateImage(cvGetSize(imgHSV),IPL_DEPTH_8U, 1);
    cvInRangeS(imgHSV, lower, upper, imgThresh); 
    return imgThresh;
}

然后对不同的对象使用不同的阈值来调用它:

IplImage* hsv;    /* Already initialized*/

/* Set thresholds for blue and green objects as an example. */
/*Obviously, set these to be whatever is necessary. */
CvScalar blue_lower = cvScalar(110,60,10);
CvScalar blue_upper = cvScalar(120,256,256);
CvScalar green_lower = cvScalar(40,60,10);
CvScalar green_upper = cvScalar(71,256,256);

/* Get the images thresholded for blue and green. */
IplImage* blue_mask = GetThresholdedImage(hsv, blue_lower, blue_upper);
IplImage* green_mask = GetThresholdedImage(hsv, green_lower, green_upper);
于 2013-07-04T22:13:41.823 回答