如何在对象检测API中获取检测结果来做一些事情?

2024-03-28 15:08:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经用网络摄像头完成了目标检测。我可以知道,当系统检测到某些特定对象(枪/刀)时,系统将使用警报声音向用户发出警报

祝你今天愉快

我已经导入了pygame作为我的音响系统,但是当我将结果和pygame结合起来时,它就不起作用了

image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
detection_scores =detection_graph.get_tensor_by_name('detection_scores:0')
detection_class=detection_graph.get_tensor_by_name('detection_classes:0')
num_detections = detection_graph.get_tensor_by_name('num_detections:0')

video = cv2.VideoCapture(0)
ret = video.set(3,1280)
ret = video.set(4,720)
while(True):

# Acquire frame and expand frame dimensions to have shape: [1, None, None, 3]
# i.e. a single-column array, where each item in the column has the pixel RGB value
ret, frame = video.read()
frame_expanded = np.expand_dims(frame, axis=0)

# Perform the actual detection by running the model with the image as input
(boxes, scores, classes, num) = sess.run(
    [detection_boxes, detection_scores, detection_classes, num_detections],
    feed_dict={image_tensor: frame_expanded})

# Draw the results of the detection (aka 'visulaize the results')
vis_util.visualize_boxes_and_labels_on_image_array(
    frame,
    np.squeeze(boxes),
    np.squeeze(classes).astype(np.int32),
    np.squeeze(scores),
    category_index,
    use_normalized_coordinates=True,
    line_thickness=8,
    min_score_thresh=0.60)

# All the results have been drawn on the frame, so it's time to display it.
cv2.imshow('Object detector', frame)

# Press 'q' to quit
if cv2.waitKey(1) == ord('q'):
    break

Tags: thenameimagegetbyvideonpframe