Reputation: 8149
I have thousands of large .png images (screenshots). I'm using opencv to do image recognition on a small portion of each image. I'm currently doing:
image = cv2.imread(path)
x,y,w,h = bounds
image = image[y:y + h, x:x + w]
The profiler tells me cv2.imread
is a bottleneck. I'm wondering if I can make the script faster by only reading the part of each image I'm interested in rather than loading the entire image and then cropping to the bounds. I can't find an OpenCV flag for that though. Am I missing one?
Upvotes: 3
Views: 10613
Reputation: 8149
AFAICT, there's no way to do this with OpenCV. But I did find a solution here: Load just part of an image in python
Simply using PIL to save the cropped region of interest when generating the screenshots works.
Upvotes: 1