Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

error:Only 8-bit 1-channel and 3-channel input/output images are

Hi, I am creating cv::Mat objects using UIImageToMats from the iOS code. I am getting the error " Only 8-bit 1-channel and 3-channel input/output images are supported in function cvInpaint" from the cvInpaint function invoked in the code snippet below.

How do I make sure that all "input/output" images are 8-bit 1-channel and 3-channel input/output images? thanks Tim

-(UIImage) inpaintLelea:(UIImage) image Mask:(UIImage*) imageMask { cv::Mat src; UIImageToMat(image, src );

cv::Mat mask;
cv::cvtColor(src, mask, CV_BGR2GRAY);
cv::threshold(mask, mask, 220, 255, CV_THRESH_BINARY);


std::vector<std::vector<cv::Point> > contours;
cv::findContours(mask.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);

for (int i = 0; i < contours.size(); i++)
{
    cv::Rect r = cv::boundingRect(contours[i]);

    if (std::abs(1 - (src.cols/r.width)) > 0.2)
        cv::drawContours(mask, contours, i, CV_RGB(0,0,0), CV_FILLED);
}

cv::Mat dst;

cv::inpaint(src, mask, dst, 1, cv::INPAINT_TELEA);

return  MatToUIImage(dst);

}