调用百度AI进行手势识别(Python)

import os
import cv2
from aip import AipBodyAnalysis
from threading import Thread
import base64

""" 你的 APPID AK SK """
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表示截取到一帧的图片
    '''
    ret, frame = capture.read()

   #只接受base64格式的图片   
    base64_data = base64.b64encode(frame)    
    gesture =  gesture_client.gesture(base64_data )   #AipBodyAnalysis内部函数
    print(gesture)
gesture_recognition()

猜你喜欢

转载自www.cnblogs.com/liubingzhe/p/11317258.html