3

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?

Jesse Aldridge
  • 7,991
  • 9
  • 48
  • 75

1 Answers1

1

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.

Community
  • 1
  • 1
Jesse Aldridge
  • 7,991
  • 9
  • 48
  • 75