'Concatenate images from folders by their ORDER in python

I know how to concatenate two exact images, but I need to combine two images each from their own folder. I cannot do it by name of the image or don´t know how to do it with a list of pairs. Is it possible to concatenate all images (always two, one from each folder) by the order of images? They are sorted by time of download so they match in order, not in exact time of download. Thanks.



Solution 1:[1]

Hope this will work !

import cv2 as cv
import os

folder1 = r"folder1_path"
folder2= r"folder2_path"

for img1,img2 in zip(os.listdir(folder1), os.listdir(folder2)):
    img1=cv2.imread(img1)
    img2=cv2.imread(img2)
    concatenate_image= cv2.vconcat([img1, img2])

     cv.imshow('Final_image', comcatenate_image)
     cv.waitKey(0)

Make sure both folder images are in same dimensions.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1