使用 Python-glob 在循环中一次加载两个图像
Loading two images at a time in a loop using Python-glob
我正在尝试使用 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-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]
andimage[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