Last active
February 15, 2017 07:28
-
-
Save belltailjp/fed98e975cae577864cc5e4114a2b3d9 to your computer and use it in GitHub Desktop.
Benchmark of OpenCV image decoding speed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import cv2 | |
import time | |
import tqdm | |
import numpy | |
if __name__ == "__main__": | |
img = cv2.imread('image.jpg') | |
img = cv2.resize(img, (768, 1280)) | |
_, imgbuf = cv2.imencode('.jpg', img) | |
n_try = 500 | |
times = numpy.zeros((n_try,), dtype=numpy.float32) | |
for i in tqdm.tqdm(range(n_try)): | |
begin = time.time() | |
_ = cv2.imdecode(imgbuf, 1) | |
times[i] = time.time() - begin | |
times = numpy.sort(times)[1:-1] # exclude minimum and maximum | |
avg = 1000 * numpy.mean(times) | |
std = 1000 * numpy.std(times) | |
print("mean={}ms, stdev={}ms".format(avg, std)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment