I am working on detecting circles on an image and I am using the houghcircle function but the function generates so interesting numbers. I use VS-2013 for c++ ide and use 3.0 version opencv. Why why ???? Here is my code ;
#include "stdafx.h"
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
cv::Mat src = cv::imread("JGRiM.jpg");
if (!src.data) {
std::cout << "ERROR:\topening image" << std::endl;
return -1;
}
cv::namedWindow("image", CV_WINDOW_AUTOSIZE);
cv::imshow("image", src);
Mat src_gray2;
cvtColor(src, src_gray2, CV_BGR2GRAY);
GaussianBlur(src_gray2, src_gray2, cv::Size(3, 3), 2, 2);
std::vector<Vec3f> circles;
cout << circles.size() << std::endl;
HoughCircles(src_gray2, circles, CV_HOUGH_GRADIENT, 1, 20, 200, 100, 0, 0);
for (size_t i = 0; i < 20; i++)
{
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
// circle center
//circle(src, center, 3, Scalar(0, 255, 0), -1, 8, 0);
// circle outline
//circle(src, center, radius, Scalar(0, 0, 255), 3, 8, 0);
cout << i << "---> " << center << endl;
}
cv::namedWindow("image", CV_WINDOW_AUTOSIZE);
cv::imshow("image", src_gray2);
cv::waitKey(0);
return 0;
}
And here is the output ;