Monday, August 11, 2008

How to crop images with opencv in python

I just spent way too long figuring this out, so I figured I'd contribute to the google knowledge:

cropped = cvCreateImage( cvSize(new_width, new_height), 8, 3)
src_region = cvGetSubRect(image, opencv.cvRect(left, top, new_width, new_height) )
cvCopy(src_region, cropped)


You'd think this would be easy and/or documented, but nope!

6 comments:

Anonymous said...

thanks - safed me a lot of hassle

greets from sevilla

daniel

Anonymous said...

yep, me too

Anonymous said...

Thx alot

arsalanK2 said...

Another way is:

cvSetImageROI(src_region, cvRect(left, top, new_width, new_height));

cvCopy(src_region, cropped)

cvResetImageROI(src_region);

Anonymous said...

thanks you have saved me from a lot of trouble

tspp said...

Thank man ! that's what we need !