Tensorflow 1.12.0 Python 3.5.0 Windows 10
大家好,我已经基于tensorflows对象检测教程创建了自己的对象检测模型。我想在检测到对象时通过SMS通知(通过twilio之类的服务),但是我不想被同一对象类的每一帧都通知,而是希望在对象,即每次调用之间至少间隔5秒。我已经研究了线程和计时器,但是担心每次调用都会重新启动线程和计时器,并且想知道它们是否是通过对象检测API来完成此任务的更有效方法。我知道我可以打印通过
检测到的实际课程print [category_index.get(value) for index,value in enumerate(classes[0]) if scores[0,index] > 0.5]
在代码中
with detection_graph.as_default():
with tf.Session(graph=detection_graph) as sess:
while True:
ret, image_np = cap.read()
# Expand dimensions since the model expects images to have shape: [1, None, None, 3]
image_np_expanded = np.expand_dims(image_np, axis=0)
image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
# Each box represents a part of the image where a particular object was detected.
boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
# Each score represent how level of confidence for each of the objects.
# Score is shown on the result image, together with the class label.
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')
# Actual detection.
(boxes, scores, classes, num_detections) = sess.run(
[boxes, scores, classes, num_detections],
feed_dict={image_tensor: image_np_expanded})
# Visualization of the results of a detection.
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=8)
cv2.imshow('object detection', cv2.resize(image_np, (800,600)))
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
但是再一次,我不希望手机短信过多,也不希望我的脚本暂停。.如果可以给出任何建议,我将不胜感激。谢谢你们。
答案 0 :(得分:0)
而不是计时器,请尝试使用计数器对检测到它的帧进行计数。
每10帧左右重置一次计数器。