Ask Your Question
1

Get quadrilateral from sparse segments

asked 2014-09-24 11:42:01 -0600

Federico gravatar image

updated 2015-08-24 20:06:41 -0600

I have a set of segments (each segment is in a std::vector of 2 cv::Point) and if I print them in a image they're arranged in this way:

image description

Most of them are in the two pseudo-parallel lines, other segments are noise. What I want to do is detect the two main lines and build the matching quadrilateral like this:

image description

What is the best approach to solve this problem?

Thanks!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2014-09-25 01:28:30 -0600

I guess that you want to find a rectangle that was deformed by a perspective transformation. Is this right? In this case I'd try to merge the short lines, find the four endpoints of the merged lines and use getPerspectiveTransformation to estimate the transformation. If you make a mistake during merging, the reprojection error of the transformation will be rather high so you can try to adjust your merging (maybe ignore some of the shorter lines or something similar) until you get a transformation with a good reprojection error. This approach is called RANSAC and could probably solve this problem.

edit flag offensive delete link more
3

answered 2014-09-24 15:20:59 -0600

aliavci gravatar image
  1. Blur it so that the close lines join together. 2.Then make a while loop to loop over every contour to leave the bigger contours only.
  2. Call the Canny function
  3. Call houghlines to draw the lines on the image to draw the lines
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-09-24 11:42:01 -0600

Seen: 774 times

Last updated: Sep 25 '14