FoldThrustBelt
FoldThrustBelt

Reputation: 13

Having trouble to concatenate multiple images with OpenCV

I have 408 images (256 x 256 pixels). I want to stack them horizontally and vertically to create one big image, but I've had trouble doing so. Files are named 5-X-1.jpg and they're all in the same directory.

If I can manage to generate one single row, I should be able to generate the rest. I've managed to make a list with the paths of these images, but I can't make cv2.imread read this array and stack it horizontally with cv2.hconcat or cv2.hstack. Error returned is "Can't convert object of type 'list' to 'str' for 'filename'".

This is the code I'm trying to get to work:

PathList = [] # empty list
InitialTermCol = 0

for imgs in range(16):
    ImgRowStack = r'C:\Users\total\Desktop\Angry\AUTOPY\JapanSteal' + '\\5-' + str(InitialTermCol) + '-1.jpg'
    PathList.append(ImgRowStack)
    InitialTermCol = InitialTermCol + 1

images = cv2.imread(PathList)
hor = np.hstack(PathList)

cv2.imshow('Horizontal', hor)
cv2.waitKey()

Upvotes: 1

Views: 746

Answers (1)

PVerstraete
PVerstraete

Reputation: 51

You should iterate over the Pathlist, to access the path to the images. Not read a list. Pathlist is in the form :Pathlist=["pathto1","pathto2","pathto3"] . So iterating over it will give you the path to the images.

for d in PathList: \\ images = cv2.imread(d) \\ Fullimage = np.hstack((Fullimage,images))

If this answers helps you, please accept it!

Upvotes: 1

Related Questions