Mask Dimensions from thresholding don't match?
Hi everyone, I have the following code producing this error:
Mat imgMasked, mask;
threshold(backprojOut, mask, 128, 255, THRESH_BINARY);
image.copyTo(imgMasked, mask);
OpenCV Error: Assertion failed (mask.depth() == CV_8U && (mcn == 1 || mcn == cn)) in copyTo
Can anyone provide me with some advice as to what is causing this? I've tried:
mask = Mat::zeros(image.rows, image.cols, CV_8U);
but that wasn't it.
Thanks.
EDIT: To clarify I'm trying to take my output from back projection on a HSV image (which is grayscale) and turn it into a binary Mat so I can apply it as a mask. Also trying the following doesn't work:
threshold(backprojOut, mask, 128, 255, THRESH_BINARY);
mask.convertTo(mask, CV_8U);
image.copyTo(imgMasked, mask);
EDIT 2: Mask has 3 channels and my image has 4, hence the error. Threshold is giving me a Mat I can't use. How can I get a single channel out of threshold?
may be backprojout type is CV_32F then mask type will be CV_32F
What is the best approach to this? Should I be extracting channels from the mask or somehow ensuring it is a single channel? I'm not sure how to specify how many channels are in a Mat. The calcBackproject() method must take a HSV and hence backprojOut will have to be HSV too as it outputs the same data type.
I don't understand : backProject Destination back projection array that is a single-channel array of the same size and depth as images .
Fair point, must have got mixed up. So back project in is the image frame, but converted to HSV, therefore single channel output with same rows and cols as image frame. Therefore because I've converted to HSV I've lost the 4th channel from the original image (presumably alpha?). So how do I get down to a single channel?
use split method