-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
63 lines (50 loc) · 1.59 KB
/
main.py
File metadata and controls
63 lines (50 loc) · 1.59 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
import time
import cv2
from tracker import processLiveFeed, startVideoWriter, endVideoWriter
"""
Implements an ORB-based object tracker as specified by the paper:
Object Tracking Based on ORB and Temporal-Spacial Constraint by Shuang Wu,
IEEE Student Member, Yawen Fan, Shibao Zheng, IEEE Member and Hua Yang, IEEE
Member
Authors: Alberto Serrano, Stephen Kim
"""
def main():
cap = cv2.VideoCapture("IMG_3385.MOV")
frame_width = int(cap.get(3))
frame_height = int(cap.get(4))
time.sleep(0.3)
prevImg = None
# always comparing two frames, so do something else seeing first frame
# prompt for ROI, then set to cframe
ret,img = cap.read()
bbox = cv2.selectROI(img, False)
prevImg = img
# Extract Bounding Box features
x = int(bbox[0])
y = int(bbox[1])
w = int(bbox[2])
h = int(bbox[3])
x_i = x + w/2
y_i = y + h/2
# Define current and past frame
cframe = (x_i, y_i, w, h)
pframe = cframe
while(True):
# Capture frame-by-frame
ret, img = cap.read()
# Constraint to end when reading from a video file instead of a device
# video stream.
if img is None:
return
else:
# prevImg will be None for first iteration (first frame)
pframe, cframe = processLiveFeed(prevImg, img, pframe, cframe)
prevImg = img
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
endVideoWriter()
# cv2.destryoAllWindows()
if __name__ == "__main__":
main()