Call Tencent API to realize key point analysis of human body

1. Introduction of the author

Zhang Siyi, female, School of Electronic Information, Xi'an Polytechnic University, 2022 graduate student, Zhang Hongwei Artificial Intelligence Research Group
Research direction: machine vision and artificial intelligence
Email: [email protected]

Wang Zeyu, male, School of Electronic Information, Xi'an Polytechnic University, 2022 graduate student, Zhang Hongwei Artificial Intelligence Research Group
Research direction: machine vision and artificial intelligence
Email: [email protected]

2. Call Tencent API to realize key point analysis of human body

2.1 Introduction to API

1. API (Application Programming Interface, application programming interface) is some pre-defined functions, the purpose is to provide applications and developers with the ability to access a set of routines based on certain software or hardware without accessing source code, or understanding The details of the inner workings.
2. To put it more plainly, the code written by others, or the compiled program, which is provided to customers for use, is called API. Using a function, class, or object in someone else's code (or program) is called using an API.

Common third-party APIs:
The Twitter API: Allows displaying recent tweets, etc. on the website.
The Google Maps API: Allows a lot to do with maps on the web (this is interesting, it also drives Google Maps). Now it's a complete set of APIs capable of a wide range of tasks. Its capabilities have been witnessed by the Google Maps API Picker.
The Facebook suite of API: Allows many functions in the Facebook ecosystem to be applied to the app to benefit it. For example, it provides functions such as logging in with a Facebook account, accepting in-app payments, and pushing targeted advertising campaigns.
The YouTube API: Allows you to embed videos on Youtube into the website, and at the same time provides many functions such as searching Youtube, creating playlists, etc.
Tencent API: Through the cloud API, you can quickly operate cloud products with only a small amount of code. Quickly and easily call cloud API to manage Tencent Cloud resources. Cloud API provides API Explorer, Tencent Cloud command line tool TCCLI, SDK, cloud API platform and API Inspector tool.
Huawei API, Baidu API, etc.

insert image description here

2.2 Tencent API usage tools

insert image description here

2.4 Introduction to MPII Dataset

MPII (MPII Human Pose Dataset)
single/multiple human body key point detection dataset, MPII human pose dataset is a benchmark for human pose estimation, the dataset includes 25,000 labeled pictures of more than 40k people, these pictures are Extracted from YouTube video. Annotations for body part occlusion, 3D torso, and head orientation are also included in the test set. The coordinates of 16 key points and information about whether they are visible or not, with a sample size of 25K, is the main data set for single-person human key point detection. Labeling data format: use the struct format of mat, and the data useful for human key point detection are as follows: Pedestrian frame: use center and scale annotation, the human body scale is about 200 pixels in height, that is, 200 is divided.
MPII Human Pose Dataset Official Website: MPII Human Pose Database
insert image description here

3. Experimental procedure and results

3.1 Call Baidu API process

1. Enter Tencent Cloud to register and log in.
insert image description here
2. Enter the human body analysis interface and select human body key point analysis.
insert image description here
3. Enter the key point analysis interface, select and click Debug.
insert image description here
4. Obtain the source code and key.
insert image description here

3.2 Complete code

import json
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.bda.v20200324 import bda_client, models
import base64
img_dir = "/data/Users/zhangsy/myProject/datasets/API-Tencent/2.jpg"
with open(img_dir, 'rb') as f:
    base64_data = base64.b64encode(f.read())
    base64_code = base64_data.decode()

try:
    # 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
    # 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
    # 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
    cred = credential.Credential("AKID0udDbkkV3MbdR1MglcFgAUeZMyMWSCnB", "zoSs43nLflfLn5EBvRhiV9o4EIDwVrzt")
    # 实例化一个http选项,可选的,没有特殊需求可以跳过
    httpProfile = HttpProfile()
    httpProfile.endpoint = "bda.tencentcloudapi.com"

    # 实例化一个client选项,可选的,没有特殊需求可以跳过
    clientProfile = ClientProfile()
    clientProfile.httpProfile = httpProfile
    # 实例化要请求产品的client对象,clientProfile是可选的
    client = bda_client.BdaClient(cred, "ap-beijing", clientProfile)

    # 实例化一个请求对象,每个接口都会对应一个request对象
    req = models.DetectBodyJointsRequest()
    # params = {
    
    
    #     "Image": "1"
    # }
    req.Image = base64_code
    # req.from_json_string(json.dumps(params))

    # 返回的resp是一个DetectBodyJointsResponse的实例,与请求对象对应
    resp = client.DetectBodyJoints(req)
    # 输出json格式的字符串回包
    print(resp.to_json_string())

except TencentCloudSDKException as err:
    print(err)


3.3 Test results

3.3.1 Test result 1
insert image description here
insert image description here
3.3.2 Test result 2
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/m0_37758063/article/details/131075506