With crackwitz’s help,i successed clear up my doubts,this is my code:
import cv2
import time
img1 = cv2.imread('lena.jpg',0)
# 1.init
#surf = cv2.xfeatures2d_SURF.create()
#sift = cv2.xfeatures2d_SIFT.create()
surf = cv2.xfeatures2d.SURF_create(400)
sift = cv2.xfeatures2d.SIFT_create()
total_time = 0
experiment_times = 1
for i in range(experiment_times):
tic = time.perf_counter()
kp = surf.detect(img1)
toc = time.perf_counter()
total_time +=(toc - tic)
print(f'The mean time of the SURF is::' + str(float(total_time / experiment_times)))
total_time = 0
for i in range(experiment_times):
tic = time.perf_counter()
kp = sift.detect(img1)
toc = time.perf_counter()
total_time +=(toc - tic)
print(f'The mean time of the SIFT is:' + str(float(total_time / experiment_times)))
lena.jpg from opencv/sources/samples/data.
when experiment_times = 1,i got:
The mean time of the SURF is::1.3295887999999998
The mean time of the SIFT is:0.03701199999999982
when experiment_times = 3,i got:
The mean time of the SURF is::0.4178568333333334
The mean time of the SIFT is:0.03863946666666666
when experiment_times = 10,i got:
The mean time of the SURF is::0.14091486000000003
The mean time of the SIFT is:0.037559639999999915
when experiment_times = 100,i got:
The mean time of the SURF is::0.03580691399999997
The mean time of the SIFT is:0.04023345399999998
when experiment_times = 300,i got:
The mean time of the SURF is::0.028634289333333295
The mean time of the SIFT is:0.04184386500000007
when experiment_times = 500,i got:
The mean time of the SURF is::0.026373681000000048
The mean time of the SIFT is:0.04070335280000003
if i dont sent 400 to SURF_create,just use :surf = cv2.xfeatures2d.SURF_create()
,i got:
experiment_times = 1
The mean time of the SURF is::1.2036111
experiment_times = 3
The mean time of the SURF is::0.4234273333333333
experiment_times = 10
The mean time of the SURF is::0.14784130999999998
experiment_times = 100
The mean time of the SURF is::0.03896763600000006
experiment_times = 300
The mean time of the SURF is::0.032780147666666676
just writing about the experiment in the hope that it will help others who have doubts