Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find contour of the set of points in OpenCV

I try to find objects on image by MSER-detection from OpenCV. But function cvExtractMSER return not contours, but set of points (CvSeq), that create figure:

(1, 4), (2, 3), (2, 4), (3, 2), (3, 3), (3, 4), (4, 1), (4, 2), (4, 3), (4, 4), ...

Area created by set of points

But I needs only points of contour:

(1, 4), (8, 4), (8, 1), (4, 1)

Highlight needed contour points

How I can find this contour?

I think, that simplest (but not fastest) way is:

  • draw b/w image with all points (how? point-by-point?)
  • use findContours for find contours on new image
like image 443
Alexander Kholodovitch Avatar asked Nov 04 '22 01:11

Alexander Kholodovitch


1 Answers

One of the options in findContours() is to pass a parameter that will remove all points except end points on a straight horizontal, vertical, or diagonal line. If you create an image and draw the points you've listed, then findContours() can do the rest of the work for you.

CV_CHAIN_APPROX_SIMPLE compresses horizontal, vertical, and diagonal segments and leaves only their end points. For example, an up-right rectangular contour is encoded with 4 points.

http://opencv.itseez.com/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=findcontours#findcontours

like image 144
Rethunk Avatar answered Nov 09 '22 08:11

Rethunk