1

I'm trying to fit lines from an binary image below. My main objective is to detect a stair model. Is there any way to do this in OpenCV ? enter image description here Thank for your help.

akash
  • 2,117
  • 4
  • 21
  • 32
  • Add also the original image, the code you tried, actual results and expexted results. You said HT didn't work, can you show why to us? – Miki Oct 12 '15 at 11:45

4 Answers4

1

The simplest methods I can think of are either the Hough Transform (HoughLines() for lines and HoughLinesP() for segments) or RANSAC (I couldn't find a RANSAC line detector in OpenCV. However there are interesting implementations in the MRPT and PCL).

EDIT: A method based on Canny() and HoughLines() is explained in extract lines from canny edge detection

maddouri
  • 3,737
  • 5
  • 29
  • 51
1

Thank Miki, 865719 , Photon, and Humam Helfawi,

After using Hough-Transform, I see that the result is not good. You can see in Figure below: hough transform result

Here is my code:

int main(int argc, char** argv){
Mat src, dst, color_dst;
src=imread("stairs.png");

Canny( src, dst, 50, 200, 3 );
cvtColor( dst, color_dst, CV_GRAY2BGR );


vector<Vec4i> lines;
HoughLinesP( dst, lines, 1, CV_PI/180, 80, 30, 10 );
for( size_t i = 0; i < lines.size(); i++ )
{
    line( color_dst, Point(lines[i][0], lines[i][1]),
        Point(lines[i][2], lines[i][3]), Scalar(0,0,255), 3, 8 );
}


namedWindow( "Source", 1 );
imshow( "Source", src );

namedWindow( "Detected Lines", 1 );
imshow( "Detected Lines", color_dst );

waitKey(0);
return 0;}

Thank for your support.

Hieu.

lightalchemist
  • 10,031
  • 4
  • 47
  • 55
0

You can detect the lines in the image by using the hough transform.

http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html

(The question is not detailed enough for more.)

Photon
  • 3,182
  • 1
  • 15
  • 16
0

Get the contours of your images and apply the hough-transform on the contours. you will got some duplicate line (very near to each other).. just filter them on some distance criteria

Humam Helfawi
  • 19,566
  • 15
  • 85
  • 160