I have a directory of images which I am trying to resize. However during this process I do not want to retain them in the directory hence I am trying to rewrite with the same name. The following is my code:
import os
from os.path import basename
from imutils import paths
import imutils
import argparse
import cv2
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to the input image")
args = vars(ap.parse_args())
for (i, imagePath) in enumerate(paths.list_images(args['image'])):
image = cv2.imread(imagePath)
fil = basename(imagePath)
filname = os.path.splitext(fil)[0]
newimage = imutils.resize(image, width=500)
cv2.imwrite(filname+'.jpg', newimage)
When I try to use cv2.imshow for both pre and post resize I could get the display. Similarly when I print the fil and filname, it gets printed correctly. However, the images are not getting overwritten.