'How to concatenate several images given a list
I have a certain scrip that spits a procedurally generated list of lists of strings of what would my tiles be in a square grid:
grid = [['grass', 'grass', 'trees'],
['flowers', 'grass', 'grass'],
['grass', 'flowers', 'grass']]
Now I can't seem to find a way to use these names in order to build an image using images of each tile
grass = cv2.imread('grass.png')
flowers = cv2.imread('flowers.png')
trees = cv2.imread('trees.png')
I am sorry I am quite new here, this is what I tried to implement:
image_grid = None
image_row = None
for row in grid:
for item in row:
if image_row is None:
image_row = eval(item)
else:
image_row = cv2.hconcat([image_row, eval(item)])
if image_grid is None:
image_grid = image_row
else:
image_grid = cv2.vconcat([image_grid, image_row])
cv2.imshow('grid', image_grid)
cv2.waitKey()
But it returns cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\core\src\matrix_operations.cpp:67: error: (-215:Assertion failed)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
