I am doing model inferencing on images. I have a folder with images, named image_0, image_1 and so on. I need to read each image, do the inference job and then save them with the same name in order to merge them together to form a bigger image. To read the images, I use the next code:
for image_path in sorted(glob.glob(r'/patches/images/*.png')):
image_np = load_image_into_numpy_array(image_path)
After the inference, to save each image I do:
cv2.imwrite(f'patches/new/image_{n}.png', im_bgr)
The line above is in the same for
loop as glob
.
n
is the number of the image, indicated by a counter in each iteration.
The problem is that glob
is not reading the images in the correct order (even if I put sorted
before it, as I read in other questions), so when I merge them together, instead of being like this (each number represents an image):
1 2 3
4 5 6
7 8 9
the result is not ordered:
1 6 8
2 9 4
5 7 3
So, how can I make glob
to read the images in the correct order?
Thank you!!!