将cv2图像存储到缓存或内存中

2024-10-01 17:28:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我现在正在用一个500万像素的相机做一些图像处理。我用cpp把相机里的图像转换成CV2格式。然后,我使用Python脚本加载它们来处理图像。使用cv2.imread()和以下代码加载200个图像需要9.426秒:

    images = glob.glob('InputSimulation\*.jpg')
    #images = Glob.fileList("InputSimulation"+os.sep)
    # images = images.sort()
    # sort out all characters just let the string remain
    images = sorted(images, key=lambda name: int(name[22:-4]))

    # TestNewMethod
    index = 0
    cv2ImageList = []
    for fname in images:
       #for testing reasons
        if index % skip_fac != 0:
            continue
        cv2ImageList.append(cv2.imread(fname))

我不确定是否有比使用cv2.imread()和for循环更快的方法。有什么建议吗?在


Tags: name图像forindex像素sortcv2fname

热门问题