101 lines
3.1 KiB
Python
101 lines
3.1 KiB
Python
import requests
|
||
import json
|
||
import datetime
|
||
|
||
def group_get_subjects(faces_data):
|
||
grouped_faces = {}
|
||
for face in faces_data['faces']:
|
||
subject = face['subject']
|
||
image_id = face['image_id']
|
||
if subject in grouped_faces:
|
||
grouped_faces[subject].append(image_id)
|
||
else:
|
||
grouped_faces[subject] = [image_id]
|
||
return grouped_faces
|
||
|
||
|
||
def filter_images_by_subject(data, subject):
|
||
# 初始化一个空列表来存储匹配的image_id
|
||
image_ids = []
|
||
|
||
# 遍历data中的faces列表
|
||
for face in data['faces']:
|
||
# 检查face字典中的'subject'键是否与传入的subject相匹配
|
||
if face['subject'] == subject:
|
||
# 如果匹配,将'image_id'添加到列表中
|
||
image_ids.append(face['image_id'])
|
||
# 返回包含所有匹配image_id的列表
|
||
return image_ids
|
||
|
||
|
||
# 该方法最后的返回结果是 打卡的人或者是陌生人
|
||
def getMaxSimilaritySubject(recognition_face_data):
|
||
first_result = recognition_face_data['result'][0]
|
||
# 从first_result中获取Box的probability
|
||
box_probability = first_result['box']['probability']
|
||
# 先判断是否存在人脸
|
||
if box_probability > 0.9:
|
||
recognition_subject_list = first_result['subjects']
|
||
# TODO 此处判断最为相似的subject,如果recognition_subject 低于阈值 直接返回陌生人
|
||
recognition_subject = recognition_subject_list[0]
|
||
|
||
|
||
# TODO postMsg 发送请求
|
||
# 1. 判断当前姓名,是否已经打卡过,若打卡过则不处理
|
||
# 2. minio保存,发送请求
|
||
def postMsg(recognition_name,temp_path,clock_in_dict) :
|
||
# 判断当前 recognition_name 之前是否已经在打卡了
|
||
# 若打卡则直接返回
|
||
if recognition_name in clock_in_dict :
|
||
return
|
||
|
||
# TODO
|
||
# 1. 保存minio
|
||
# 2. 发送请求
|
||
send_post_request()
|
||
return
|
||
|
||
def send_post_request(url, token, msg, picUrl, videoUrl):
|
||
payload = {
|
||
"channelNo": 'ip',
|
||
"alarmContent": msg,
|
||
"alarmTime": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||
"picInfo": [
|
||
{"url": picUrl}
|
||
],
|
||
"videoInfo": [
|
||
{"url": videoUrl}
|
||
]
|
||
}
|
||
headers = {
|
||
'X-Access-Token': token,
|
||
'Content-Type': 'application/json'
|
||
}
|
||
response = requests.post(url, headers=headers, data=json.dumps(payload))
|
||
print(response)
|
||
|
||
|
||
def getFacelist(data):
|
||
# 解析JSON数据
|
||
parsed_data = json.loads(json.dumps(data))
|
||
|
||
# 提取faces中的数据
|
||
faces = parsed_data['faces']
|
||
|
||
# 用于存储唯一的subject
|
||
unique_subjects = set()
|
||
|
||
# 用于存储过滤后的face
|
||
filtered_faces = []
|
||
|
||
# 遍历faces
|
||
for face in faces:
|
||
subject = face['subject']
|
||
|
||
# 如果subject是唯一的,则将其添加到unique_subjects集合和filtered_faces列表中
|
||
if subject not in unique_subjects:
|
||
unique_subjects.add(subject)
|
||
filtered_faces.append(face)
|
||
return filtered_faces
|
||
|