import json
import cv2
import requests
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.iai.v20200303 import iai_client, models
from tencentcloud.ft.v20200304 import ft_client
from tencentcloud.ft.v20200304 import models as ft_models
import numpy as np
import base64
import matplotlib.pyplot as plt
%matplotlib inline
import warnings
warnings.filterwarnings("ignore")
SecretId="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
SecretKey="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
img_path="./images/test2.jpg"
"""
https://cloud.tencent.com/document/product/867/44989
"""
try:
cred = credential.Credential(SecretId, SecretKey)
httpProfile = HttpProfile()
httpProfile.endpoint = "iai.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = iai_client.IaiClient(cred, "ap-beijing", clientProfile)
req = models.DetectFaceAttributesRequest()
with open(img_path,"rb") as file:
img=base64.b64encode(file.read())
params = {
"Image": str(img, encoding='utf-8'),
"NeedRotateDetection": 1,
"NeedFaceAttributes":1,
"NeedQualityDetection":1
}
req.from_json_string(json.dumps(params))
resp = client.DetectFaceAttributes(req).to_json_string()
resp=json.loads(resp)
print(resp)
except TencentCloudSDKException as err:
print(err)
{'ImageWidth': 300, 'ImageHeight': 300, 'FaceDetailInfos': [{'FaceRect': {'X': 73, 'Y': 78, 'Width': 135, 'Height': 176}, 'FaceDetailAttributesInfo': {'Age': 0, 'Beauty': 0, 'Emotion': {'Type': 0, 'Probability': 0}, 'Eye': {'Glass': {'Type': 0, 'Probability': 0}, 'EyeOpen': {'Type': 0, 'Probability': 0}, 'EyelidType': {'Type': 0, 'Probability': 0}, 'EyeSize': {'Type': 0, 'Probability': 0}}, 'Eyebrow': {'EyebrowDensity': {'Type': 0, 'Probability': 0}, 'EyebrowCurve': {'Type': 0, 'Probability': 0}, 'EyebrowLength': {'Type': 0, 'Probability': 0}}, 'Gender': {'Type': 0, 'Probability': 0}, 'Hair': {'Length': {'Type': 0, 'Probability': 0}, 'Bang': {'Type': 0, 'Probability': 0}, 'Color': {'Type': 0, 'Probability': 0}}, 'Hat': {'Style': {'Type': 0, 'Probability': 0}, 'Color': {'Type': 0, 'Probability': 0}}, 'HeadPose': {'Pitch': 0, 'Yaw': 0, 'Roll': 0}, 'Mask': {'Type': 0, 'Probability': 0}, 'Mouth': {'MouthOpen': {'Type': 0, 'Probability': 0}}, 'Moustache': {'Type': 0, 'Probability': 0}, 'Nose': {'Type': 0, 'Probability': 0},