Reputation: 12747
Is there a way to extract a rectangle of my choice from an image, maybe using numpy arrays? Most implementations available seem to be for regular sliding window solutions, but those always include steps, or rectangles of the same aspect ratio, or something like that.
Is it possible to provide the beginning x and y coordinates and the width and height (or ending x and y coordinates), and extract exactly that rectangle? Can this be done using numpy arrays alone? Or is there another way to do this?
Upvotes: 3
Views: 3072
Reputation: 1695
The best way to do this would be slicing i.e.
rect = np.copy(img[y1:y1+height,x1:x1+width])
where (x1, y1) is the upper left corner of your rectangle.
Upvotes: 3