我目前正在youtube上学习Tensorflow对象检测的完整课程。Find the video here.
我目前正在将“从网络摄像头检测”的代码应用到一个视频中,现在我试图在一个excel或csv文件中总结检测结果。详细地说,我需要一个文件,其中包含每个检测结果、位置以及发生时间。
我已经找到了一些关于如何打印出边界框坐标或detect.py在使用YOLO时使用www.example.com函数的例子,但我仍然没有找到任何解决我的具体问题的想法。
这是我用来检测视频或网络摄像头的代码。在本例中,我从网络摄像头进行检测:
cap = cv2.VideoCapture(0)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
while cap.isOpened():
ret, frame = cap.read()
image_np = np.array(frame)
input_tensor = tf.convert_to_tensor(np.expand_dims(image_np, 0), dtype=tf.float32)
detections = detect_fn(input_tensor)
num_detections = int(detections.pop('num_detections'))
detections = {key: value[0, :num_detections].numpy()
for key, value in detections.items()}
detections['num_detections'] = num_detections
# detection_classes should be ints.
detections['detection_classes'] = detections['detection_classes'].astype(np.int64)
label_id_offset = 1
image_np_with_detections = image_np.copy()
viz_utils.visualize_boxes_and_labels_on_image_array(
image_np_with_detections,
detections['detection_boxes'],
detections['detection_classes']+label_id_offset,
detections['detection_scores'],
category_index,
use_normalized_coordinates=True,
max_boxes_to_draw=1,
min_score_thresh=.75,
agnostic_mode=False)
cv2.imshow('object detection', cv2.resize(image_np_with_detections, (800, 600)))
if cv2.waitKey(10) & 0xFF == ord('q'):
cap.release()
cv2.destroyAllWindows()
break
非常感谢您的帮助!〈3
1条答案
按热度按时间anauzrmj1#
tf.image.draw_bounding_boxes( )
输入是tf.constant(),您可以直接保存到目标文件。示例:在工作功能上,您可以对图像显示进行注解,并将其保存为Pandas。喜欢连接、积累数据、创建摘要。
输出量: