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()