import cv2, os base_path = "data/images/" new_path = "data/ims/" for infile in os.listdir(base_path): print ("file : " + infile) read = cv2.imread(base_path + infile) outfile = infile.split('.') + '.jpg' cv2.imwrite(new_path+outfile,read,[int(cv2.IMWRITE_JPEG_QUALITY), 200])
Here is what the above code is Doing:
1. We are reading the image from the path specified in the base_path variable.
2. We are then saving the image to the path specified in the new_path variable.
3. We are also specifying the image quality to be 200.