How can I clip an Image [closed]
I have images with a region of interest (=rectangle) and I want to clip the image to this region. Is there a simple way of doing this ? The calls I tried do the row-clipping just fine, but ignore the colums at least if I show the image on the screen ?
Mat image2=image(Rect(x0,y0,w,h))
Actually this is what I do, but as I said, if I do imshow("test", image2) then the rows above and below are clipped, but not the columns. So p.ex. the part between x=0 and x0 is still shown. My question is, if I need to build this myself or if there is a standard to do this...
This should really give you an image of size WxH starting from x0,y0.
Note that this operation only defines a ROI on the image (a reference to a sub-image), so if you change something, image will change too. To crop the image, you have to make a copy of image2.
To erase the contents of an image outside a ROI, create a mask (black background and white rectangle) and use image.copyTo(image2,mask)
Ok that was the trick by adding: image2.copyto(image2);
made it work, thx...
I only did a resize, and that seems not to do the same...