Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python OpenCv, only read part of image

Tags:

python

opencv

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?

like image 597
Jesse Aldridge Avatar asked Apr 15 '26 08:04

Jesse Aldridge


1 Answers

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.

like image 94
Jesse Aldridge Avatar answered Apr 16 '26 22:04

Jesse Aldridge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!