You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.0 KiB
Python

def analysis_yolov8(frame, model_coco, labels_names, confidence_set):
# 第一步用COCO数据集推理
results_coco = model_coco(frame)
re_list = []
if results_coco:
for r in results_coco:
boxes = r.boxes
idx = 0
for box in boxes:
idx += 1
# get box coordinates in (top, left, bottom, right) format
b = box.xyxy[0]
c = box.cls
# 保存标签和坐标值作为返回结果
blist = b.tolist()
labels_name = model_coco.names[int(c)]
confidence = float(box.conf)
confidence = round(confidence, 2)
# 过滤置信度以下目标
if confidence < confidence_set:
continue
if labels_name in labels_names:
# 一个结果字典
re_dict = {labels_name: blist}
re_list.append(re_dict)
return re_list