- 安装
windows下python环境最方便的就是直接pip install opencv-python
- 图片质量
import cv2
img= cv2.imread('image0.JPG',1)
cv2.imwrite('imageMyTest.jpg', img,[cv2.IMWRITE_JPEG_QUALITY,0]) # arg3:图片质量,jpg为有损压缩
img= cv2.imread('image0.JPG',1)
cv2.imwrite('imageMyTest.png', img,[cv2.IMWRITE_PNG_COMPRESSION,0]) # arg3:图片质量,png为无损压缩
# jpg 为0的时候压缩比高(0~100),png为0的时候压缩比低(0~9)
【opencv学习】像素操作
import cv2
img = cv2.imread('image0.jpg',1)
(b,g,r) = img[100,100]
print(b,g,r)# bgr
#10 100 --- 110 100
for i in range(1,100):
img[10+i,100] = (255,0,0)
cv2.imshow('image',img)
cv2.waitKey(0) #1000 ms
image.png