求助!人脸照片无法上传到人脸库
166******78 发布于2020-11 浏览:572 回复:2
0
收藏

有大佬帮我看看是哪里出问题了吗?

我是用python-opencv拍摄人脸图像然后上传至人脸库的,程序编译通过了,但是功能没有实现,照片并没有上传到人脸库中。

from aip import AipFace
import base64
import cv2
import os

 

APP_ID = '21177474'
API_KEY = '5GldK7WGlK2LtISFd7U4T95P'
SECRET_KEY = 'XwaOW2YRl8lA4lwUZREQ23d4RrzVlivFk'
client = AipFace(APP_ID, API_KEY, SECRET_KEY)

add_name = 'user'#要录入的人名


target_dir = './pic_dir/{}/'.format(add_name)
if os.path.exists(target_dir) is False:
os.makedirs(target_dir)


def generate():
face_cascade = cv2.CascadeClassifier('.\cascades\haarcascade_frontalface_default.xml')
face_cascade.load('D:\python37\Lib\site-packages\cv2\data/haarcascade_frontalface_default.xml')
#打开摄像头
camera = cv2.VideoCapture(0)
forword_count = 0
#正脸采集,一共20张图片
while (forword_count <= 1):
ret, frame = camera.read()
#转化为灰度图像,用来检测人脸
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray, 1.3, 8)

for (x, y, w, h) in faces:
#画出预测框
cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2)

f = cv2.resize(gray[y:y + h, x:x + w], (200, 200))
#保存录入的图片
cv2.imwrite('./pic_dir/{0}/{1}.png'.format(add_name, forword_count), f)
print(forword_count)
forword_count += 1
#展示图片
cv2.imshow("camera", frame)
#一秒钟24帧
if cv2.waitKey(1000 // 24) & 0xff == ord("q"):
break

camera.release()
cv2.destroyAllWindows()

 


def uplode():
filePath = './pic_dir/user/0.jpg'
with open(filePath, "rb+") as f:
# b64encode是编码
base64_data = base64.b64encode(f.read())

image = str(base64_data, 'utf-8')

imageType = "BASE64"

groupId = "add_1"

userId = add_name

""" 调用人脸注册 """
print(userId)
client.addUser(image, imageType, groupId, userId)
pass

if __name__ == "__main__":
generate()
uplode()

收藏
点赞
0
个赞
共2条回复 最后由166******78回复于2020-11
#3166******78回复于2020-11

我已经解决了,谢谢您

 

0
#2756665228回复于2020-11

每次入库到百度接口。接口返回的内容是什么呢?

 

0
TOP
切换版块