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

asked 2014-10-28 20:38:02 -0600

tim obrien gravatar image

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);

}

edit retag flag offensive close merge delete

Comments

1

Did you try to simply print out the type of the src Mat?

The type you can find here: https://github.com/Itseez/opencv/blob/master/modules/core/include/opencv2/core/cvdef.h (line 258). So 0 means 8 bit 1 channel. To get the higher channel equivalents, you just use this formula: type_number + (channels - 1) * 8.

So, for example 8 bit 3 channel would be simply 16.

Moster gravatar imageMoster ( 2014-10-29 01:07:29 -0600 )edit

@Moster I did not understand the method you have talked about. Could you elaborate a bit more?

ankur17 gravatar imageankur17 ( 2019-06-01 07:11:12 -0600 )edit