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 9, 2018
1 parent
deb5758
commit 7bc3ca8
Showing
9 changed files
with
73 additions
and
48 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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
tf_models/ | ||
*.csv | ||
*.csv | ||
*.mp4 | ||
__pycache__/ |
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
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,42 @@ | ||
import os | ||
import numpy as np | ||
from utils import label_map_util | ||
from utils.webcam import draw_boxes_and_labels | ||
|
||
|
||
CWD_PATH = os.getcwd() | ||
PATH_TO_LABELS = os.path.join(CWD_PATH, 'detection', 'data', 'mscoco_label_map.pbtxt') | ||
|
||
NUM_CLASSES = 90 | ||
# label map | ||
label_map = label_map_util.load_labelmap(PATH_TO_LABELS) | ||
categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, | ||
use_display_name=True) | ||
category_index = label_map_util.create_category_index(categories) | ||
|
||
# pass in image_np, returns | ||
def detect_objects(image_np, sess, detection_graph): | ||
|
||
image_np_expanded = np.expand_dims(image_np, axis=0) | ||
image_tensor = detection_graph.get_tensor_by_name('image_tensor:0') | ||
|
||
boxes = detection_graph.get_tensor_by_name('detection_boxes:0') | ||
|
||
scores = detection_graph.get_tensor_by_name('detection_scores:0') | ||
classes = detection_graph.get_tensor_by_name('detection_classes:0') | ||
num_detections = detection_graph.get_tensor_by_name('num_detections:0') | ||
|
||
# Do the detection/model prediction here | ||
(boxes, scores, classes, num_detections) = sess.run( | ||
[boxes, scores, classes, num_detections], | ||
feed_dict={image_tensor: image_np_expanded}) | ||
|
||
rect_points, class_names, class_colors = draw_boxes_and_labels( | ||
boxes=np.squeeze(boxes), | ||
classes=np.squeeze(classes).astype(np.int32), | ||
scores=np.squeeze(scores), | ||
category_index=category_index, | ||
min_score_thresh=.5 | ||
) | ||
|
||
return dict(rect_points=rect_points, class_names=class_names, class_colors=class_colors) |
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
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
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,19 @@ | ||
import cv2 | ||
|
||
class VideoWriter(object): | ||
|
||
def __init__(self, path, size): | ||
self.path = path | ||
self.size = size | ||
self.writer = cv2.VideoWriter(self.path, | ||
cv2.VideoWriter_fourcc('M','J','P','G'), | ||
20.0, self.size, True) | ||
|
||
def __call__(self, frame): | ||
self.writer.write(frame) | ||
|
||
def close(): | ||
self.writer.release() | ||
|
||
|
||
|