Ask Your Question
4

crop image

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

andrea gravatar image

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

hi!

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
5

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

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

Comments

thanks :)

andrea gravatar imageandrea ( 2012-07-31 14:40:04 -0500 )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 -0500 )edit

You should crop the bounding rectangle in the same way as Michael suggested. But then you can call cv:fillPoly (http://docs.opencv.org/modules/core/doc/drawing_functions.html?highlight=poly#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 -0500 )edit
1

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

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
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 19,499 times

Last updated: Jul 31 '12