树莓派python手势识别控制_python树莓派相机实现手势识别源码调用的百度API_新锐下载...

# 使用python3运行

# 作者:xuehu96

# 编写时间 2019年8月11日

from picamera import PiCamera,Color

import time

import demjson

from pygame import mixer

from aip import AipBodyAnalysis

from aip import AipSpeech

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':'脸'}

# 下面的key要换成自己的

""" 人体分析 APPID AK SK """

APP_ID = '*******'

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

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

""" 语音技术 APPID AK SK """

SpeechAPP_ID = '*******'

SpeechAPI_KEY ='*******************'

SpeechSECRET_KEY = '*******************'

camera = PiCamera()

client = AipBodyAnalysis(APP_ID, API_KEY, SECRET_KEY)

Speechclient = AipSpeech(SpeechAPP_ID, SpeechAPI_KEY, SpeechSECRET_KEY)

'''cam config'''

camera.resolution = (1280, 720)

camera.annotate_text = "xuehu96 !" #图片上加水印

#camera.annotate_background = Color('blue')

camera.annotate_text_size = 20

camera.annotate_foreground = Color('white')

camera.brightness = 55

""" 读取图片 """

def get_file_content(filePath):

with open(filePath, 'rb') as fp:

return fp.read()

mixer.init()

while True:

"""1.拍照 """

camera.start_preview()

time.sleep(2)

mixer.music.stop()

camera.capture('./image.jpg')

camera.stop_preview()

image = get_file_content('./image.jpg')

""" 2.调用手势识别 """

raw = str(client.gesture(image))

text = demjson.decode(raw)

try:

res = text['result'][0]['classname']

except:

print('识别结果:什么也没识别到哦~' )

else:

print('识别结果:' + hand[res])

""" 3.调用文字转语音"""

content = hand[res]

result = Speechclient.synthesis(content, 'zh', 1, {'spd': 2, 'vol': 6, 'per': 1})

#print(result)

if not isinstance(result, dict):

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

f.write(result)

mixer.music.load('./res.mp3')

mixer.music.play()

#            time.sleep(3)

#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值