How to copy a image region using opencv in python?

Both cv.GetSubRect and ROI functions are available in Python, but in old import cv mode or import cv2.cv. ie use cv2.cv.GetSubRect() or cv2.cv.SetImageROI if you are familier with them.

On the other hand, it is simple to set ROI without these functions due to numpy integration in new cv2.

If (x1,y1) and (x2,y2) are the two opposite vertices of plate you obtained, then simply use function:

roi = gray[y1:y2, x1:x2]

that is your image ROI.

So choose whatever suit you.

Leave a Comment