Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 30 video output #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions umt/umt_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import time
import datetime
import argparse

import cv2
Expand All @@ -21,7 +22,9 @@

LABEL_PATH = "models/tflite/coco_ssd_mobilenet_v1_1.0_quant_2018_06_29/labelmap.txt"
DEFAULT_LABEL_MAP_PATH = os.path.join(os.path.dirname(__file__), LABEL_PATH)
TRACKER_OUTPUT_TEXT_FILE = 'object_paths.csv'
TRACKER_OUTPUT_TEXT_FILE = f'object_paths/object_paths_{datetime.date.today()}_{int(time.time())}.csv'
VIDEO_OUT_ORIGINAL_FRAMES = f'output/{datetime.date.today()}_{int(time.time())}-original-frames.avi'
VIDEO_OUT_DETECTED_FRAMES = f'output/{datetime.date.today()}_{int(time.time())}-detected-frames.avi'

# deep sort related
MAX_COSINE_DIST = 0.4
Expand Down Expand Up @@ -75,6 +78,9 @@ def main():

# main tracking loop
print('\n> TRACKING...')
originalVideoWriter = None
detectedVideoWriter = None

with open(TRACKER_OUTPUT_TEXT_FILE, 'w') as out_file:
for i, pil_img in enumerate(img_generator(args)):

Expand All @@ -83,10 +89,17 @@ def main():

# add header to trajectory file
if i == 0:
header = (f'frame_num,rpi_time,obj_class,obj_id,obj_age,'
'obj_t_since_last_update,obj_hits,'
'xmin,ymin,xmax,ymax')
print(header, file=out_file)
header = (f'frame_num,rpi_time,obj_class,obj_id,obj_age,'
'obj_t_since_last_update,obj_hits,'
'xmin,ymin,xmax,ymax')
print(header, file=out_file)

if args.save_frames:
# note: selecting 10fps is certainly wrong-- the wrongness will depend on the speed of processing (most specifically if
# we have GPU / TPU capabilities.)
originalVideoWriter = cv2.VideoWriter(VIDEO_OUT_ORIGINAL_FRAMES,cv2.VideoWriter_fourcc('M','J','P','G'), 10, (pil_img.width,pil_img.height))
detectedVideoWriter = cv2.VideoWriter(VIDEO_OUT_DETECTED_FRAMES,cv2.VideoWriter_fourcc('M','J','P','G'), 10, (pil_img.width,pil_img.height))


# get detections
detections = generate_detections(pil_img, interpreter, args.threshold)
Expand Down Expand Up @@ -117,6 +130,10 @@ def main():
# convert pil image to cv2
cv2_img = cv2.cvtColor(np.array(pil_img), cv2.COLOR_RGB2BGR)

# write a frame to the "original" video
if args.save_frames:
originalVideoWriter.write(cv2_img)

# cycle through actively tracked objects
for track in tracker.tracks:
if not track.is_confirmed() or track.time_since_update > 1:
Expand All @@ -136,8 +153,16 @@ def main():
cv2.waitKey(1)

# persist frames
if args.save_frames: cv2.imwrite(f'output/frame_{i}.jpg', cv2_img)

if args.save_frames:
cv2.imwrite(f'output/frame_{i}.jpg', cv2_img)
# write a frame to the "detected" video
detectedVideoWriter.write(cv2_img)

#cleanup the video resources
if args.save_frames:
originalVideoWriter.release()
detectedVideoWriter.release()

cv2.destroyAllWindows()
pass

Expand Down