-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
98 lines (76 loc) · 3.24 KB
/
main.py
File metadata and controls
98 lines (76 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import cv2
import numpy as np
# path to the video
video_path = 'C:/Habib University/OneDrive - Habib University/University/7th Semester/Digital Image Processing/Project/FD in Dynamic Environment/Dynamic1.mp4'
capture = cv2.VideoCapture(video_path)
# initial the frame number of the video frames
frameNr = 0
# total keypoints in the video via SIFT
total_kp_sift = 0
# total keypoints in the video via ORB
total_kp_orb = 0
# total keypoints in the video via Harris cornor detector
total_kp_hcd = 0
# total keypoints in the video via FAST
total_kp_fast = 0
# total keypoints in the video via BRIEF
total_kp_brief = 0
# total keypoints in the video via BRISK
total_kp_brisk = 0
while(True):
flag, frame = capture.read()
if flag:
print(frameNr)
# convert image to gray scale
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Initiate SIFT detector
sift = cv2.SIFT_create()
# find the keypoints with SIFT
kp_sift, sift_descriptors = sift.detectandCompute(gray,None)
# Initiate ORB detector
orb = cv2.ORB_create()
# find the keypoints with ORB
kp_orb = orb.detect(gray,None)
# find the keypoints using Harris cornor detector
gray_hcd = np.float32(gray)
kp_hcd = cv2.cornerHarris(gray_hcd,2,3,0.04)
# Initiate FAST object with default values
fast = cv2.FastFeatureDetector_create()
# find and draw the keypoints
kp_fast = fast.detect(gray,None)
# Initiate BRISK object with default values
brisk = cv2.BRISK_create()
# find and draw the keypoints
kp_brisk = brisk.detect(gray,None)
# Initiate STAR detector
star = cv2.xfeatures2d.StarDetector_create()
# Initiate BRIEF extractor
brief = cv2.xfeatures2d.BriefDescriptorExtractor_create()
# find the keypoints with STAR
kp = star.detect(gray,None)
# compute the descriptors with BRIEF
kp_brief, des = brief.compute(gray, kp)
total_kp_sift += len(kp_sift)
total_kp_orb += len(kp_orb)
total_kp_hcd += len(kp_hcd)
total_kp_fast += len(kp_fast)
total_kp_brief += len(kp_brief)
total_kp_brief += len(kp_brisk)
print('Dimensions of Frame ', str(frameNr),frame.shape)
print('SIFT Keypoints in Frame ', str(frameNr) , ' length of keypoints ', len(kp_sift))
print('ORB Keypoints in Frame ', str(frameNr) , ' length of keypoints ', len(kp_orb))
print('HCD Keypoints in Frame ', str(frameNr) , ' length of keypoints ', len(kp_hcd))
print('FAST Keypoints in Frame ', str(frameNr) , ' length of keypoints ', len(kp_fast))
print('BRISK Keypoints in Frame ', str(frameNr) , ' length of keypoints ', len(kp_brisk))
else:
break # exist the loop when frames are finished
frameNr = frameNr+1 # increment in frame number
print(" = "*12)
print('\n'*5)
print('Total SIFT keypoints in the video', total_kp_sift)
print('Total ORB keypoints in the video', total_kp_orb)
print('Total HCD keypoints in the video', total_kp_hcd)
print('Total FAST keypoints in the video', total_kp_fast)
print('Total BRIEF keypoints in the video', total_kp_brief)
print('Total BRIEF keypoints in the video', total_kp_brisk)
capture.release()