纪录一个坑,就是图像的读取、转换、保存相关的
import cv2
import numpy as np
from pylab import *
from skimage.io import imsave,imread
cv_read=cv2.imread('/0.jpg')#读到的BGR
io_read=imread('/0.jpg')#读到的RGB
cv_RGB=cv2.cvtColor(im,cv2.COLOR_BGR2RGB)#将用cv2读到的BGR转为RGB
cv2.imwrite('/2.jpg',cv_read)#用BGR顺序保存cv_read,会看到正常的图
cv2.imwrite('/3.jpg',io_read)#用BGR顺序保存io_read,会看到红蓝交换的不正常图
cv2.imwrite('/4.jpg',cv_RGB)#用BGR顺序保存cv_RGB,会看到红蓝交换的不正常图
如果代码后面涉及到RGB2GRAY这样的操作,会以大约R3:G6:B1比例计算灰度图,如果错把BGR当作RGB进行了计算会得到不一样的灰度图!
另外PIL.Image.open也是经常被用来读图像的,可以参考此博客:
https://blog.csdn.net/dcrmg/article/details/102963336?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166004750016782425129743%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=166004750016782425129743&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_positive~default-1-102963336-null-null.142v39control,185v2tag_show&utm_term=Image&spm=1018.2226.3001.4187