opencv默认优化
在opencv当中包含没有被优化的代码,使用 cv2.useOptimized()函数查看是否被优化
使用cv2.setUseOptimized()开启优化
import cv2
import numpy as np
# check if optimization is enabled
print(cv2.useOptimized())#True
e1 = cv2.getTickCount()
s=1+1
e2 = cv2.getTickCount()
print((e2 - e1)/ cv2.getTickFrequency())
cv2.setUseOptimized(False)
print(cv2.useOptimized())#False
e1 = cv2.getTickCount()
s=1+1
e2 = cv2.getTickCount()
print((e2 - e1)/ cv2.getTickFrequency())
使用函数cv2.useOptimized() 来查看优化是否被开启,
使用函数cv2.setUseOptimized() 来开启优化。
import cv2
import numpy as np
img = cv2.imread('cat.jpg')
# check if optimization is enabled
cv2.useOptimized()
%timeit res = cv2.medianBlur(img,49)
# Disable it
cv2.setUseOptimized(False)
cv2.useOptimized()
%timeit res = cv2.medianBlur(img,49)
网友评论