import cv2 img = cv2.imread ('C:/Users/Administrator/Pictures/test1.jpg',0) # 读取图片,第二个参数0是灰色,1是彩色 img2 = cv2.imread ('C:/Users/Administrator/Pictures/test1.jpg',1)
#jpg保存
cv2.imwrite('C:/Users/Administrator/Pictures/write1.jpg',img) #写入图片 jpg有损压缩,png无损压缩
cv2.imwrite('C:/Users/Administrator/Pictures/write2.jpg',img2,[cv2.IMWRITE_JPEG_QUALITY,50]) #最后一个参数控制图片质量 0-100
#png保存
cv2.imwrite('C:/Users/Administrator/Pictures/write1.png',img2,[cv2.IMWRITE_PNG_COMPRESSION,9]) #最后一个参数为压缩倍数 0-9
cv2.imshow('pic_name',img) #展示图片 1 name 2 img cv2.waitKey(0) #停止程序,否则展示太快,看不