findContours Problems with CV_RETR_CCOMP & CV_RETR_FLOODFILL

asked 2013-07-08 07:31:27 -0500

updated 2013-07-08 07:35:12 -0500

The contours are wrong:

problem1:

Mat arr(10,10,CV_8UC1,Scalar(0));
rectangle(arr,Point(2,0),Point(6,0),Scalar::all(1),-1);
cout << arr << endl;
vector<vector<Point>> contors;
findContours(arr,contors,CV_RETR_CCOMP,CV_CHAIN_APPROX_NONE);

for (size_t i=0;i < contors.size();i++)
cout << boundingRect(contors[i]) << endl;

Result1: image description

Problem2:

Mat arr(10,10,CV_32SC1,Scalar(0));
rectangle(arr,Point(2,1),Point(6,1),Scalar::all(1),-1);
cout << arr << endl;
vector<vector<Point>> contors;
findContours(arr,contors,CV_RETR_CCOMP,CV_CHAIN_APPROX_NONE);

for (size_t i=0;i < contors.size();i++)
    cout << boundingRect(contors[i]) << endl;

Result2: image description

edit retag flag offensive close merge delete