图片数据读取速度比较
import time
import cv2
import os
import numpy as np
# opencv
N = 100
tic = time.time()
for i in range(N):
img=cv2.imread(r'D:\code\testAndExperiment\py\Gluon\test1\1.jpeg',1)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
print(N/(time.time()-tic), 'images decoded per second with opencv')
from scipy.misc import imread
N = 100
tic = time.time()
for i in range(N):
img = imread(r'D:\code\testAndExperiment\py\Gluon\test1\1.jpeg')
print(N/(time.time()-tic), 'images decoded per second with scipy.misc')
from skimage import io
N = 100
tic = time.time()
for i in range(N):
img = io.imread(r'D:\code\testAndExperiment\py\Gluon\test1\1.jpeg')
print(N/(time.time()-tic), 'images decoded per second with skimage')
# # pillow
from PIL import Image
N = 100
tic = time.time()
for i in range(N):
img = Image.open(r'D:\code\testAndExperiment\py\Gluon\test1\1.jpeg')
img = np.array(img)
print(N/(time.time()-tic), 'images decoded per second with pillow')
# mx.image
import mxnet as mx
N = 100
tic = time.time()
for i in range(N):
img = mx.image.imdecode(open(r'D:\code\testAndExperiment\py\Gluon\test1\1.jpeg','rb').read())
mx.nd.waitall()
print(N/(time.time()-tic), 'images decoded per second with mx.image')
测试可能受环境影响,结果据说mx是OpenCV的5倍
https://www.lizenghai.com/archives/49800.html