Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

HOUGHCIRCLE generates strange numbers

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 ; image description

HOUGHCIRCLE generates strange numbers

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; circles.size(); i++)
{
    Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
    int radius = cvRound(circles[i][2]);
    // circle center
    //circle(src, circle(src, center, 3, Scalar(0, 255, 0), -1, 8, 0);
    // circle outline
    //circle(src, 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 Here is the output Results ; image descriptionimage description

HOUGHCIRCLE generates strange numbers

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 < circles.size(); 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);
}

cv::namedWindow("image", CV_WINDOW_AUTOSIZE);
cv::imshow("image", src_gray2);
cv::waitKey(0);
return 0;
}

Here is the input Image;

image description

Here is the Results ; image description

HOUGHCIRCLE generates strange numbers

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>
<iostream> 
#include <stdio.h>
#include <opencv2\opencv.hpp>
#include <opencv\cv.h>
#include <opencv2\core.hpp>
#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");
cv::imread("asd.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), cv::Size(9, 9), 2, 2);
 Canny(src_gray2, src_gray2, 25, 35, 3, true);
std::vector<Vec3f> circles;

circles; 
cout << circles.size() << std::endl;
 HoughCircles(src_gray2, circles, CV_HOUGH_GRADIENT, 1, 20, 200, 2, 100, 0, 0);
35, 30, 50, 70);

for (size_t i = 0; i < circles.size(); 20; i++)
{
    Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
    int radius = cvRound(circles[i][2]);
    // circle center
    circle(src, //circle(src, center, 3, Scalar(0, 255, 0), -1, 8, 0);
    // circle outline
    circle(src, //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;
}

Here is the input Image;resuls; image description

image description

Here is the Results ; image description