Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Mat reshape not reducing channel number

Hi everyone, I get the error: error: (-215) mask.depth() == CV_8U && (mcn == 1 || mcn == cn) in function copyTo, when the following code runs. Why does reshape() not reduce the number of channels in mask to 1? I need a binary mask to find an object in the scene, however drawcontours() is giving me a grayscale 3 channel image, and my input image is 4 channels hence the error, but I thought reshape would fix this by reducing it to 1 channel. The printout states Mask has 3 channels still. Thanks for your help.

 Mat mask;
  if (contoursOn)
    mask = contours(image, backprojOut);
  mask.reshape(1);
  printf("mask channels: %d", mask.channels());
  image.copyTo(outImg, mask);
  image = outImg;
  return;

Mat reshape not reducing channel number

Hi everyone, I get the error: error: (-215) mask.depth() == CV_8U && (mcn == 1 || mcn == cn) in function copyTo, when the following code runs. Why does reshape() not reduce the number of channels in mask to 1? I need a binary mask to find an object in the scene, however drawcontours() is giving me a grayscale 3 channel image, and my input image is 4 channels hence the error, but I thought reshape would fix this by reducing it to 1 channel. The printout of mcn states Mask has 3 channels still. Thanks for your help. channels.

 Mat mask;
  if (contoursOn)
    mask = contours(image, backprojOut);
  mask.reshape(1);
  printf("mask channels: %d", mask.channels());
  image.copyTo(outImg, mask);
  image = outImg;
  return;