我正在尝试使用iPhone上的openCV来检测彩色球体。对于第一个测试用例,我使用了一个单一的黄色大理石和给定的代码:
cv::Mat thresholdHSV;
cv::Mat imgHSV;
cv::cvtColor(inputFrame, imgHSV, CV_BGR2HSV);
cv::inRange(imgHSV,cv::Scalar(20,100,100),cv::Scalar(30,255,255),thresholdHSV);
std::vector<std::vector<cv::Point> > contours;
findContours(thresholdHSV.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
//Draw them
cv::Mat destinationSource = cv::Mat::zeros(inputFrame.size(), inputFrame.type());
drawContours(destinationSource, contours, -1, cv::Scalar(255,255,255), CV_FILLED);
这已经给了我很好的结果:
![enter image description here](https://istack.dev59.com/hH1Jy.webp)
但是,我需要以某种方式检测圆形。理想情况下,我希望在上应用 HoughCircle 但我得到了 OpenCv 错误:"Bad argument(the source image must be 8-bit, single-channel)。
我也尝试应用
HoughCircles(thresholdHSV, detectedCircles, CV_HOUGH_GRADIENT, 1, thresholdHSV.rows / 8, 200, 100, 0, 0);
但我根本没有得到任何结果。
如何在destinationSource图像上应用HoughCircle,或者是否有其他方法可以检测圆形?(当有更多颜色相同的球体非常接近彼此时,因为findContours只会找到一个轮廓,所以我还要考虑这一点)
非常感谢任何帮助,并感谢您的时间。