0


Python OpenCv学习基础知识六

Python OpenCv学习基础知识六

文章目录

一、简介

好久没有更新opencv了,今天来一篇opencv重启opencv征程。

二、程序效率检测一

"""
1\1、使用OpenCV检测程序效
率

使用OpenCV检测程序效率
"""import cv2
import numpy as np

img1 = cv2.imread('E:\\\\1\\\\Documents\\\\PyTorch\\\\pytorch_learning\\\\others\\\\opencv_cv_2\\\\test1.jpg')

e1 = cv2.getTickCount()for i inrange(5,49,2):
    img1 = cv2.medianBlur(img1,i)
e2 = cv2.getTickCount()
time =(e2-e1)/cv2.getTickFrequency()print(time)"""
import cv2
import numpy as np

img1 = cv2.imread('45.jpg')

e1 = cv2.getTickCount()
for i in range(5,49,2):
    img1 = cv2.medianBlur(img1,i)
e2 = cv2.getTickCount()
time = (e2-e1)/cv2.getTickFrequency()
print(time)
"""

三、程序效率检测二

# 2\2、OpenCV中的默认优化"""
import cv2 
import numpy as np

# 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
"""

四、程序效率监测三

"""
3\3、在IPython中检测程序效率
""""""
import cv2
import numpy as np

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
"""

五、总结

以上就是一些有关程序效率监测的内容,希望对大家有一些帮助了啦。

最后,谢谢大家的阅读与支持嘞la


本文转载自: https://blog.csdn.net/m0_54218263/article/details/122754406
版权归原作者 hhh江月 所有, 如有侵权,请联系我们删除。

“Python OpenCv学习基础知识六”的评论:

还没有评论