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.

48 lines
1.0 KiB
Python

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