当前位置:网站首页>Using Baidu Intelligent Cloud face detection interface to achieve photo quality detection
Using Baidu Intelligent Cloud face detection interface to achieve photo quality detection
2022-04-23 13:45:00 【Du Xiaorui】
First create baidu account , Log in to Baidu AI Open platform , Enter the Developer Center , Access control , Select face recognition in products and services . Then create an application .
Created successfully API Key and Secret Key
Next, use the just obtained API Key and Secret Key obtain access_token.
To the authorized service address https://aip.baidubce.com/oauth/2.0/token Send a request ( Recommended POST), And in URL With the following parameters :
- grant_type: Necessary parameters , Fixed for client_credentials;
- client_id: Necessary parameters , Applied API Key;
- client_secret: Necessary parameters , Applied Secret Key;
Use postman Simulation request received access_token, as follows :
Test interface
Face detection interface
Ability introduction
- Face detection : Detect the face in the picture and mark the location information .
- Face key points : Show the key information of face , And 150 Key information .
- Face attribute value : Display face attribute information , Such age 、 Gender, etc .
- Face quality information : Return the occlusion of all parts of the face 、 light 、 Fuzzy 、 Completeness 、 Confidence, etc .
Call interface
stay postman Call interface in ,url Add parameters in access_token, The value is the one you just applied for token. Set up Header in Content-Type Parameter is application/json. And then in body Add parameters in image and image_type, Represents picture information and picture type respectively , As shown in the figure below :
Here, due to not buying all the returned error messages .
python call
After receiving Baidu's free resources, try again .
Use python Call the face detection interface to detect the quality of face photos .
Use the first three indicators in the interface document to evaluate the photo quality , If all the above three conditions are met, the photo is considered qualified .
Next use python To achieve :
# encoding:utf-8
import requests
import base64
import os
import json
''' Face detection and attribute analysis '''
# obtain access_token
# client_id Obtained for the official website AK, client_secret Obtained for the official website SK
# host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=【】&client_secret=【】'
# response = requests.get(host)
# if response:
# print(response.json())
# api Address :https://cloud.baidu.com/doc/FACE/s/yk37c1u4t?_=1628489078955
""" occlusion: left_eye : 0.6, # The threshold of occlusion of the left eye right_eye : 0.6, # Right eye occlusion threshold nose : 0.7, # The threshold at which the nose is obscured mouth : 0.7, # The threshold of mouth occlusion left_cheek : 0.8, # The threshold of occlusion of the left cheek right_cheek : 0.8, # The threshold of occlusion of the right cheek chin_contour : 0.6, # Jaw occlusion threshold blur: Less than 0.7 illumination: Greater than 40 """
# Check whether a picture is qualified
def is_ok(img):
request_url = "https://aip.baidubce.com/rest/2.0/face/v3/detect"
params = {
"image":img, "image_type":"BASE64", "face_field":"faceshape,facetype,age,quality,angle"}
access_token = ' You got it yourself from the official website access_token'
request_url = request_url + "?access_token=" + access_token
headers = {
'content-type': 'application/json'}
response = requests.post(request_url, data=params, headers=headers)
# Because free resources have throughput limitations , Therefore, if the throughput is exceeded, an error will be reported , Output the error here . Of course, you can also sleep every time the program runs 1 second , So it won't exceed qps 了 .
if response.json()['error_code'] != 0:
print(response.json()['error_msg'])
return False
if response:
res = response.json()['result']
else:
print(' No response ')
res = res['face_list'][0]
occlusion = res['quality']['occlusion']
left_eye = occlusion['left_eye']
right_eye = occlusion['right_eye']
nose = occlusion['nose']
mouth = occlusion['mouth']
left_cheek = occlusion['left_cheek']
right_cheek = occlusion['right_cheek']
chin_contour = occlusion['chin_contour']
blur = res['quality']['blur']
illumination = res['quality']['illumination']
if left_eye < 0.6 and right_eye < 0.6 and nose < 0.7 and mouth < 0.7 and left_cheek < 0.8 and right_cheek < 0.8 and chin_contour < 0.6 and blur < 0.7 and illumination > 40:
return True
else:
return False
if __name__=='__main__':
path = ' The path of the folder where the photos are stored '
files = os.listdir(path)
for file in files:
f = open(path + '/' + file, 'rb')
img = base64.b64encode(f.read())
if is_ok(img):
print(' qualified ')
else:
print(' unqualified ')
Download some pictures from the Internet to test , As shown in the following nine pictures :
Two runs , Take a look at the results :
版权声明
本文为[Du Xiaorui]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230556584889.html
边栏推荐
- Using open to open a file in JNI returns a - 1 problem
- 交叉碳市场和 Web3 以实现再生变革
- Detailed explanation of ADB shell top command
- Ora-600 encountered in Oracle environment [qkacon: fjswrwo]
- Technologie zéro copie
- Storage scheme of video viewing records of users in station B
- Oracle and MySQL batch query all table names and table name comments under users
- Logstash数据处理服务的输入插件Input常见类型以及基本使用
- Apache seatunnel 2.1.0 deployment and stepping on the pit
- Remove the status bar
猜你喜欢
Isparta is a tool that generates webp, GIF and apng from PNG and supports the transformation of webp, GIF and apng
Special window function rank, deny_ rank, row_ number
SAP ui5 application development tutorial 72 - animation effect setting of SAP ui5 page routing
Android clear app cache
Detailed explanation of redis (Basic + data type + transaction + persistence + publish and subscribe + master-slave replication + sentinel + cache penetration, breakdown and avalanche)
Exemple de méthode de réalisation de l'action d'usinage à point fixe basée sur l'interruption de déclenchement du compteur à grande vitesse ob40 pendant le voyage de tia Expo
Dolphin scheduler integrates Flink task pit records
[point cloud series] learning representations and generative models for 3D point clouds
Plato farm, a top-level metauniverse game, has made frequent positive moves recently
SAP UI5 应用开发教程之七十二 - SAP UI5 页面路由的动画效果设置试读版
随机推荐
Ora-16047 of a DG environment: dgid mismatch between destination setting and target database troubleshooting and listening vncr features
TIA博途中基於高速計數器觸發中斷OB40實現定點加工動作的具體方法示例
顶级元宇宙游戏Plato Farm,近期动作不断利好频频
Oracle kills the executing SQL
Ora-600 encountered in Oracle environment [qkacon: fjswrwo]
Lenovo Saver y9000x 2020
聯想拯救者Y9000X 2020
10g database cannot be started when using large memory host
Isparta is a tool that generates webp, GIF and apng from PNG and supports the transformation of webp, GIF and apng
联想拯救者Y9000X 2020
Two ways to deal with conflicting data in MySQL and PG Libraries
Oracle lock table query and unlocking method
Influence of openssh version on SSH mutual trust creation in RAC environment
Plato farm, a top-level metauniverse game, has made frequent positive moves recently
Dolphin scheduler source package Src tar. GZ decompression problem
Analysis of cluster component gpnp failed to start successfully in RAC environment
The interviewer dug a hole for me: what's the use of "/ /" in URI?
Oracle job scheduled task usage details
kettle庖丁解牛第16篇之输入组件周边讲解
Three characteristics of volatile keyword [data visibility, prohibition of instruction rearrangement and no guarantee of operation atomicity]