-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetection.py
More file actions
executable file
·56 lines (40 loc) · 1.83 KB
/
detection.py
File metadata and controls
executable file
·56 lines (40 loc) · 1.83 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
import time
import pickle
import cv2
import numpy as np
from sfmt.config import video_config, detector_config
from sfmt.concurrent_detector import ConcurrentDetector
from sfmt.video_collector import VideoCollector
if __name__ == "__main__":
cams = video_config["cams"]
scaling_factor = video_config["scaling_factor"]
# for retrieval of video frames from files/cameras
video_collector = VideoCollector(cams)
# create object detector
detector = ConcurrentDetector()
# create GUI window for video output
for cap_id in range(len(cams)):
cv2.namedWindow("cap {}".format(cap_id), cv2.WINDOW_NORMAL)
cv2.resizeWindow("cap {}".format(cap_id), 640, 360)
step = 0
while True:
# get frames from each camera (each list entry corresponds to a frame of a different camera)
timestamps, frames = video_collector.get_frame_packet()
# resize the frame by a factor to make subsequent processing faster
frames_small = video_collector.resize_frames(frames, video_config["scaling_factor"])
# run the object detector on each frame in the list of frames
# returns a set of detected bounding boxes, class labels and confidence scores for each frame
detections = detector.detect_batch(frames)
# store detections for each step in a file "detections/step_xxx"
print(detections)
pickle.dump(detections, open("detections/step_{}.pkl".format(step), "wb"))
step += 1
# display frames
for cap_id, (frame_small, cam) in enumerate(zip(frames_small, video_config["cams"])):
cv2.imshow("cap {}".format(cap_id), frame_small)
# if user presses key 'q' exit the loop and stop program
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# clean up
video_collector.destroy()
cv2.destroyAllWindows()