Crop Image Patch & Paste [closed]
So I am trying to extract a 16x16 patch from the centre of an image and paste it into some random location in the same image and display it. Here is the code I wrote for the same:
void patchPase(Mat& img, Mat& result) {
Point pt1;
pt1.x = rng.uniform( x_1, x_2 );
pt1.y = rng.uniform( y_1, y_2 );
Mat smallImage;
smallImage = img(Rect((img.size().width/2),(img.size().height/2), 16, 16));
Rect roi(Point(pt1.x, pt1.y), smallImage.size());
smallImage.copyTo(img(roi));
result = img;
}
However this fails to run with the following error:
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /build/opencv-92Ozt2/opencv-2.4.9.1+dfsg/modules/highgui/src/window.cpp, line 269
terminate called after throwing an instance of 'cv::Exception'
what(): /build/opencv-92Ozt2/opencv-2.4.9.1+dfsg/modules/highgui/src/window.cpp:269: error: (-215) size.width>0 && size.height>0 in function imshow
Where have I mistaken? Thanks.
in opencv 3.1 there is no bug (if img is not empty, check it). After calling function patchPase result and img are identical.
OpenCV 2.4.9.1 is ancient and full of bugs compared to recent editions. Please avoid using it!