ApproxPolygon - Close contour
I need close the contour, but i don't understand how to use the approxpolydp function.
This image below is my open contour.
add a comment
I need close the contour, but i don't understand how to use the approxpolydp function.
This image below is my open contour.
you can't do what you want by approxPolyDP
.
try the code below:
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
using namespace std;
int main( int, char** argv )
{
Mat src, srcGray;
src = imread( argv[1] );
cvtColor(src, srcGray, COLOR_BGR2GRAY);
srcGray = srcGray > 127;
vector<Point> contours;
findNonZero( srcGray, contours );
polylines( src, contours, false, Scalar(255,255,255) );
imshow("Result", src);
waitKey();
return 0;
}
Result :
Hello guy,
Thanks by the help.
Your code helped me a lot.
@diegomoreira keep in mind it works only if contour shape is like ∩ or U. it fails for example C shape.
Asked: 2015-11-29 11:43:28 -0600
Seen: 1,459 times
Last updated: Nov 29 '15