实现向分组中添加单个人脸服务
This commit is contained in:
parent
ffeee70a5b
commit
55b9a5cbfb
@ -168,7 +168,7 @@ async def get_all_employee_pictures(pageNo=1, pageSize=500):
|
||||
# 获取图片
|
||||
try:
|
||||
await HaikangUtil.get_person_picture(employee["serverIndexCode"], employee["picUri"], f"./employee/face_images/{employee['personName']}.jpg")
|
||||
await asyncio.sleep(1)
|
||||
await asyncio.sleep(0.5)
|
||||
except Exception as e:
|
||||
print(e, employee["visitorId"])
|
||||
|
||||
@ -184,6 +184,26 @@ async def face_group_addition_service(name, description):
|
||||
with open("face_group_addition_service.json", "w", encoding="utf-8") as f:
|
||||
f.write(json.dumps(result[1]))
|
||||
|
||||
# 向分组中添加单个人脸
|
||||
async def face_single_addition_service(faceGroupIndexCode, image_path, name):
|
||||
|
||||
with open(image_path, 'rb') as f:
|
||||
image_data = f.read()
|
||||
|
||||
encoded_image = base64.b64encode(image_data).decode('utf-8')
|
||||
|
||||
faceInfo = {
|
||||
"name": name,
|
||||
}
|
||||
facePic = {
|
||||
"picBinaryData": encoded_image,
|
||||
}
|
||||
|
||||
|
||||
result = await HaikangUtil.face_single_addition(faceGroupIndexCode, faceInfo, facePic)
|
||||
print(result)
|
||||
with open("face_single_addition_service.json", "w", encoding="utf-8") as f:
|
||||
f.write(json.dumps(result[1]))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
@ -206,5 +226,17 @@ if __name__ == '__main__':
|
||||
# asyncio.run(query_visitor_record_pictures_service("80890167-b8d4-4e33-af35-94db87c90816"
|
||||
# , "/pic?0de900=71f0ip-4eo881-342*fo1=9=8522*4l5373169147*1t1=0*0ps==418b*=6127*38da35a12-8338cd-9*l168od0f1f1=002"))
|
||||
#asyncio.run(door_online_status_service(["d4a610b6554d4544bc35dd3138f128b0"]))
|
||||
asyncio.run(get_all_visitor_pictures())
|
||||
# asyncio.run(get_all_visitor_pictures())
|
||||
|
||||
# 测试获取访客预约记录图片
|
||||
asyncio.run(get_all_employee_pictures())
|
||||
|
||||
# 测试获取员工图片
|
||||
asyncio.run(get_all_employee_pictures())
|
||||
|
||||
# 添加单个人脸分组
|
||||
asyncio.run(face_group_addition_service("访客", "访客分组"))
|
||||
|
||||
# 向分组中添加单个人脸
|
||||
asyncio.run(face_single_addition_service("d4a610b6554d4544bc35dd3138f128b0", "./a7b3c794281902041c9b823df7667ce7.jpg", "测试"))
|
||||
|
||||
|
||||
@ -40,6 +40,8 @@ class HaiKangSettings:
|
||||
|
||||
HAIKANG_FACE_GROUP_ADDITION = '/api/frs/v1/face/group/single/addition'
|
||||
|
||||
HAIKANG_FACE_SIGLE_ADDITION = '/api/frs/v1/face/single/addition'
|
||||
|
||||
HAIKANG_FACE_SAVE_PATH = "./face_images"
|
||||
|
||||
|
||||
|
||||
@ -558,4 +558,23 @@ class HaikangUtil:
|
||||
if back["code"] == "0":
|
||||
return [True, back["data"]]
|
||||
else:
|
||||
return [False, back["code"], back["msg"]]
|
||||
return [False, back["code"], back["msg"]]
|
||||
|
||||
# 向分组中单个添加人脸图片
|
||||
@classmethod
|
||||
async def face_single_addition(cls, faceGroupIndexCode: str, faceInfo: dict, facePic: dict):
|
||||
url = f"{HaiKangConfig.HAIKANG_URL}:{HaiKangConfig.HAIKANG_PORT}/artemis{HaiKangConfig.HAIKANG_FACE_SIGLE_ADDITION}"
|
||||
body_dict = {
|
||||
"faceGroupIndexCode": faceGroupIndexCode,
|
||||
"faceInfo": faceInfo,
|
||||
"facePic": facePic,
|
||||
}
|
||||
body_json = json.dumps(body_dict, separators=(",", ":"))
|
||||
headers = cls.build_signed_headers(
|
||||
"POST", url, body_json, HaiKangConfig.HAIKANG_AK, HaiKangConfig.HAIKANG_SK
|
||||
)
|
||||
back = await cls.send_request("POST", url, headers, body_json)
|
||||
if back["code"] == "0":
|
||||
return [True, back["data"]]
|
||||
else:
|
||||
return [False, back["code"], back["msg"]]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user