图片靠右
This commit is contained in:
22
ImageProcessing/baidu.py
Normal file
22
ImageProcessing/baidu.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from aip import AipBodyAnalysis
|
||||
import config
|
||||
|
||||
|
||||
def face_center(filename, model):
|
||||
app_id = config.getInstance().conf.get("face", "appid")
|
||||
api_key = config.getInstance().conf.get("face", "key")
|
||||
app_secret = config.getInstance().conf.get("face", "secret")
|
||||
client = AipBodyAnalysis(app_id, api_key, app_secret)
|
||||
with open(filename, 'rb') as fp:
|
||||
img = fp.read()
|
||||
result = client.bodyAnalysis(img)
|
||||
if 'error_code' in result:
|
||||
raise result['error_msg']
|
||||
print('[+]Found person ' + str(result['person_num']))
|
||||
# 中心点取鼻子x坐标
|
||||
max = 0
|
||||
for person_info in result["person_info"]:
|
||||
x = int(person_info['body_parts']['nose']['x'])
|
||||
if x > max:
|
||||
max = x
|
||||
return max
|
||||
@@ -1,10 +1,15 @@
|
||||
import face_recognition
|
||||
|
||||
|
||||
def face_center(filename, model):
|
||||
image = face_recognition.load_image_file(filename)
|
||||
face_locations = face_recognition.face_locations(image, 0, model)
|
||||
if face_locations:
|
||||
top, right, bottom, left = face_locations[0]
|
||||
face_locations = face_recognition.face_locations(image, 1, model)
|
||||
print('[+]Found person ' + str(len(face_locations)))
|
||||
max = 0
|
||||
for face_location in face_locations:
|
||||
top, right, bottom, left = face_location
|
||||
# 中心点
|
||||
return int((right+left)/2)
|
||||
return 0
|
||||
x = int((right+left)/2)
|
||||
if x > max:
|
||||
max = x
|
||||
return max
|
||||
|
||||
Reference in New Issue
Block a user