如果检测到物体,如何添加声音警报
嘿,我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 Playsound 模块在 Python 中播放声音。使用pip安装playsound后,导入并使用playsound函数:
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:
playsound Documentation: https://pypi.org/project/playsound/