Region of Interest opencv python

Ajay Nair picture Ajay Nair · Mar 15, 2013 · Viewed 77.8k times · Source

I am trying to get a region of an image (ROI) using opencv python. The version of opencv used is 2.4.3. However when I try to call the API

cv2.SetImageROI

it returns this error

AttributeError: 'module' object has no attribute 'SetImageROI'

Also on checking the documentation it seems to suggest this api is a legacy python function. http://docs.opencv.org/2.4.3/search.html?q=setimageroi

I am not sure how to go about getting the ROI using this current version of opencv in python. Could some one please suggest how to go about this?

Thanks

Answer

Ajay Nair picture Ajay Nair · Mar 15, 2013

Okay, On further analysis realized that the cv2 since it has been supporting numpy array structure, there is no longer any need for a API, the entire image can be manipulated in the array itself. eg:

img = cv2.imread('image.png')
img = img[c1:c1+25,r1:r1+25]

Here c1 is the left side column pixel location, and r1 is the corresponding row location. And img now has the image specified within the pixels as the ROI.

EDIT: Very nicely explained here, How to copy a image region using opencv in python?