Skip to content

Instantly share code, notes, and snippets.

@belltailjp
Last active February 15, 2017 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save belltailjp/fed98e975cae577864cc5e4114a2b3d9 to your computer and use it in GitHub Desktop.
Save belltailjp/fed98e975cae577864cc5e4114a2b3d9 to your computer and use it in GitHub Desktop.
Benchmark of OpenCV image decoding speed
#!/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