Opencv 随笔1------ 图片的读写(png jpg)

1.图片的读写

!!!!!opencv 读入JPG图片的 颜色顺序是 B G R (blue ,green , red )

!!!!!skimage 读入JPG图片颜色顺序是 RGB

!!!!!matplotlib 也是RGB显示JPG


import cv2
import os
PicName = raw_input("please input name of picture:")
path = os.path.join(os.getcwd(), PicName)#os.getwd 获取当前目录
print path
img = cv2.imread(path, 1) #读入存储的格式是 numpy,
cv2.imshow("1", img)
cv2.waitKey(0) #这个一定要加这样imshow 才起作用

2.图片的保存(png  jph)

import cv2
import os
PicName = raw_input("please input name of picture:")
path = os.path.join(os.getcwd(), PicName)#os.getwd 获取当前目录
print path
img = cv2.imread(path, 1) #读入存储的格式是 numpy,
cv2.imshow("1", img)
cv2.waitKey(0) #这个一定要加这样imshow 才起作用
cv2.imwrite('img.jpg',img, [cv2.IMWRITE_JPEG_QUALITY, 50])
# jpg 存储,范围 0-100,品质越高,数字越大
cv2.imwrite('imge1.png',img, [cv2.IMWRITE_PNG_COMPRESSION, 0])
# png ,参数范围0-9 ,表示压缩, 数字越小,压缩越小

 

你可能感兴趣的:(opencv)