Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.

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.

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.mask. Also trying the following doesn't work:

  threshold(backprojOut, mask, 128, 255, THRESH_BINARY);
  mask.convertTo(mask, CV_8U);
  image.copyTo(imgMasked, mask);

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?