原文链接: opencv 和scipy misc 模块 图像resize 速度比较 timeit 模块使用
上一篇: fast style transfer 快速风格转换 test
下一篇: python 成员变量和类变量的区别
操作不是很频繁的话使用misc模块比较方便
如果需要大量进行resize操作,或者需要对大图片进行操作,使用opencv会显著加快速度
import cv2 as cv
import scipy.misc as sm
import numpy as np
import timeit
size = (500, 500)
new_size = (600, 600)
image = np.random.uniform(0, 255, size).astype(np.uint8)
def f1():
cv.resize(image, new_size)
def f2():
sm.imresize(image, new_size)
step = 1000
repeat = 10
# 长度为10 的数组,表示每一千次的执行时间
print(timeit.Timer('f1()', setup='from __main__ import f1').repeat(repeat, step))
print(timeit.Timer('f2()', s