I am trying to detect colored spheres with openCV using an Iphone. For the first test case I was using one single yellow marble with the given code:
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);
This gave me already good results:
However I will need to detect the circle shape somehow. Ideally I want to apply HoughCircle on however I get the OpenCv error: "Bad argument(the source image must be 8-bit, single-channel).
I also tried to apply
HoughCircles(thresholdHSV, detectedCircles, CV_HOUGH_GRADIENT, 1, thresholdHSV.rows / 8, 200, 100, 0, 0);
but I don't get any result at all.
How can apply HoughCircle on the destinationSource image or is there any other way to detect circular shapes? (I have also to consider when there are more spheres of the same color very close to each other since findContours will find just one countour then)
any help is highly appreciated and thank you for your time.