Python OpenCv,仅读取部分图像 [英] Python OpenCv, only read part of image

查看:318
本文介绍了Python OpenCv,仅读取部分图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数千个大的.png图像(屏幕截图).我正在使用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]

分析器告诉我cv2.imread是瓶颈.我想知道是否可以通过仅读取我感兴趣的每个图像的一部分而不是加载整个图像然后裁剪到边界来使脚本更快.我虽然找不到OpenCV标志.我想念一个吗?

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,无法使用OpenCV做到这一点.但是我确实在这里找到了解决方案:仅加载以下内容的一部分python中的图片

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

在生成屏幕截图时,只需使用PIL保存感兴趣的裁剪区域.

Simply using PIL to save the cropped region of interest when generating the screenshots works.

这篇关于Python OpenCv,仅读取部分图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆