Ask Your Question

Revision history [back]

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 :

image description