当前位置:网站首页>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
边栏推荐
- Interval query through rownum
- TCP reset Gongji principle and actual combat reproduction
- Troubleshooting of expdp export error when Oracle table has logical bad blocks
- PG SQL intercepts the string to the specified character position
- [indicators] precision, recall
- The query did not generate a result set exception resolution when the dolphin scheduler schedules the SQL task to create a table
- MySQL and PgSQL time related operations
- Processing of ASM network not automatically started in 19C
- Solution: you have 18 unapplied migration (s) Your project may not work properly until you apply
- Common analog keys of ADB shell: keycode
猜你喜欢
MySQL index [data structure + index creation principle]
Information: 2021 / 9 / 29 10:01 - build completed with 1 error and 0 warnings in 11S 30ms error exception handling
Unified task distribution scheduling execution framework
MySQL [SQL performance analysis + SQL tuning]
Apache Atlas Compilation and installation records
Detailed explanation of redis (Basic + data type + transaction + persistence + publish and subscribe + master-slave replication + sentinel + cache penetration, breakdown and avalanche)
AI21 Labs | Standing on the Shoulders of Giant Frozen Language Models(站在巨大的冷冻语言模型的肩膀上)
Ai21 labs | standing on the shoulders of giant frozen language models
Campus takeout system - "nongzhibang" wechat native cloud development applet
Handling of high usage of Oracle undo
随机推荐
面试官给我挖坑:单台服务器并发TCP连接数到底可以有多少 ?
Parameter comparison of several e-book readers
Window function row commonly used for fusion and de duplication_ number
解决tp6下载报错Could not find package topthink/think with stability stable.
Using open to open a file in JNI returns a - 1 problem
Influence of openssh version on SSH mutual trust creation in RAC environment
What does the SQL name mean
TERSUS笔记员工信息516-Mysql查询(2个字段的时间段唯一性判断)
Django::Did you install mysqlclient?
为什么从事云原生开发需要学习容器技术
这个SQL语名是什么意思
GDB的使用
Oracle creates tablespaces and modifies user default tablespaces
Lenovo Saver y9000x 2020
ACFs file system creation, expansion, reduction and other configuration steps
Oracle database combines the query result sets of multiple columns into one row
Test the time required for Oracle library to create an index with 7 million data in a common way
Bottomsheetdialogfragment + viewpager + fragment + recyclerview sliding problem
Oracle RAC database instance startup exception analysis IPC send timeout
软考系统集成项目管理工程师全真模拟题(含答案、解析)