各种门槛 [英] Various thresholds
问题描述
我试图通过一个网络摄像头同时跟踪不同颜色的多个对象。现在我可以用单一阈值的单色做到这一点:
I am trying to track multiple objects with different color at the same time via a single web cam. Now I can do that for single color with single threshold:
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;
}
我正在寻找一些提示来做各种门槛。如果它可能,它需要多少个窗口?我是否需要为不同的颜色指定不同的窗口?
I'm looking for some hints to do various threshold. Also if its possible, how many windows does it require? Do i need to assign different windows for different colors?
推荐答案
最简单的方法是为每种颜色创建一个阈值图像你想跟踪。您可以修改函数以将其作为参数,而不是对阈值范围进行硬编码。这允许您为不同的对象重用该函数。
The easiest way to do this is create a thresholded image for each color you wish to track. Instead of hard-coding your threshold ranges, you could modify your function to take them as parameters. This lets you re-use the function for different objects.
修改后的函数可能如下所示:
The modified function might look like this:
IplImage* GetThresholdedImage(IplImage* imgHSV, CvScalar lower, CvScalar upper)
{
IplImage* imgThresh=cvCreateImage(cvGetSize(imgHSV),IPL_DEPTH_8U, 1);
cvInRangeS(imgHSV, lower, upper, imgThresh);
return imgThresh;
}
然后使用不同对象的不同阈值调用它:
And then call it using different thresholds for different objects:
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);
这篇关于各种门槛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!