We know opencv is the default BGR
channel order and open the display, and PIL.Image is RGB
opened and displayed, in order to use opencv open picture shows it must be converted channel (no conversion channel can also be displayed in PIL.Image, but the color will change).
Opencv turn PIL.Image
cv2_img = cv2.imread("test.jpg") # 返回的数据默认就是numpy.arrary类型
cv2.imshow("cv2_img", cv2_img)
cv2.waitKey(0)
pil_img = Image.fromarray(cv2.cvtColor(cv2_img,cv2.COLOR_BGR2RGB))
pil_img.show()
PIL.Image turn Opencv
pil_img = Image.open("test.jpg")
pil_img.show()
cv2_img = cv2.cvtColor(np.asarray(pil_img), cv2.COLOR_RGB2BGR)
cv2.imshow("cv2_img", cv2_img)
cv2.waitKey(0)