Skip to content

Commit

Permalink
added csv report
Browse files Browse the repository at this point in the history
  • Loading branch information
Schuman Zhang committed Jul 3, 2018
1 parent 53db9f6 commit deb5758
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions analytics/tracking.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from collections import defaultdict
import csv
import cv2
import os

# tracks and tallys what's present at any particular time on screen
# puts stats in a csv file in another directory
# [['person: 98%'], ['book: 55%'], ['book: 50%']]
class ObjectTracker(object):
def __init__(self):
def __init__(self, path, file_name):
self.class_counts = {}
self.occupancy = False
self.fp = open(os.path.join(path, file_name), 'w')
self.writer = csv.DictWriter(self.fp, fieldnames=['frame', 'detections'])
self.writer.writeheader()
self.prev = None


def update_class_counts(self, class_names):
Expand All @@ -28,8 +33,8 @@ def update_person_status(self, class_names):
self.occupancy = False


def write_to_report(self):
pass
def write_to_report(self, frame_number):
self.writer.writerow({'frame': frame_number, 'detections': self.class_names})


def __call__(self, context):
Expand All @@ -55,5 +60,7 @@ def __call__(self, context):
key_1 = str(list(self.class_counts.keys())[0])
cv2.putText(frame, (key_1 + ':' + str(self.class_counts[key_1])), (int(frame.shape[1] * 0.85), 30), font, 0.6, (255, 255, 255), 1)

self.write_to_report(context['frame_number'])

return frame

4 changes: 2 additions & 2 deletions objection_detection_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def worker(input_q, output_q):
'''

fps = FPS().start()
object_tracker = ObjectTracker()
object_tracker = ObjectTracker(path='./', file_name='report.csv')
while True:
frame = video_capture.read()
# (ret, frame) = stream.read()
Expand All @@ -131,7 +131,7 @@ def worker(input_q, output_q):
else:
data = output_q.get()
context = {'frame': frame, 'class_names': data['class_names'], 'rec_points': data['rect_points'], 'class_colors': data['class_colors'],
'width': args.width, 'height': args.height}
'width': args.width, 'height': args.height, 'frame_numer': fps.get_numFrames()}
new_frame = object_tracker(context)
cv2.imshow('Video', new_frame)

Expand Down

0 comments on commit deb5758

Please sign in to comment.