CV2模块教程系列——打开读取图片、窗口显示、保存图片
import cv2
img1 = cv2.imread('./imgg/1.jpeg',cv2.IMREAD_GRAYSCALE)
# cv2.IMREAD_COLOR:默认参数,读入一副彩色图片,忽略alpha通道
# cv2.IMREAD_GRAYSCALE:读入灰度图片
# cv2.IMREAD_UNCHANGED:顾名思义,读入完整图片,包括alpha通道
cv2.imshow('image',img1)
# 等待键盘输入
cv2.waitKey(0)
#cv2.IMWRITE_JPEG_QUALITY类型为 long ,必须转换成 int
#cv2.IMWRITE_PNG_COMPRESSION, 从0到9 压缩级别越高图像越小
cv2.imwrite('./out/1_1.jpg',img1, [int( cv2.IMWRITE_JPEG_QUALITY), 95])
cv2.imwrite('./out/1_2.jpg',img1, [int(cv2.IMWRITE_PNG_COMPRESSION), 9])
# 销毁所有窗口
cv2.destroyAllWindows()
# 销毁指定窗口
#dv2.destroyWindow(wname)