I am new to OpenCV and following along with a book. I am trying to extract a binary image indicating component regions with the following:
cv::Mat result;
result = image.clone();
cv::watershed(image, result);
When executed, this produces the following error:
segmentation.cpp:159: error: (-215) src.type() == CV_8UC3 && dst.type() == CV_32SC1
in function watershed
The error is certainly correct, as I verified with the type2str
function in this SO post: How to find out what type of a Mat object is with Mat::type() in OpenCV
I also tried using image.copyTo(result)
instead of clone()
, but this produces the same error message. What am I doing wrong, and how can I copy a Mat
to get the same type?
I am guessing the hacky solution would be to convert the color of result to match the color of image, as is done here: OpenCV: How to convert CV_8UC1 mat to CV_8UC3 but this seems wrong no?