PIL与opencv需要通过一定方法转换,然后转换颜色通道顺序。
scipy与opencv两者都是numpy矩阵,uint8,范围为0-255,通过颜色通道顺序就可以实现转换
path= './datasets/clothes_color_domain_train/color_domain_0000005.jpg'
import cv2
from PIL import Image
import numpy as np
from scipy.misc import imread
#PIL转opencv
image = Image.open(path)
print(image)
image.show()
img = cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2BGR)
cv2.imshow("OpenCV", img)
cv2.waitKey()
cv2.destroyAllWindows()
#opencv转PIL
img = cv2.imread(path)
cv2.imshow("OpenCV", img)
image = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
cv2.waitKey()
cv2.destroyAllWindows()
image.show()
#scipy与opencv区别
img = imread(path)
print(img)
cv2.imshow("scipy and opencv", np.hstack((img, cv2.cvtColor(img,cv2.COLOR_RGB2BGR))))
cv2.waitKey()
cv2.destroyAllWindows()
np.hstack()