opencv与PIL.Image读取图片的速度对比

用python读同一张图片,连续读取100次,opencv的耗时比Image的多不少。

代码如下:

import time
import cv2
import numpy as np
import PIL.Image as Image

img_fn = '1651_00006204.png'

N = 100
t1 = time.time()
for i in range(N):
    img = cv2.imread(img_fn)
t2 = time.time()-t1
print('io cost cv ',t2)

t1 = time.time()
for i in range(N):
    img = Image.open(img_fn)
    img = np.asarray(img)
t2 = time.time()-t1
print('io cost pil ',t2)

执行结果:

你可能感兴趣的:(python,opencv,python)