Created
March 22, 2020 13:59
-
-
Save e96031413/3f8e2ddf63f7428776cda703cb6e4f31 to your computer and use it in GitHub Desktop.
OpenCV轉換成PIL.Image格式 & PIL.Image轉換成OpenCV格式
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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