Skip to content

Instantly share code, notes, and snippets.

@e96031413
Created March 22, 2020 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e96031413/3f8e2ddf63f7428776cda703cb6e4f31 to your computer and use it in GitHub Desktop.
Save e96031413/3f8e2ddf63f7428776cda703cb6e4f31 to your computer and use it in GitHub Desktop.
OpenCV轉換成PIL.Image格式 & PIL.Image轉換成OpenCV格式
# OpenCV轉換成PIL.Image格式:
import cv2
from PIL import Image
import numpy
img = cv2.imread("plane.jpg")
cv2.imshow("OpenCV",img)
image = Image.fromarray(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
image.show()
cv2.waitKey()
# PIL.Image轉換成OpenCV格式:
import cv2
from PIL import Image
import numpy
image = Image.open("plane.jpg")
image.show()
img = cv2.cvtColor(numpy.asarray(image),cv2.COLOR_RGB2BGR)
cv2.imshow("OpenCV",img)
cv2.waitKey()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment