# draw circle function (x,y) coordinate help (Hough circle)

Hello forum,

I wrote a simple code for the standard hough circular transform. However, I am unsure why the center of the circle is shifted. Can anyone help me on this ?

#include <opencv2\opencv.hpp>
#include <opencv\cv.h>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
Mat image, canny_output;

image.copyTo(canny_output);

Canny(canny_output, canny_output, 100, 200, 3);

Mat temp        = Mat::zeros(image.size(), CV_8UC1);
Mat hough_space = Mat::zeros(image.size(), CV_8UC1);

// Standard Hough Circle Transform ( Radius = 9 )
for (int i = 0; i < canny_output.rows; i++)
for (int j = 0; j < canny_output.cols; j++)

if (canny_output.at<uchar>(i, j) != 0) {      // Edge point

circle(temp, Point(i, j), 9, 20, 1, 0);   // Draw circle of radius 9 at edge point
//circle(temp, Point(j, i), 9, 20, 1, 0); // Using this line instead gives me the correct drawn circle
hough_space = hough_space + temp;
image = image + temp;
temp = Mat::zeros(image.size(), CV_8UC1); // Clear temp

}

namedWindow("canny op", CV_WINDOW_NORMAL);
imshow("canny op", canny_output);

namedWindow("image", CV_WINDOW_NORMAL);
imshow("image", image);

namedWindow("hough space", CV_WINDOW_NORMAL);
imshow("hough space", hough_space);

waitKey(0);
}

edit retag close merge delete

1

i did not understand exactly what you want to do. but maybe this helps

2

Like in your other thread here: In your example code there is no cv:HoughCircles(), so no one can comprehend your problem. Take a look at the example I have linked in the other thread how to use cv::HoughCircles().

For further help post some code that is related to cv::HoughCircles().

And by the way post some code which can be compiled without adding the declarations of the variables.

And don't double post the same question.

It is normal. The variable i iterates over the rows, the variable j over the columns but the first argument of the Point constructor is x, the second is y.

Just swap it and it should be fine.