Tencent_人脸识别_人像变换

本文详细介绍了使用Python实现腾讯人脸识别库进行人像变换的步骤,包括人脸检测、关键点定位以及人像融合等核心技术,展示了如何通过编程实现有趣的视觉效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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, # 是否开启图片旋转识别支持。0为不开启,1为开启
        "NeedFaceAttributes":1, # 是否需要返回人脸属性信息(FaceAttributesInfo)
        "NeedQualityDetection":1 #是否开启质量检测。0 为关闭,1 为开启。默认为 0。
    }
    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},
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值