如何在不需要保存/加载的情况下在PIL和cv2之间转换图像(Python 3.6.3)

时间:2017-12-11 05:21:11

标签: python image python-imaging-library cv2

Python 3.6.3

如何在不保存和反复加载图片的情况下执行以下操作,有没有办法在两种格式之间转换图像? (允许我只在开头加载一次图片并在结尾处保存一次。)

from PIL import Image
import cv2
import numpy as np

img = Image.open(r'C:\Users\Chris\Desktop\programs\pic.jpg')
#modify picture using PIL functions
img.save(r'C:\Users\Chris\Desktop\programs\pic.jpg')

img = cv2.imread("pic.jpg")
#modify picture using cv2 functions
cv2.imwrite("pic.jpg", img)

img = Image.open(r'C:\Users\Chris\Desktop\programs\pic.jpg')
#modify picture using PIL functions
img.save(r'C:\Users\Chris\Desktop\programs\pic.jpg)')

0 个答案:

没有答案