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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.