Ask Your Question

crop image

asked 2012-07-31 14:18:13 -0600

andrea gravatar image

updated 2012-07-31 14:18:29 -0600


someone know how to use crop for the image?

for example i have one image i want to show a part of this image...

i read that there are the cvRect and cvSetImageROI.....

thanks a lot :)

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2012-07-31 14:30:18 -0600

Michael Burdinov gravatar image
Mat cropedImage = fullImage(Rect(roiX,roiY,roiWidth,roiHeight));

Also note that this operation doesn't really perform cropping or coping memory. croppedImage uses same memory buffer as fullImage, so any changes of one of them may affect another.

edit flag offensive delete link more


thanks :)

andrea gravatar imageandrea ( 2012-07-31 14:40:04 -0600 )edit

sorry have another question... but if i want to crop a region that is not a rect? for example i have 4 point (the vertices) and i want the region delimited by this vertices (almost of the time is a rectangle but not always)

andrea gravatar imageandrea ( 2012-07-31 14:44:35 -0600 )edit

You should crop the bounding rectangle in the same way as Michael suggested. But then you can call cv:fillPoly ( to create a mask for your region. You can keep the mask in a separate matrix, or add to the submatrix as an alpha channel (4th channel in the CV_8UC4 matrix).

Kirill Kornyakov gravatar imageKirill Kornyakov ( 2012-08-03 16:22:32 -0600 )edit

answered 2012-07-31 14:54:20 -0600

Before the question pops up, because it is closely related. Here is how to extract the data in a RotatedRect:

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2012-07-31 14:18:13 -0600

Seen: 21,106 times

Last updated: Jul 31 '12