Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

HI, there is the other code which is used findContours. I don't know which one is more effictive.

Mat CV_EXPORTS FillHoles( Mat _src)
{
    CV_Assert(_src.type()==CV_8UC1);
    Mat dst;
    vector<vector<cv::Point>> contours;
    vector<Vec4i> hierarchy;

    findContours(_src,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE,cv::Point(0,0));
    CvScalar color=cvScalar(255);
    dst=Mat::zeros(_src.size(),CV_8UC1);

    for(int i=0;i<contours.size();i++)
    {
        drawContours(dst,contours,i,color,-1,8,hierarchy,0,cv::Point());
    }
    return dst;
}