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(Rect(r->x+lowerRect.x,
r->y + lowerRect.y,
lowerRect.width,
lowerRect.height));
Mat canny;
//to grayscale so I can apply canny
cvtColor(devilROI, canny, CV_RGB2GRAY);
//makes my region of interest with Canny
Canny(canny, canny, low_threshold, high_threshold);
//back to the original image
addWeighted(devilROI, 1.0, canny, 0.3, 0., devilROI);
And it is giving me the following error when the addWeighted is executed:
OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array') in arithm_op, file C:\OpenCV2.3\ opencv\modules\core\src\arithm.cpp, line 1227 terminate called after throwing an instance of 'cv::Exception' what(): C:\OpenCV2.3\opencv\modules\core\src\arithm.cpp:1227: error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function arithm_op
Do you have any suggestion of what the problem might be? I've been stuck on this for a long time...
Thank you.
Ok, I think I got it.
I tried using the Mat::copyTo, then I got the:
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:
So, if anyone has any other suggestion, I would be grateful.
Thank you!
Easy. You do not have the same number of channels in the 2 images to merge.
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