方法及运行结果
#PIL Image转成opencv Image
#python-Version3.7.1
#
'''Packages&Version
numpy==1.15.3
opencv-python==3.4.2.16
opencv-contrib-python==3.4.2.16
Pillow-PIL==0.1.dev0
'''
from PIL import Image, ImageEnhance
import cv2
import numpy
pil_image = Image.open('image.jpg')
contrast_enhancer = ImageEnhance.Contrast(pil_image)
pil_enhanced_image = contrast_enhancer.enhance(2)
enhanced_image = np.asarray(pil_enhanced_image)
r, g, b = cv2.split(enhanced_image)
enhanced_image = cv2.merge([b, g, r])
cv2.imshow('Enhanced Image', enhanced_image)
cv2.waitKey()
输入图片:
输出图片: