Vehicle-Detection-and-Tracking
Vehicle-Detection-and-Tracking copied to clipboard
detecting of persons not working
Hello, I changed the v to 1 but it doesn't detect persons
@AndreAhmed , it is possible. SSD-Moblienet Detector can fail to detect objects in some cases. You can considering using other types of detectors.
@AndreAhmed , also change idx_vec = [i for i, v in enumerate(cls) if ((v==3) and (scores[i]>0.3))] to idx_vec = [i for i, v in enumerate(cls) if ((v==1) and (scores[i]>0.0))] to see if you can detect any person (basically lower the detection threshold to 0). Hope this would work for you to some degree.
@kcg2015 Thanks for your fast reply.
It doesn't work at all with that line of code, and there dozen of bounding box out there.
You can test that video https://github.com/ahmetozlu/tensorflow_object_counting_api/blob/master/input_images_and_videos/pedestrian_survaillance.mp4
@AndreAhmed , you probably have to try different TF detectors.
I have tested on this video and it works. i changed nothing except the directory for weight file and video file. look the detector module here.
import numpy as np
import tensorflow as tf
import os
import cv2
from matplotlib import pyplot as plt
cwd = os.path.dirname(os.path.realpath(file))
class Detector(object):
def init(self):
self.car_boxes = []
os.chdir(cwd)
detect_model_name = "/ssd_mobilenet_v1_coco_11_06_2017"
PATH_TO_CKPT = detect_model_name + '/frozen_inference_graph.pb'
self.detection_graph = tf.Graph()
config = tf.ConfigProto()
with self.detection_graph.as_default():
od_graph_def = tf.GraphDef()
with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
serialized_graph = fid.read()
od_graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(od_graph_def, name='')
self.sess = tf.Session(graph=self.detection_graph, config=config)
self.image_tensor = self.detection_graph.get_tensor_by_name('image_tensor:0')
self.boxes = self.detection_graph.get_tensor_by_name('detection_boxes:0')
self.scores =self.detection_graph.get_tensor_by_name('detection_scores:0')
self.classes = self.detection_graph.get_tensor_by_name('detection_classes:0')
self.num_detections =self.detection_graph.get_tensor_by_name('num_detections:0')
def box_normal_to_pixel(self, box, dim):
height, width = dim[0], dim[1]
box_pixel = [int(box[0]*height), int(box[1]*width), int(box[2]*height), int(box[3]*width)]
return np.array(box_pixel)
def get_points(self, image, visual=False):
self.car_boxes = []
category_index={1: {'id': 1, 'name': u'person'}}
with self.detection_graph.as_default():
image_expanded = np.expand_dims(image, axis=0)
(boxes, scores, classes, num_detections) = self.sess.run(
[self.boxes, self.scores, self.classes, self.num_detections],
feed_dict={self.image_tensor: image_expanded})
if visual == True:
vis_util.visualize_boxes_and_labels_on_image_array(
image,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,min_score_thresh=.4,
line_thickness=3)
plt.figure(figsize=(9,6))
plt.imshow(image)
plt.show()
boxes=np.squeeze(boxes)
classes =np.squeeze(classes)
scores = np.squeeze(scores)
cls = classes.tolist()
idx_vec = [i for i, v in enumerate(cls) if ((v==1) and (scores[i]>0.45))]
if len(idx_vec) ==0:
print('no detection!')
else:
tmp_car_boxes=[]
for idx in idx_vec:
dim = image.shape[0:2]
box = self.box_normal_to_pixel(boxes[idx], dim)
left, top, right, bottom = box[1], box[0], box[3], box[2]
box= [left, top, right, bottom]
tmp_car_boxes.append(box)
cv2.rectangle(image, (left, top), (right, bottom), (250,20,250), 4)
self.car_boxes = tmp_car_boxes
return self.car_boxes