pil读图片需要0ms,但是转换opencv需要13ms
opencv读图片需要13ms
import numpy as np
import cv2
import time
from PIL import Image
def a():
path='d:/1.jpg'
for i in range(10):
start=time.time()
roiImg=Image.open(path)
img = cv2.cvtColor(np.asarray(roiImg), cv2.COLOR_RGB2BGR)
read_time=time.time()-start
start = time.time()
imgByteArr = io.BytesIO()
roiImg.save(imgByteArr, format='BMP')
# roiImg.save(imgByteArr, format='Jpeg')
# imgByteArr = imgByteArr.getvalue()
print('pil time',read_time,time.time()-start)
start = time.time()
img=Image.open(imgByteArr)
print('read io time', time.time() - start)
# img.show()
# cv2.imshow('',img_decode)
# cv2.waitKey(1)