Ask Your Question

Revision history [back]

findContours Problems with CV_RETR_CCOMP & CV_RETR_FLOODFILL

The contours are wrong:

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;

image description

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;

image description

findContours Problems with CV_RETR_CCOMP & CV_RETR_FLOODFILL

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>> vector<vector<point>> contors; findContours(arr,contors,CV_RETR_CCOMP,CV_CHAIN_APPROX_NONE); 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

findContours Problems with CV_RETR_CCOMP & CV_RETR_FLOODFILL

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>> vector<vector<Point>> contors;
    findContours(arr,contors,CV_RETR_CCOMP,CV_CHAIN_APPROX_NONE);

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