gpt4 book ai didi

python - 使用 Python-glob 循环一次加载两个图像

转载 作者:行者123 更新时间:2023-12-01 04:07:51 29 4
gpt4 key购买 nike

我正在尝试使用 Python-glob 读取文件夹中的所有图像。这是部分代码:

    for file in glob.glob("\*.jpg"):
image=cv2.imread(file);

It is working pretty well, but I need to to read two images at a time in one iteration of the glob loop i.e. the two consecutive images. In simple terms i need image[i] and image[i+1].

最佳答案

这是您要找的吗?

files = glob.glob("\*.jpg")
img_a = cv2.imread(files[0])

for file in files[1:]:

img_b = cv2.imread(file);

# do what you need to do with img_a and img_b

# and then prepare img_a for the next loop
img_a = img_b

关于python - 使用 Python-glob 循环一次加载两个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35338343/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com