Your cropped grayscale image croppedImage
is a 1 channel image but you are trying to overlay it onto 3 channel RGB image frame
. In other words, the function copyTo
in
croppedImage.copyTo(frame(Rect(pt1, croppedImage.size())));
expects croppedImage
to have the same number of channels as frame
. This is why you are getting the error.
EDIT To solve your issue you may try convert your grayscale cropped image back to RGB format (it will still look like the grayscale image). Something like
cvtColor(croppedImage, croppedImage, CV_BGR2GRAY ); // to grayscale
cvtColor(croppedImage, croppedImage, CV_GRAY2BGR ); // to RGB
croppedImage.copyTo(frame(Rect(pt1, croppedImage.size())));