forked from schumanzhang/object_detection_real_time
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Schuman Zhang
committed
Jul 3, 2018
0 parents
commit 53db9f6
Showing
19 changed files
with
1,070 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
tf_models/ | ||
*.csv |
Empty file.
Empty file.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from collections import defaultdict | ||
import csv | ||
import cv2 | ||
|
||
# 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): | ||
self.class_counts = {} | ||
self.occupancy = False | ||
|
||
|
||
def update_class_counts(self, class_names): | ||
frame_counts = defaultdict(int) | ||
for item in class_names: | ||
count_item = item[0].split(':')[0] | ||
frame_counts[count_item] += 1 | ||
|
||
# sort this dictionary? | ||
self.class_counts = frame_counts | ||
|
||
def update_person_status(self, class_names): | ||
for item in class_names: | ||
if item[0].split(':')[0] == 'person': | ||
self.occupancy = True | ||
return | ||
self.occupancy = False | ||
|
||
|
||
def write_to_report(self): | ||
pass | ||
|
||
|
||
def __call__(self, context): | ||
self.update_class_counts(context['class_names']) | ||
self.update_person_status(context['class_names']) | ||
frame = context['frame'] | ||
font = cv2.FONT_HERSHEY_SIMPLEX | ||
for point, name, color in zip(context['rec_points'], context['class_names'], context['class_colors']): | ||
|
||
cv2.rectangle(frame, (int(point['xmin'] * context['width']), int(point['ymin'] * context['height'])), | ||
(int(point['xmax'] * context['width']), int(point['ymax'] * context['height'])), color, 3) | ||
cv2.rectangle(frame, (int(point['xmin'] * context['width']), int(point['ymin'] * context['height'])), | ||
(int(point['xmin'] * context['width']) + len(name[0]) * 6, | ||
int(point['ymin'] * context['height']) - 10), color, -1, cv2.LINE_AA) | ||
cv2.putText(frame, name[0], (int(point['xmin'] * context['width']), int(point['ymin'] * context['height'])), font, | ||
0.3, (0, 0, 0), 1) | ||
|
||
cv2.rectangle(frame, (0, 0), (frame.shape[1], 50), (0, 0, 0), cv2.FILLED) | ||
cv2.putText(frame, ("Room occupied: {occupied}".format(occupied=self.occupancy)), (30, 30), | ||
font, 0.6, (255, 255, 255), 1) | ||
|
||
if len(list(self.class_counts.keys())) > 0: | ||
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) | ||
|
||
return frame | ||
|
Oops, something went wrong.