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.

50 lines
1.2 KiB
Python

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import cv2
from tqdm import tqdm
from ultralytics import YOLO
from ultralytics.yolo.utils.plotting import Annotator
import os
def analysis_yolov8(images, model_coco,confidence):
frame = images
# 第一步用COCO数据集推理
results_coco = model_coco(frame)
# print(results_coco)
if results_coco:
for r in results_coco:
boxes = r.boxes
re_list = []
for box in boxes:
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)
return re_list
# if __name__ == '__main__':
# model_coco = YOLO("model_files/bk1.pt")
# frame = cv2.imread("E:/BANK_XZ/data_file/0000162.jpg")
# analysis_video(frame, model_coco,confidence=0.5)