# How to remove small line segments from contour?

Is there a way to remove small line segments from a contour?

For example,in this image,largest contour is specified by green color and it's approximation is specified by blue color:

As contour is a set of Points,I guess we can do somethings to remove segments of contours that are in red circles.For example by detecting and removing small lines or small sub contours or another way.But I do not know how I can do it.Please remember I want to remove them after finding contour and not before that.Do you know how I can remove them?Or any idea?

edit retag close merge delete

Sort by » oldest newest most voted

The easiest approach to test would be a simple erode/dilate. Just draw your green contour as a (white) filled pylygon on a black background and call erode for some iterations. This will shrink your goal rectangle but also remove the additional lines. If you then call dilate for the same number of iterations, the rectangle will be (approximately) the same size as before, but without your additional lines.

more

at first , fill closed loop, then use erode/dilate

( 2014-10-12 10:43:00 -0500 )edit

on opencv4android not sure but I think there is myvector.push_back (myvectorpoint); function ..... I suggest to use minarearect function for find 4point ... if you need store it in a vector ..... than draw the line around your poligon image (4 line poligon)..... using function line(IMG, point[0], point[1], scalar(XXX), 3,8,1)....for every poligon side.

more

Make sure your parameters aren't giving you excess lines by calling OpenCV's convexHull function found here: http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/hull/hull.html

After this to find corners, there's a whole complex manual method of running all the lines through many while loops and calculating their slopes to detect whether they are horizontal or vertical. check your vertical lines separately for highest and lowest y values. Make sure you do this separately for vertical lines on specific x ranges to differentiate between right line and left line

more

@aliavci Can you add more details?In opencv4android,how I can achieve corners?

( 2014-10-10 14:11:34 -0500 )edit

Official site

GitHub

Wiki

Documentation