from utils.compreface_util import ComprefaceUtil
import asyncio
import time 
import json

image_path = "./haotian1.jpg"

with open(image_path, "rb") as f:
    image_bytes = f.read()  # 获取图片的字节流

# # 测试上传人脸图片
# print(asyncio.run(ComprefaceUtil.face_addition(image_path, '刘昊天_访客')))

# #-----------------------------------------测试人脸识别--------------------------------------------
# start_time = time.time()
# result = asyncio.run(
#         ComprefaceUtil.face_recognition(
#             image_bytes,
#             options={
#                 "limit": 0,
#                 "det_prob_threshold": 0.8,
#                 "prediction_count": 1,
#                 # 可选参数 age,gender,landmarks,calculator
#                 "face_plugins": "gender",
#                 "status": "true",
#             },
#         )
#     )
# print(result)
# with open("compreface_face_recognition.json", "w", encoding="utf-8") as f:
#     f.write(json.dumps(result, ensure_ascii=False, indent=4))

# print("spend time:", time.time() - start_time)

# #-----------------------------------------测试人脸识别end------------------------------------------

# -----------------------------------------测试人脸检测--------------------------------------------
start_time = time.time()
result = asyncio.run(
        ComprefaceUtil.face_detection(
            image_bytes,
            options={
                "limit": 0,
                "det_prob_threshold": 0.8,
                "prediction_count": 1,
                # 可选参数 age,gender,landmarks,calculator
                "face_plugins": "pose",
                "status": "false",
            }
        )
)
print(result)
with open("compreface_face_detection.json", "w", encoding="utf-8") as f:
    f.write(json.dumps(result, ensure_ascii=False, indent=4))

print("spend time:", time.time() - start_time)
# -----------------------------------------测试人脸检测end-----------------------------------------
