-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetect_objects.py
More file actions
59 lines (45 loc) · 1.56 KB
/
detect_objects.py
File metadata and controls
59 lines (45 loc) · 1.56 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
# import the necessary packages
import numpy as np
import cv2
from cv2 import CAP_PROP_FPS, CAP_PROP_FRAME_COUNT
pathToVideo = '/home/peternagy/facial_landmark/world.mp4'
tracker = cv2.legacy.TrackerTLD_create()
video = cv2.VideoCapture(pathToVideo)
frameIndex = 5000
# frameIndex = 5010
video.set(1, int(frameIndex - 1))
ok, frame = video.read()
bboxes = []
# bbox = (302, 236, 40, 40)
bbox = (310, 182, 40, 40)
bboxes.append(bbox)
bbox = (316, 290, 40, 40)
# bbox = (304, 289, 40, 80)
bboxes.append(bbox)
# bbox = (824, 219, 40, 40)
bbox = (822, 165, 40, 40)
bboxes.append(bbox)
bbox = (825, 275, 40, 40)
# bbox = (824, 280, 50, 90)
bboxes.append(bbox)
multiTracker = cv2.legacy.MultiTracker_create()
for bbox in bboxes:
multiTracker.add(cv2.legacy.TrackerTLD_create(), frame, bbox)
for i, newbox in enumerate(bboxes):
p1 = (int(newbox[0]), int(newbox[1]))
p2 = (int(newbox[0] + newbox[2]), int(newbox[1] + newbox[3]))
cv2.rectangle(frame, p1, p2, (255, 0, 0), 2, 1)
cv2.imshow('MultiTracker', frame)
cv2.waitKey(0)
while True:
ok, frame = video.read()
frameIndex = frameIndex + 1
# ok, bbox = tracker.update(frame)
success, boxes = multiTracker.update(frame)
for i, newbox in enumerate(boxes):
p1 = (int(newbox[0]), int(newbox[1]))
p2 = (int(newbox[0] + newbox[2]), int(newbox[1] + newbox[3]))
cv2.rectangle(frame, p1, p2, (255, 0, 0), 2, 1)
cv2.putText(frame, "Frame Index : " + str(int(frameIndex)), (100, 50), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50, 170, 50), 2);
cv2.imshow('MultiTracker', frame)
cv2.waitKey(0)