Что я должен добавить, чтобы, когда система обнаруживает какой-то конкретный объект, она воспроизводила звуковой сигнал? - PullRequest
0 голосов
/ 28 сентября 2019

Я выполнил 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

myСистема автоматически обнаруживает опасное оружие, когда моя система обнаружила «Пистолет» или «Нож», она подаст сигнал безопасности с помощью звукового сигнала тревоги.

1 Ответ

0 голосов
/ 28 сентября 2019

Для 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&")
...