当前位置:网站首页>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
边栏推荐
- Static interface method calls are not supported at language level '5'
- Zero copy technology
- Oracle kills the executing SQL
- Test the time required for Oracle library to create an index with 7 million data in a common way
- Oracle job scheduled task usage details
- QT calling external program
- SAP ui5 application development tutorial 72 - animation effect setting of SAP ui5 page routing
- [tensorflow] sharing mechanism
- Lenovo Saver y9000x 2020
- Campus takeout system - "nongzhibang" wechat native cloud development applet
猜你喜欢

SAP ui5 application development tutorial 72 - animation effect setting of SAP ui5 page routing

Double pointer instrument panel reading (I)

JUC interview questions about synchronized, ThreadLocal, thread pool and atomic atomic classes

Common types and basic usage of input plug-in of logstash data processing service
![MySQL [acid + isolation level + redo log + undo log]](/img/52/7e04aeeb881c8c000cc9de82032e97.png)
MySQL [acid + isolation level + redo log + undo log]
![[point cloud series] full revolutionary geometric features](/img/00/701ba2f8130948329404dc4629ca46.png)
[point cloud series] full revolutionary geometric features

【视频】线性回归中的贝叶斯推断与R语言预测工人工资数据|数据分享

Set Jianyun x Feishu Shennuo to help the enterprise operation Department realize office automation

面试官给我挖坑:单台服务器并发TCP连接数到底可以有多少 ?
![[indicators] precision, recall](/img/40/8fbd9b83bd2fe8ac13ffeb1834b002.png)
[indicators] precision, recall
随机推荐
Static interface method calls are not supported at language level '5'
Oracle index status query and index reconstruction
Remove the status bar
What does the SQL name mean
浅谈js正则之test方法bug篇
爱可可AI前沿推介 (4.23)
Personal learning related
Part 3: docker installing MySQL container (custom port)
Oracle database combines the query result sets of multiple columns into one row
JS compares different elements in two arrays
Window analysis function last_ VALUE,FIRST_ VALUE,lag,lead
What do the raddr and rport in webrtc ice candidate mean?
面试官给我挖坑:URI中的 “//” 有什么用?
Generate 32-bit UUID in Oracle
GDB的使用
NPM err code 500 solution
联想拯救者Y9000X 2020
GDB的使用
[point cloud series] summary of papers related to implicit expression of point cloud
[point cloud series] learning representations and generative models for 3D point clouds