Ask Your Question

Revision history [back]

First don't use memset :

    cv::Mat binTest = cv::Mat(1000, 2000, CV_8UC1,Scalar(255));
    //find out connected component
    cv::Mat _dstImg, __stat, _centroid;
    int cc = cv::connectedComponentsWithStats(binTest, _dstImg, __stat, _centroid, 8, CV_32S,            cv::ConnectedComponentsAlgorithmsTypes::CCL_GRANA);

Now results is for __stat :

stat
[2147483647, 2147483647, 2, 2, 0;
 0, 0, 2000, 1000, 2000000]
centroid 
[-nan(ind), -nan(ind);
 999.5, 499.5]

last column of stat is surface then surface for connected components is 0. Results are good , weird but good!

First don't use memset :

    cv::Mat binTest = cv::Mat(1000, 2000, CV_8UC1,Scalar(255));
    //find out connected component
    cv::Mat _dstImg, __stat, _centroid;
    int cc = cv::connectedComponentsWithStats(binTest, _dstImg, __stat, _centroid, 8, CV_32S,            cv::ConnectedComponentsAlgorithmsTypes::CCL_GRANA);

Now results is for __stat :

stat
[2147483647, 2147483647, 2, 2, 0;
 0, 0, 2000, 1000, 2000000]
centroid 
[-nan(ind), -nan(ind);
 999.5, 499.5]

last column of stat is surface then surface for connected components with 0 label is 0. Results are good , weird but good!good 2 components but one empty!

Now with cv::Mat binTest = cv::Mat(1000, 2000, CV_8UC1,Scalar(0));

results :

 stat
[0, 0, 2000, 1000, 2000000]
centroid
 [999.5, 499.5]

May be you can post an issue