|
|
|
@ -1,50 +0,0 @@
|
|
|
|
|
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)
|