Trying to run findContours on a binary image"
Mat conv(image.size(), CV_8U);
image.convertTo(conv, CV_8U);
vector<vector<cv::Point> > contours;
findContours(conv, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
thorws error:
OpenCV Error: Unsupported format or combination of formats ([Start]FindContours support only 8uC1 images) in cvStartFindContours,
Any ideas? Thanks
From the documentation:
C++: void Mat::convertTo(OutputArray m, int rtype, double alpha=1, double beta=0 ) const
Parameters:rtype – desired output matrix type or, rather, the depth since the number of channels are the same as the input has; if rtype is negative, the output matrix will have the same type as the input.
You see that the number of channels is not changed by convertTo
, this means most probably that you get 3 channels (r, g and b). However findContours
requires a monochrome image.
You need to convert the image to black-and-white:
cv::Mat bwImage;
cv::cvtColor(image, bwImage, CV_RGB2GRAY);
vector< vector<cv::Point> > contours;
cv::findContours(bwImage, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With