使用YOLOv8obb模型获取边框坐标时报错obbs = r.boxes.xywhr.cpu().tolist()
AttributeError: 'NoneType' object has no attribute 'xywhr'
import time
import cv2
from ultralytics import YOLO
from ultralytics.utils.plotting import save_one_box as crop
import imutils
import numpy as np
import os
import shutil
model = YOLO('best.pt')
video_path ="D:/WIN_20230907_21_08_23_Pro.mp4"
cap = cv2.VideoCapture(video_path)
confi=0.2
while cap.isOpened():
success, frame = cap.read()
confi = round(confi, 2)
if confi <= 0.2:
confi = 0.2
elif confi >= 0.8:
confi = 0.8
if success:
results = model(frame, conf=confi, save=False, show=False)
annotated_frame = results[0].plot()
cv2.imshow("YOLOv8 Tracking", annotated_frame)
r=results[0]
if results:
obbs = r.boxes.xywhr.cpu().tolist()
for i, obb in enumerate(obbs):
xc, yc, w, h, angle = obb # Unpack the OBB
else:
bkg = np.ones((256, 1280, 3), dtype=np.uint8)
bkg *= 200
annotated_frame = np.vstack((annotated_frame, bkg))
if cv2.waitKey(1) & 0xFF == ord("q"):
break
else:
# Break the loop if the end of the video is reached
break
# Release the video capture object and close the display window
cap.release()
cv2.destroyAllWindows()
修改后不管有没有检测到物体,都会print:no objects detected
最前面有这个报错不知道有没有关系:
UserWarning: Plan failed with a cudnnException: CUDNN_BACKEND_EXECUTION_PLAN_DESCRIPTOR: cudnnFinalize Descriptor Failed cudnn_status: CUDNN_STATUS_NOT_SUPPORTED (Triggered internally at C:\actions-runner\_work\pytorch\pytorch\builder\windows\pytorch\aten\src\ATen\native\cudnn\Conv_v8.cpp:919.)
return F.conv2d(input, weight, bias, self.stride,