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

asked 2015-08-01 06:54:59 -0600

Nbb gravatar image

updated 2015-10-10 02:28:48 -0600

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 = imread("lost3.png", CV_LOAD_IMAGE_GRAYSCALE);
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 flag offensive close merge delete

Comments

1

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

sturkmen gravatar imagesturkmen ( 2015-08-01 10:14:41 -0600 )edit
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.

matman gravatar imagematman ( 2015-08-01 12:53:27 -0600 )edit

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.

Eduardo gravatar imageEduardo ( 2015-08-03 04:40:37 -0600 )edit