首页 > 其他分享 >18.压缩图片

18.压缩图片

时间:2022-08-30 09:25:33浏览次数:101  
标签:ranfs Users Pictures 压缩 cv2 jpg 18 imwrite 图片

语法

读取图片,并进行质量压缩,语法imwrite(filename, img, params=None)

注意

注意这里的params,是(paramId_1, paramValue_1, paramId_2, paramValue_2, ... .)这种写法,其中paramId需要去查,针对图片压缩,可以选用IMWRITE_JPEG_QUALITY

示例

import cv2
import numpy as np
src = cv2.imread('C:/Users/ranfs/Pictures/ranfs0.jpg')
cv2.imwrite('C:/Users/ranfs/Pictures/ranfs01.jpg', src)
cv2.imwrite('C:/Users/ranfs/Pictures/ranfs95.jpg', src, (cv2.IMWRITE_JPEG_QUALITY, 95))
cv2.imwrite('C:/Users/ranfs/Pictures/ranfs85.jpg', src, [cv2.IMWRITE_JPEG_QUALITY, 85])
cv2.imwrite('C:/Users/ranfs/Pictures/ranfs25.jpg', src, [cv2.IMWRITE_JPEG_QUALITY, 25])
cv2.imwrite('C:/Users/ranfs/Pictures/ranfs15.jpg', src, [cv2.IMWRITE_JPEG_QUALITY, 15])

参考:

[1] cv :: ImwriteFlags https://blog.csdn.net/Dontla/article/details/102701956
[2] Image file reading and writing https://docs.opencv.org/4.1.0/d4/da8/group__imgcodecs.html#ga292d81be8d76901bff7988d18d2b42ac

标签:ranfs,Users,Pictures,压缩,cv2,jpg,18,imwrite,图片
From: https://www.cnblogs.com/TheoryDance/p/16638110.html

相关文章