I'm working on detecting balls on images with Objective-C++ and OpenCV. I tried to use HoughCircle transformation, but I am not detecting the balls properly. For me it seems like the parameters do not fit to the description of the function. Is it different in Objective-C++ than in C++?
This is my code and the description of the OpenCV function:
cv::medianBlur(grayMat, grayMat, 17);
std::vector<cv::Vec3f> circles;
cv::HoughCircles(grayMat, circles, CV_HOUGH_GRADIENT,
1, //dp resolution
1, //minDist
140.0, //higher threshold
120.0, //lower threshold
15, //min radius
50); //max radius
If the parameters are correct as I implemented them, the idea was to use seed growing to get better results. I have no idea how to implement this in Objective-C++ and OpenCV. I already saw some examples in C++ but I do not know how to "translate" that into Objective-C++.
Could you please have a look at my HoughCircle parameters or give me an Objective-C++ example for seed growing?
Thanks a lot!
Edit: Here are two example images - I need universal parameters to detect the balls on both pictures:
You can use the C++ API of OpenCV on Objective C++ projects, with no change.
I tried your code and edited the parameters a little bit. The following parameters will detect all the circles:
cvtColor(img, gray, COLOR_BGR2GRAY);
medianBlur(gray, gray, 13);
vector<Vec3f> circles;
HoughCircles(gray, circles, HOUGH_GRADIENT, 1,
gray.rows/16,
100, 30, 15, 250
);
You will note three things after trying this code:
When doing a project like this, it is good to resize the images to a fixed size before starting to analyze them. The parameter values will be different for different image resolutions, unless you find a way to normalize them.