Skip to content

Instantly share code, notes, and snippets.

@jdhao
Created March 11, 2020 10:28
Show Gist options
  • Save jdhao/67e4dfdde3b4dad7f1e1df53e03056b7 to your computer and use it in GitHub Desktop.
Save jdhao/67e4dfdde3b4dad7f1e1df53e03056b7 to your computer and use it in GitHub Desktop.
Save image with quality parameter in OpenCV
import cv2
img = cv2.imread('test.jpg')
# specify the write parameter, can be found in https://docs.opencv.org/master/d4/da8/group__imgcodecs.html#ga292d81be8d76901bff7988d18d2b42ac
write_param = [cv2.IMWRITE_JPEG_QUALITY, 90, cv2.IMWRITE_JPEG_OPTIMIZE, 1]
cv2.imwrite("test_new.jpg", img, write_param)
# Reference
# https://docs.opencv.org/master/d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment