Python Image base64 codec, convert to Opencv, pil. Image

Python Image base64 codec, convert to Opencv, pil. Image Image format

Pil. Image is converted to OpenCV format

import cv2
from PIL import Image
import numpy
 
image = Image.open("1.jpg")
image.show()
img = cv2.cvtColor(numpy.asarray(image),cv2.COLOR_RGB2BGR)
cv2.imshow("OpenCV",img)
cv2.waitKey()
Copy the code

OpenCV is converted to pil. Image format

import cv2
from PIL import Image
import numpy
 
img = cv2.imread("1.jpg")
cv2.imshow("OpenCV",img)
image = Image.fromarray(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
image.show()
cv2.waitKey()
Copy the code