美文网首页
存取图像 — OpenCV& Python

存取图像 — OpenCV& Python

作者: WZChan | 来源:发表于2017-10-09 14:16 被阅读0次
import cv2

img_path = 'C:/Users/WZChan/Desktop/test_600x350.jpg'
color_img = cv2.imread(img_path)
print color_img.shape

gray_img = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)
print gray_img.shape

cv2.imwrite('C:/Users/WZChan/Desktop/test_grayscale.jpg', gray_img)
reload_grayscale = cv2.imread('C:/Users/WZChan/Desktop/test_grayscale.jpg')
print reload_grayscale

#IMWRITE_JEPG_QUALITY:0~100  DEFAULT:95
cv2.imwrite('C:/Users/WZChan/Desktop/test_600x350_imwrite.jpg', color_img, (cv2.IMWRITE_JPEG_QUALITY, 80))
#IMWRITE_PNG_COMPRESSION:0~9 DEFAULT:3
cv2.imwrite('C:/Users/WZChan/Desktop/test_600x350_imwrite.png', color_img, (cv2.IMWRITE_PNG_COMPRESSION, 5))
img_cv2.jpg img_pyplot.jpg

相关文章

网友评论

      本文标题:存取图像 — OpenCV& Python

      本文链接:https://www.haomeiwen.com/subject/mhfpyxtx.html