Reputation: 85
The related code is here(C++, opencv):
Rect rec = boundingRect(...);
image_grey.copyTo(gesture_grey, mask);
imshow("image_grey", gesture_grey(rec));
resize(gesture_grey(rec), gesture_grey, Size(256, 256));
imshow("gesture_grey", gesture_grey);
Why are the two images so different before and after resizing? How to fix it?
Upvotes: 1
Views: 69
Reputation: 1990
The problem is in copyTo
method. It doesn't clear the content of 'gesture_grey' image container.
When you use gesture_grey(rec)
you are effectively executing copy constructor, which gives you a new image container, so it's all cool. But when you call copyTo
you are copying over to an existing target 'gesture_grey'.
To fix it, you need to re-initialize 'gesture_grey' in order to clear it, before calling copyTo
. Otherwise, what you see is a combination of the previous content of 'gesture_grey' + new content you copy from image_grey
.
Upvotes: 1