使用Pythonglob一次加载两个图像

2024-10-02 06:23:45 发布

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

我尝试使用pythonglob读取文件夹中的所有图像。 代码如下:

    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].


Tags: theto代码in图像image文件夹for
1条回答
网友
1楼 · 发布于 2024-10-02 06:23:45

这就是你要找的吗?在

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

相关问题 更多 >

    热门问题