失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > python手势识别_10分钟用python实现手势识别

python手势识别_10分钟用python实现手势识别

时间:2024-03-31 19:26:26

相关推荐

python手势识别_10分钟用python实现手势识别

import os

import cv2

from aip import AipBodyAnalysis

from aip import AipSpeech

from threading import Thread

import time

from playsound import playsound

""" 你的 APPID AK SK """

APP_ID = '********'

API_KEY = '********'

SECRET_KEY = '********'

''' 调用'''

hand={'One':'数字1','Five':'数字5','Fist':'拳头','Ok':'OK',

'Prayer':'祈祷','Congratulation':'作揖','Honour':'作别',

'Heart_single':'比心心','Thumb_up':'点赞','Thumb_down':'Diss',

'ILY':'我爱你','Palm_up':'掌心向上','Heart_1':'双手比心1',

'Heart_2':'双手比心2','Heart_3':'双手比心3','Two':'数字2',

'Three':'数字3','Four':'数字4','Six':'数字6','Seven':'数字7',

'Eight':'数字8','Nine':'数字9','Rock':'Rock','Insult':'竖中指','Face':'脸'}

#语音合成

client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

#手势识别

gesture_client = AipBodyAnalysis(APP_ID, API_KEY, SECRET_KEY)

capture = cv2.VideoCapture(0)#0为默认摄像头

def camera():

while True:

#获得图片

ret, frame = capture.read()

# cv2.imshow(窗口名称, 窗口显示的图像)

#显示图片

cv2.imshow('frame', frame)

if cv2.waitKey(1) == ord('q'):

break

Thread(target=camera).start()#引入线程防止在识别的时候卡死

def gesture_recognition():

#第一个参数ret 为True 或者False,代表有没有读取到图片

#第二个参数frame表示截取到一帧的图片

while True:

try:

ret, frame = capture.read()

#图片格式转换

image = cv2.imencode('.jpg',frame)[1]

gesture = gesture_client.gesture(image) #AipBodyAnalysis内部函数

words = gesture['result'][0]['classname']

voice(hand[words])

print(hand[words])

except:

voice('识别失败')

if cv2.waitKey(1) == ord('q'):

break

def voice(words):

#语音函数

result = client.synthesis(words, 'zh', 1, {

'vol': 5,

})

if not isinstance(result, dict):

with open('./res.mp3', 'wb') as f:

f.write(result)

f.close()

playsound('./res.mp3')

gesture_recognition()

如果觉得《python手势识别_10分钟用python实现手势识别》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。