如果检测到物体,如何添加声音警报

发布于 2025-01-11 23:22:38 字数 1018 浏览 0 评论 0原文

嘿,我是 Python 新手,我的问题是,如果系统检测到游戏中的对象,我如何添加警报声音:)

我给了我搜索变量的对象:vision_Logo

# initialize the WindowCapture class
wincap = WindowCapture('Main Phone')
# initialize the Vision class
vision_Logo = Vision('Logo.jpg')


# HSV filter
hsv_filter = HsvFilter(15, 45, 190, 29, 170, 255, 85, 100, 0, 10)


while(True):

    # get an updated image of the game
    screenshot = wincap.get_screenshot()

    # pre-process the image
    processed_image = vision_Logo.apply_hsv_filter(screenshot, hsv_filter)

    # do object detection
    rectangles = vision_Logo.find(processed_image, 0.41)

    # draw the detection results onto the original image
    output_image = vision_Logo.draw_rectangles(screenshot, rectangles)


    # display the processed image
    cv.imshow('Matches', output_image)

    # press 'q' with the output window focused to exit.
    # waits 1 ms every loop to process key presses
    if cv.waitKey(1) == ord('q'):
        cv.destroyAllWindows()
        break

print('Done.')

Hey im new to Python and my question is how can i add an alert sound if the system detected the object in the game :)

I gave the object im searching for the variable: vision_Logo

# initialize the WindowCapture class
wincap = WindowCapture('Main Phone')
# initialize the Vision class
vision_Logo = Vision('Logo.jpg')


# HSV filter
hsv_filter = HsvFilter(15, 45, 190, 29, 170, 255, 85, 100, 0, 10)


while(True):

    # get an updated image of the game
    screenshot = wincap.get_screenshot()

    # pre-process the image
    processed_image = vision_Logo.apply_hsv_filter(screenshot, hsv_filter)

    # do object detection
    rectangles = vision_Logo.find(processed_image, 0.41)

    # draw the detection results onto the original image
    output_image = vision_Logo.draw_rectangles(screenshot, rectangles)


    # display the processed image
    cv.imshow('Matches', output_image)

    # press 'q' with the output window focused to exit.
    # waits 1 ms every loop to process key presses
    if cv.waitKey(1) == ord('q'):
        cv.destroyAllWindows()
        break

print('Done.')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱要勇敢去追 2025-01-18 23:22:38

您可以使用 Playsound 模块在 Python 中播放声音。使用pip安装playsound后,导入并使用playsound函数:

from playsound import playsound
.
.
.
.
playsound('soundfile.mp3')
print('Done.')

playsound文档:https://pypi.org/项目/播放声音/

You can use the playsound module to play sounds in Python. After installing playsound using pip, import it and use the playsound function:

from playsound import playsound
.
.
.
.
playsound('soundfile.mp3')
print('Done.')

playsound Documentation: https://pypi.org/project/playsound/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文