【 python手势识别项目 】百度云计算实现手势识别

调用百度云计算,实现python手势识别。
转载于10分钟用python实现手势识别

import os
import cv2
from aip import AipBodyAnalysis
from aip import AipSpeech
from threading import Thread
import time
import playsound

""" 你的 APPID AK SK """
APP_ID = '23678578'
API_KEY = 'XRdiguUTBroIEicHjNtxZCQ6'
SECRET_KEY =  'BOqhMisUWPFsMGMs3QDuDoskSQYYnRwV'
''' 调用'''

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()
  • 2
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MR_Promethus

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值