[英]Python OpenCv, only read part of image
I have thousands of large .png images (screenshots). 我有数千个大型.png图片(屏幕截图)。 I'm using opencv to do image recognition on a small portion of each image.
我正在使用opencv对每个图像的一小部分进行图像识别。 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. 探查器告诉我
cv2.imread
是一个瓶颈。 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.
我虽然找不到OpenCV标志。 Am I missing one?
我想念一个吗?
AFAICT, there's no way to do this with OpenCV. AFAICT,OpenCV无法做到这一点。 But I did find a solution here: Load just part of an image in python
但是我确实找到了一个解决方案: 在python中仅加载一部分图像
Simply using PIL to save the cropped region of interest when generating the screenshots works. 生成屏幕截图时,仅使用PIL保存感兴趣的裁剪区域即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.