Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I checked your code; the first problem is that you already have an edge image. If you run a Canny filter, it will encircle your walls, giving you a lot of false edges.

So use just the thresholded image (just convert it to grayscale):

threshold(img_tmp,bin_img,30,255,cv::THRESH_BINARY_INV);
cvtColor(bin_img, bin_img, COLOR_BGR2GRAY);

Then, you should play with the parameters of the Hough transform. As the image is noisy (the lines aren't straight), increment the rho and theta resolutions. I got quite good results with the following parameters:

HoughLinesP(bin_img,tmp_lines, 2, CV_PI/36, 10, 10, 1);

Here is my result (37 lines detected):

Result

For better results, you must use more sophisticated algorithms (e.g. marked point processes with a linear model - but you won't find these in OpenCV).

I checked your code; the first problem is that you already have an edge image. If you run a Canny filter, it will encircle your walls, giving you a lot of false edges.edges. That's why you got generally two lines on both sides of your original line (you can see it on the magnified image).

So use just the thresholded image (just convert it to grayscale):

threshold(img_tmp,bin_img,30,255,cv::THRESH_BINARY_INV);
cvtColor(bin_img, bin_img, COLOR_BGR2GRAY);

Then, you should play with the parameters of the Hough transform. As the image is noisy (the lines aren't straight), increment the rho and theta resolutions. I got quite good results with the following parameters:

HoughLinesP(bin_img,tmp_lines, 2, CV_PI/36, 10, 10, 1);

Here is my result (37 lines detected):

Result

For better results, you must use more sophisticated algorithms (e.g. marked point processes with a linear model - but you won't find these in OpenCV).