I saw a tutorial on the Internet , Call Tencent cloud face recognition api And modify the age api To simulate the faces of people of different ages
But most of the tutorial code is the same , It's estimated that the key to plagiarizing someone is that they can't execute
Jay Chou is just about to release a new album , A little change , Take a picture of Jay , Do an experiment
Here we go
1、 First, register an account on Tencent cloud , open API Key management page (https://console.cloud.tencent.com/cam/capi) Get SecretId and SecretKey, This string of values should be saved , The following script needs to use
2、 Then create resources , Cloud product entrance in the upper left corner , Choose in turn “ Face recognition ” and “ Face transformation ” Create resources , The current rule is that each account has 1000 A resource can be used , And resources are not immediately available after they are created , So this step should be done well first .
After creation , You can see the current resource status under the resource directory on the left
3、 Install Tencent cloud's SDK,
pip3 install tencentcloud-sdk-python
4、 The next step is the script , To realize face change, you need to call “ Face recognition ” and “ Face transformation ” Two api, The original plan was to combine the two scripts , I'll toss around when I have time .
The first is execution “ Face recognition ” step , Get face attribute values , Go straight to the code
import json
import base64
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
from tencentcloud.iai.v20200303 import models as models03 sid = "xxxxx"# Obtained in the first step SecretId
skey = "xxxxxx"# Obtained in the first step SecretKey
try:
filepath = 'test.jpg'# Pictures that need to change face , It's better to take a front view
file = open(filepath, "rb")
base64_data = base64.b64encode(file.read()) cred = credential.Credential(sid, skey)
httpProfile = HttpProfile()
httpProfile.endpoint = "iai.tencentcloudapi.com" clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = iai_client.IaiClient(cred, "ap-beijing", clientProfile) req = models03.DetectFaceAttributesRequest()
params = {
"MaxFaceNum":2,
"Action":"DetectFace",
"Version":"2018-03-01",
"Image": base64_data.decode()
}
req.from_json_string(json.dumps(params))
resp = client.DetectFaceAttributes(req) faceDetailInfos = resp.FaceDetailInfos
for faceDetailInfo in faceDetailInfos:
faceRect = faceDetailInfo.FaceRect
print(faceRect)
except TencentCloudSDKException as err:
print(err)
After execution , Get the return information , Record the... In the return value x、y equivalence
5, Execute the script to modify the age , Get the X、Y、Width Fill in the corresponding content of the script with the same value
import json
import base64
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.ft.v20200304 import ft_client, models
import time sid = "xxxx"# Obtained in the first step SecretId
skey = "xxxx"# Obtained in the first step SecretKey cred = credential.Credential(sid, skey)
httpProfile = HttpProfile()
httpProfile.endpoint = "ft.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = ft_client.FtClient(cred, "ap-beijing", clientProfile) filepath = 'test.jpg'
file = open(filepath, "rb")
base64_data = base64.b64encode(file.read()) req = models.ChangeAgePicRequest()
for age in range(10, 80):# Set the age here , such as (10,30) It means generating 10 To the age of 79 Year old pictures , altogether 71 Zhang
params = {
"Image": base64_data.decode(),
"AgeInfos": [{
"Age": age,
"FaceRect": {
"Y": 120, # Notice the first and second X、Y、Width、Height All values need to be modified
"X": 198,
"Width": 150,
"Height": 201
}},
{
"Age": age,
"FaceRect": {
"Y": 120,
"X": 198,
"Width": 150,
"Height": 201
}}],
"RspImgType":
"base64"
}
req.from_json_string(json.dumps(params))
resp = client.ChangeAgePic(req)
image_base64 = resp.ResultImage
image_data = base64.b64decode(image_base64)
file_path = '{}.png'.format(age)
with open(file_path, 'wb') as f:
f.write(image_data)
time.sleep(1)
Execute the script , The script will generate pictures of all ages under the same directory , Dangdangdang , Then you can play freely
Pay attention to the file directory , Of course , You can change the script , It can be stored differently , It's easy for me
Put... In the previous original picture , Pay tribute to !!!!
Catalog python Call Tencent cloud SMS interface Account registration python Encapsulating Tencent cloud SMS interface in python Call Tencent cloud SMS interface Account registration Register a Tencent cloud account on Tencent cloud official website , Pass real name authentication Then open the SMS service , Create SMS app ...
Recently, the project has used the identity identification interface of Tencent cloud , Don't talk much , Go straight to the code : private void IDCardVerification(HttpContext context) { string imgStr = ...
// Get the timestamp .net framework /* DateTime dt = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1 ...
One . Write it at the front Recently, the project needs to use the function of identifying words in pictures , Originally used Tesseract It's written here , But the effect is not very ideal . Then I searched the Internet OCR Interface , Just prepare to use Tencent cloud . Baidu OCR Try the interface . But this Tencent cloud ...
Because there are a large number of ECS managed by you , It needs to be replaced from time to time IP, Click... On the management console , It's a waste of time , So I thought of passing API The way it's called , Replace IP A series of actions , All integrated into Python In the code , Implement one line of command , complete IP ...
Preface : This blog is the first time for the author to use Baidu cloud api Face detection , The main content includes two parts , One is to obtain interfaces , Second, face detection with the help of interface . The author also has a preliminary understanding of this aspect , I also refer to miscellaneous blog posts , There may be errors and other defects in the content , ...
To do the project, you need to upload videos , Acquisition duration , Upload a lot of tutorials , Little information available , There is only one official request address . For a long time , They didn't say how to use the request address . Finally, it is found that Tencent cloud needs to be called SDK Official address :https://github.com/Q ...
Let's get straight to the point about the cause of the problem : call web api Double quotation marks are added in the request header , Missing double quotation marks in the request body . The object storage provided by Tencent cloud (COS)C# SDK Is based on .NET Framework use WebRequest ...
rely on : <!-- Tencent SMS relies on --> <dependency> <groupId>com.github.qcloudsms</groupId> <a ...
brief introduction Tencent location service provides basic punctuation capabilities for wechat applets . Drawing interface of lines and circles and other map components and position display . Map selection and other maps API Location service capability support , So that developers can freely implement their own wechat applet products . On this basis , Tencent location service ...
Two solutions : 1. Right click on the project ->Build Path->Add Libraries..->Server Runtime choice Apache Tomcat v8.0 2. Right click on the project ...
/* Variable operating ( Operators between two variables need to be separated by spaces , Otherwise, an error will be reported .)==,!= <,>,<=,>=+,-,*,/,% */ $width1:50px;$width2:100px; ...
0x00 Standard module Module : standardFull name : Standard moduleDescription : Basic commands (does not require ...
JSP(Java Server Pages) What is? JSP Java Server Pages(Java Server side page ) Use JSP:SP = HTML + Java Code + JSP Something of itself . perform J ...
Roadmap Motivation and Primal Problem Dual Problem Messages behind Soft-Margin SVM Model Selection S ...
1.vi /etc/apt/sources.list deb http://mirrors.aliyun.com/debian wheezy main contrib non-free deb-src ...
1. modify Installation directory web.config The file of . The general catalog is : C:\Program Files\GenerSoft\bscw_local\web.config To ensure security, I want to back up my files . 2 ...
I need a table to store all the working days. I dont like loop, so I tried sql. The following is the ...
One . How to choose PHP5.3 Of VC9 Version and VC6 edition VC6 Version is using Visual Studio 6 Compiler compiled , If your PHP Yes, it is Apache To set up , Then you choose VC6 edition . VC9 Version is using ...
ionic2: 1. Create project : ionic start MyIonic2Project tutorial --v2 ( download tutorial Template to initialize the project ) ionic start MyIonic ...