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
Python OpenCV – selectroi() Function With this method, we can select a range of interest in an image manually by selecting the area on the image. Parameter: window_name: name of the window where selection process will be shown. source image: image to select a ROI.
In this article, we show how to create a region of interest in an image in Python using the OpenCV module. First, let's explain the concept of a region of interest. A region of interest is a place on an image where we want to search for something.
Our hierarchical region-of-interest detection algorithm uses five steps: (1) a priori information processing; (2) image downsampling; (3) region-of-candidates (ROCs) detection for each prototype group; (4) ROC arbitration; and (5) ROC area extension to form regions of interest (ROIs).
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With