|
|
|
@ -19,7 +19,7 @@ from config import (
|
|
|
|
|
LABEL_NAMES,
|
|
|
|
|
BOX_AREA_THRESHOLD,
|
|
|
|
|
DETECT_CONF_THRESHOLD,
|
|
|
|
|
ARTICULATION_THD,
|
|
|
|
|
ARTICULATION_THD, MOTOR_VEHICLE, MOTOR_VEHICLE_LIST,
|
|
|
|
|
)
|
|
|
|
|
from fd_face_detection import FaceRecognition
|
|
|
|
|
from fd_yolo import FdYolov8
|
|
|
|
@ -72,7 +72,7 @@ class TrackMain(object):
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
xywhs, labels, scores, xy_list = infos
|
|
|
|
|
tinfos_each_frame = {PERSON: [], CAR: []}
|
|
|
|
|
tinfos_each_frame = {PERSON: [], MOTOR_VEHICLE: []}
|
|
|
|
|
|
|
|
|
|
for xywh, label_id, score, polygon in zip(
|
|
|
|
|
xywhs, labels, scores, xy_list
|
|
|
|
@ -93,6 +93,7 @@ class TrackMain(object):
|
|
|
|
|
conf = round(score, 2)
|
|
|
|
|
|
|
|
|
|
# 通过面积过滤掉一些小框
|
|
|
|
|
# todo 预筛选,阈值不能太高,后面还会有topN过滤
|
|
|
|
|
if s <= BOX_AREA_THRESHOLD:
|
|
|
|
|
continue
|
|
|
|
|
if conf <= DETECT_CONF_THRESHOLD:
|
|
|
|
@ -104,7 +105,11 @@ class TrackMain(object):
|
|
|
|
|
info['conf'] = conf
|
|
|
|
|
info['box_area'] = s
|
|
|
|
|
info['polygon_indexs'] = polygon.astype(int)
|
|
|
|
|
tinfos_each_frame[label].append(info)
|
|
|
|
|
# 机动车包含car,truck,motorcycle,bus
|
|
|
|
|
if label in MOTOR_VEHICLE_LIST:
|
|
|
|
|
tinfos_each_frame[MOTOR_VEHICLE].append(info)
|
|
|
|
|
else:
|
|
|
|
|
tinfos_each_frame[label].append(info)
|
|
|
|
|
|
|
|
|
|
return tinfos_each_frame
|
|
|
|
|
|
|
|
|
@ -124,12 +129,12 @@ class TrackMain(object):
|
|
|
|
|
all_licenses = []
|
|
|
|
|
# 存储一帧中所有人脸embedding
|
|
|
|
|
all_face_embeddings = []
|
|
|
|
|
for label, target_infos in tinfos_each_frame.items():
|
|
|
|
|
for label_alias, target_infos in tinfos_each_frame.items():
|
|
|
|
|
# 按照框面积大小降序排序
|
|
|
|
|
target_infos.sort(key=lambda x: x['box_area'], reverse=True)
|
|
|
|
|
|
|
|
|
|
# todo 交警 先对整个图片上前topn的大框图中的person,送到交警检测模型中检测是否是交警
|
|
|
|
|
if label == PERSON:
|
|
|
|
|
if label_alias == PERSON:
|
|
|
|
|
police_indexs = get_police(
|
|
|
|
|
frame_copy, target_infos[:TOPN_AREA], self.model_traffic_police
|
|
|
|
|
)
|
|
|
|
@ -145,7 +150,7 @@ class TrackMain(object):
|
|
|
|
|
target_img = frame[p1[1]: p2[1], p1[0]: p2[0]]
|
|
|
|
|
target_img = target_img.astype(np.uint8)
|
|
|
|
|
|
|
|
|
|
if label == CAR:
|
|
|
|
|
if label_alias == MOTOR_VEHICLE:
|
|
|
|
|
# licenses = predict_ocr(target_img, self.ocr)
|
|
|
|
|
licenses = predict_ocr(target_img)
|
|
|
|
|
licenses = list(set(licenses))
|
|
|
|
@ -153,7 +158,7 @@ class TrackMain(object):
|
|
|
|
|
if licenses:
|
|
|
|
|
is_hit = True
|
|
|
|
|
|
|
|
|
|
elif label == PERSON:
|
|
|
|
|
elif label_alias == PERSON:
|
|
|
|
|
# 是交警,则不处理
|
|
|
|
|
if index in police_indexs:
|
|
|
|
|
continue
|
|
|
|
@ -174,7 +179,7 @@ class TrackMain(object):
|
|
|
|
|
# test
|
|
|
|
|
if is_hit:
|
|
|
|
|
frame_copy = draw_rectangle_text(
|
|
|
|
|
frame_copy, index, p1, p2, label, info['conf'], -1, info['box_area']
|
|
|
|
|
frame_copy, index, p1, p2, label_alias, info['conf'], -1, info['box_area']
|
|
|
|
|
)
|
|
|
|
|
return all_face_embeddings, all_licenses, frame_copy
|
|
|
|
|
|
|
|
|
|