opencv-性能测量与改进技术
2017-10-20 17:17
232 查看
参考:
1、http://docs.opencv.org/3.3.0/ 官方文档api
2、http://docs.opencv.org/3.3.0/d6/d00/tutorial_py_root.html 官方英文教程
3、https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_tutorials.html
4、https://github.com/makelove/OpenCV-Python-Tutorial# 进阶教程
5、https://docs.opencv.org/3.3.0/index.html
官方英文教程
6、https://github.com/abidrahmank/OpenCV2-Python-Tutorials
7、https://www.learnopencv.com/
8、http://answers.opencv.org/questions/ OpenCV论坛
注:安装的版本
opencv_python-3.3.0-cp36-cp36m-win_amd64.whl
参考:https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_tutorials.html
To measure the performance of your code.
Some tips to improve the performance of your code.
You will see these functions : cv2.getTickCount, cv2.getTickFrequency etc.
Python also provides a module time which is helpful in measuring the time of execution.
Another module profile helps to get detailed report on the code,
Normally, OpenCV functions are faster
than Numpy functions. So for same operation, OpenCV functions are preferred. But, there can be exceptions, especially when Numpy works with views instead of copies.
Scipy Lecture Notes - Advanced
Numpy
Timing and Profiling in IPython
1、http://docs.opencv.org/3.3.0/ 官方文档api
2、http://docs.opencv.org/3.3.0/d6/d00/tutorial_py_root.html 官方英文教程
3、https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_tutorials.html
4、https://github.com/makelove/OpenCV-Python-Tutorial# 进阶教程
5、https://docs.opencv.org/3.3.0/index.html
官方英文教程
6、https://github.com/abidrahmank/OpenCV2-Python-Tutorials
7、https://www.learnopencv.com/
8、http://answers.opencv.org/questions/ OpenCV论坛
注:安装的版本
opencv_python-3.3.0-cp36-cp36m-win_amd64.whl
参考:https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_tutorials.html
性能测量与改进技术
目标
To measure the performance of your code.Some tips to improve the performance of your code.
You will see these functions : cv2.getTickCount, cv2.getTickFrequency etc.
Python also provides a module time which is helpful in measuring the time of execution.
Another module profile helps to get detailed report on the code,
使用OpenCV测量性能
e1 = cv2.getTickCount() # your code execution e2 = cv2.getTickCount() time = (e2 - e1)/ cv2.getTickFrequency()
import cv2
from datetime import datetime import time # Load two images img1 = cv2.imread('messi5.jpg') e1 = cv2.getTickCount() start_time=datetime.now() start_time2=time.time() for i in range(5,49,2): img1 = cv2.medianBlur(img1,i) e2 = cv2.getTickCount() t = (e2 - e1)/cv2.getTickFrequency() print(t) print((datetime.now()-start_time).total_seconds()) print(time.time()-start_time2) # Result I got is 0.521107655 seconds# Load two imagesimg1 = cv2.imread('messi5.jpg')e1 = cv2.getTickCount()start_time=datetime.now()for i in range(5,49,2): img1 = cv2.medianBlur(img1,i)e2 = cv2.getTickCount()t = (e2 - e1)/cv2.getTickFrequency()print(t)print((datetime.now()-start_time).total_seconds())# Result I got is 0.521107655 seconds
OpenCV中的默认优化
# check if optimization is enabled In [5]: cv2.useOptimized() Out[5]: True In [6]: %timeit res = cv2.medianBlur(img,49) 10 loops, best of 3: 34.9 ms per loop # Disable it In [7]: cv2.setUseOptimized(False) In [8]: cv2.useOptimized() Out[8]: False In [9]: %timeit res = cv2.medianBlur(img,49) 10 loops, best of 3: 64.1 ms per loop
测量IPython中的性能
In [10]: x = 5 In [11]: %timeit y=x**2 10000000 loops, best of 3: 73 ns per loop In [12]: %timeit y=x*x 10000000 loops, best of 3: 58.3 ns per loop In [15]: z = np.uint8([5]) In [17]: %timeit y=z*z 1000000 loops, best of 3: 1.25 us per loop In [19]: %timeit y=np.square(z) 1000000 loops, best of 3: 1.16 us per loop
In [35]: %timeit z = cv2.countNonZero(img) 100000 loops, best of 3: 15.8 us per loop In [36]: %timeit z = np.count_nonzero(img) 1000 loops, best of 3: 370 us per loop
Normally, OpenCV functions are faster
than Numpy functions. So for same operation, OpenCV functions are preferred. But, there can be exceptions, especially when Numpy works with views instead of copies.
Additional Resources
Python Optimization TechniquesScipy Lecture Notes - Advanced
Numpy
Timing and Profiling in IPython
相关文章推荐
- OpenCV-Python[第三章]——性能测量与优化技巧
- 测量webView页面性能技术方案
- JavaScript测量和影响性能的工具和技术
- 测量webView页面性能技术方案
- 对论文试题3“论改进Web服务器性能的有关技术”写作的评注
- 论改进Web服务器性能的有关技术—论文1:银行业的应用
- LTE发射机ACLR性能的测量技术
- LTE发射机ACLR性能的测量技术
- 深入oracle 12c数据库备份与恢复(优化RMAN性能、Oracle flashback技术)
- 高并发处理技术老司机带你玩RabbitMq实现性能倍增
- 逐渐成熟 Intel VT技术性能初探
- go程序性能测量和分析
- 网格技术亟待改进
- asp.net 程序性能优化的七个方面 (c#(或vb.net)程序改进)
- netperf 与网络性能测量
- XX行关于联机交易(OLTP)系统类项目的性能测试技术方案
- 由12306.cn谈谈网站性能技术
- 软件性能优化漫谈(一):软件性能测量与分析
- 秋色园QBlog技术原理解析:性能优化篇:缓存总有失效时,持续的缓存方案(十四)
- 虚拟化技术性能总结:Zones, KVM, Xen