'How can I fix my python code to save and resize images using glob on linux

I wrote the following code to resize images in a folder to 100*100 and save the images in the same folder using for loop.I am wondering why it isn't working. The following is the code I have written:

import cv2
import glob

images=glob.glob("*.jpg")
for image in images:
    img=cv2.imread(image,0)
    re=cv2.resize(img,(100,100))
    cv2.imshow("Hey",re)
    cv2.waitKey(500)
    cv2.destroyAllWindows()
    cv2.imwrite("resized_"+image,re)

I executed this:

nsu@NSU:~/Desktop/cryptology$ python3 img2.py

I got no error:

nsu@NSU:~/Desktop/cryptology$ python3 img2.py
nsu@NSU:~/Desktop/cryptology$ 

But the folder where i have saved the images and code is as it is...

what should i do?

**A viewer posted an answer which resulted the same. **The problem MAY not be with the code. **Please consider this



Solution 1:[1]

If you like you can use very robust module of python called Pillow for image manipulation, so first do pip3 install pillow

then run this code

from PIL import Image
import glob

images=glob.glob("*.jpg")

for im in images:
    # print(im)
    img = Image.open(im)
    img = img.resize((100, 100), Image.ANTIALIAS)
    img.save(im+'_resized.jpg')

hope it helps ... you need to improve the code if you want to keep the aspect ratio of the image

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 Vivek Sharma