Ask Your Question
1

How to remove small line segments from contour?

asked 2014-10-10 09:18:52 -0600

HasanGhaforian gravatar image

updated 2015-10-19 15:16:44 -0600

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:

image description

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 flag offensive close merge delete

Comments

@HasanGhaforian. Can you post original image?

supra56 gravatar imagesupra56 ( 2020-01-20 07:06:44 -0600 )edit

3 answers

Sort by ยป oldest newest most voted
2

answered 2014-10-11 03:48:16 -0600

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.

edit flag offensive delete link more

Comments

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

wuling gravatar imagewuling ( 2014-10-12 10:43:00 -0600 )edit
0

answered 2014-10-11 12:59:41 -0600

gfx gravatar image

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.

edit flag offensive delete link more
0

answered 2014-10-10 12:40:43 -0600

aliavci gravatar image

updated 2014-10-19 02:56:39 -0600

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

edit flag offensive delete link more

Comments

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

HasanGhaforian gravatar imageHasanGhaforian ( 2014-10-10 14:11:34 -0600 )edit

Question Tools

Stats

Asked: 2014-10-10 09:18:52 -0600

Seen: 5,567 times

Last updated: Oct 19 '14