# coding=utf-8
import cv2
import numpy as np
from aip import AipFace
import base64
from PIL import Image
# APPID AK SK
APP_ID = '14731743'
API_KEY = '2ijIIDelus1qNlQfrokG2dhG'
SECRET_KEY = '5f9K7AkUpmebr0yB9y0g5GscbjbcsLdx'
client = AipFace(APP_ID, API_KEY, SECRET_KEY)
cap = cv2.VideoCapture(0)
cv2.namedWindow('MyWindow')
fps = cap.get(cv2.CAP_PROP_FPS)
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video = cv2.VideoWriter("D:/avi/aaa.avi", fourcc, 5, size)
print(cap.isOpened())
count=0
while count > -1:
ret,img = cap.read()
imgBinary=img.tobytes()
image = base64.b64encode(imgBinary)
imageType = "BASE64"
image64 = str(image,'utf-8')
result=client.detect(image64, "BASE64", None)
print(result)
location=result['result']['face_list'][0]['location']
left_top=(int(location['left']),int(location['top']))
right_bottom=(int(left_top[0]+location['width']),int(left_top[1]+location['height']))
print(left_top)
cv2.rectangle(img,left_top,right_bottom,(0,0,255),2)
video.write(img)
cv2.imshow('video',img)
key=cv2.waitKey(1)
if key==ord('q'):
break
video.release()
cap.release()
cv2.destroyAllWindows()
错误参数
{'error_code': 222203, 'error_msg': 'image check fail', 'log_id': 1345050722858694051, 'timestamp': 1542285869, 'cached': 0, 'result': None}
Traceback (most recent call last):
File "C:\Users\Administrator\eclipse-workspace\AI\AI.py", line 38, in
location=result['result']['face_list'][0]['location']
TypeError: 'NoneType' object is not subscriptable
首先提醒下 APPID AK SK这些参数不要泄漏出来哈
错误是图像检查失败,就说获取的图像数据是不正确的,
最后异常的类型,原因是变量使用了系统内置的关键字list。好好检查一下吧