我应该添加些什么,以便当系统检测到某些特定对象时,它将发出警报声音?

问题描述 投票:0回答:1

我已经使用网络摄像头完成了对象检测API,系统已成功运行了检测到的对象,现在我想添加,当系统检测到某些特定对象时,它将播放差异警报声音

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)
    #if xxxxx:
    #    alert.play()
    #else:
    #    pass
    # 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

我的系统是自动检测危险武器,当我的系统检测到“枪”或“刀”时,它将通过声音警报来提醒安全。

tensorflow object-detection-api
1个回答
0
投票

对于Windows

import winsound winsound.PlaySound("sound_file.wav", FLAG)
或只是哔声

import winsound dur = 500 # as millisecond freq = 2000 # sound frequency winsound.Beep(freq, dur)

您可以检查文件https://docs.python.org/3.7/library/winsound.html

对于其他操作系统(Linux,Mac等)

import os os.system("sound_file.wav&")
© www.soinside.com 2019 - 2024. All rights reserved.