Horizontal Line detection with OpenCV

前端 未结 5 624
一整个雨季
一整个雨季 2020-11-27 12:33

I am trying to find horizontal and vertical lines from an image which came from a \"document\". The documents are scanned pages from contracts and so the lines look like wha

5条回答
  •  醉酒成梦
    2020-11-27 12:50

    You might consider leaving the Hough line detection since this method looks for "global" lines, not necessarily line segments. I recently implemented an application that identified "parallelograms" - essentially squares that might be rotated and perspective fore-shortened due to viewing angle. You might consider something similar. My pipeline was:

    1. Convert from RGB to grayscale (cvCvtColor)
    2. Smooth (cvSmooth)
    3. Threshold (cvThreshold)
    4. Detect edges (cvCanny)
    5. Find contours (cvFindContours)
    6. Approximate contours with linear features (cvApproxPoly)

    In your application, the resulting contour list will likely be large (depending upon the "aggressiveness" of smoothing and the feature enhancement of the Canny edge detector. You can prune this list by a variety of parameters: number of points returned from the contour finder, area of the contour (cvContourArea), etc. From my experience, I would expect that "valid" lines in your application would have well-defined area and vertex count properties. Additionally, you can filter out contours based on distance between end-points, angle defined by the line connecting end-points, etc.

    Depending upon how much CPU "time" you have, you can always pair the Hough algorithm with an algorithm like that above to robustly identify horizontal and vertical lines.

提交回复
热议问题