问题
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), ...
But I needs only points of contour:
(1, 4), (8, 4), (8, 1), (4, 1)
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
回答1:
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
回答2:
If I understood it correctly, you are looking for the corners of the detected object.
You can iterate through your list of countours and write a simple logic to detect the 4 corners by doing simple coordinates comparisons.
来源:https://stackoverflow.com/questions/10297713/find-contour-of-the-set-of-points-in-opencv