I am trying to apply the Canny operator in a certain location of an image with the following code:
//region of interest from my RGB image
Mat devilROI = img(
Easy. You do not have the same number of channels in the 2 images to merge.
cvtColor(devilROI, canny, CV_RGB2GRAY);
Is taking your 3 channel image and turning it into a 1 channel greyscale image. You need the same number of channels to use addWeighted
Ok, I think I got it.
I tried using the Mat::copyTo, then I got the:
(scn ==1 && (dcn == 3 || dcn == 4))
error.
Then I found this Stackoveflow topic, which gave me the idea of converting back to RGB, then I tried the following and it worked:
Mat devilROI = img(Rect(r->x+lowerRect.x,
r->y + lowerRect.y,
lowerRect.width,
lowerRect.height));
Mat canny;
cvtColor(devilROI, canny, CV_BGR2GRAY);
Canny(canny, canny, low_threshold, high_threshold);
cvtColor(canny, canny, CV_GRAY2BGR);
addWeighted(devilROI, 1.0, canny, 0.3, 0., devilROI);
So, if anyone has any other suggestion, I would be grateful.
Thank you!