Question

I am trying to implement Hough Transform for line detection in an already pre-processed image. So my input image is a black-white edge image, 0 - background and 255 - foreground. I do not wish to use the inbuilt HoughLines library by OpenCV. I am actually stuck with creating the accumulator and increasing its values properly. I cant figure out where i went wrong, so here is my code block :

int diagonal = sqrt(height * height + width * width);

IplImage *acc = cvCreateImage (cvSize(180, 2 * diagonal),IPL_DEPTH_8U, 1);
unsigned char* accData = (unsigned char *)acc->imageData;

for (int i=0; i<height; i++)
{
    for (int j=0; j<step; j++)
    {
        if (data[i*step + j] > 200)
        {
            for (int theta=0; theta<180; theta++)
            {
                int p = j * cos(theta) + i * sin(theta);
                if (p > 0)
                    accData[theta*180 + p] += 1;
            }
        }
    }
}

The output image that i get in acc is not what it should look like. I am not getting any sinusoids, instead only white patches here and there. Can anyone provide any feedback about where i went wrong ?

Was it helpful?

Solution

What I see there is that you don t use sinus with radians values but with degree values you could change it as follows:

int p = j * cos((double)theta*PI/180) + i * sin((double)theta*PI/180);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top