Сообщение об ошибке:
Скорость: предварительная обработка 4,5 мс, вывод 332,2 мс, постобработка 0,6 мс на
изображение в форме (1, 3, 480, 640) Обнаружения для DeepSORT: [[ 107.22
186.92 639.26 479.49 0.83611]] Traceback (последний вызов): Файл "/home/roy/environments/001-opencv/004-opencv.py" ,
строка 127, в ФайлDetect_customers()
"/home/roy/environments/001-opencv/004-opencv.py", строка 84, в
detect_customers track = tracker.update_tracks(deep_sort_detections,
frame= рамка) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^
Файл
"/home/roy/environments/001-opencv/lib/python3.12/site-packages/deep_sort_realtime/deepsort_tracker.py",
строка 195, в update_tracks утверждает len(raw_detections[0][0] )==4
^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: объект типа 'numpy.float32'
не имеет len()
Раздел кода (обнаружение и отслеживание):
Код: Выделить всё
def detect_customers():
# Initialize YOLO and DeepSORT
model = YOLO("yolov8s.pt") # Load YOLO model
tracker = DeepSort(max_age=30, n_init=3)
cap = cv2.VideoCapture(0) # Replace 0 with the video source
active_customers = {}
while True:
ret, frame = cap.read()
if not ret:
break
results = model(frame) # Perform YOLO inference
detections = []
for result in results:
for box in result.boxes:
# Extract bounding box and confidence score
x1, y1, x2, y2 = box.xyxy[0].tolist() # Convert bounding box to list
confidence = float(box.conf[0]) # Confidence score
# Append detection in the required format
detection = [float(x1), float(y1), float(x2), float(y2), float(confidence)]
detections.append(detection)
# Handle empty detections
if len(detections) == 0:
deep_sort_detections = np.empty((0, 5)) # Empty array for no detections
else:
deep_sort_detections = np.array(detections, dtype=np.float32) # Convert to NumPy array with proper structure
# Debugging: Print the detections being passed to DeepSORT
print("Detections for DeepSORT:", deep_sort_detections)
# Update tracker
tracks = tracker.update_tracks(deep_sort_detections, frame=frame)
for track in tracks:
if not track.is_confirmed():
continue
track_id = track.track_id
ltrb = track.to_ltrb() # Convert to (left, top, right, bottom)
cv2.rectangle(frame, (int(ltrb[0]), int(ltrb[1])), (int(ltrb[2]), int(ltrb[3])), (0, 255, 0), 2)
cv2.putText(frame, f"ID: {track_id}", (int(ltrb[0]), int(ltrb[1]) - 10),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
# Display frame
cv2.imshow("Customer Detection", frame)
if cv2.waitKey(1) & 0xFF == 27: # Press ESC to exit
break
cap.release()
cv2.destroyAllWindows()
- Описание ошибки: при передаче deep_sort_detections в
tracker.update_tracks(), Я получаю ошибку TypeError: объект типа
'numpy.float32' не имеет len(). - Формат обнаружения: я форматирую обнаружения как [[x1, y1, x2, y2,
confidence], ...] и преобразуем его в массив NumPy с помощью
dtype=np.float32. Однако похоже, что DeepSORT ожидает
другой формат или возникла какая-то проблема с типом.
- Как правильно отформатировать данные обнаружения, чтобы они были совместимы с
методом update_tracks() DeepSORT? - Я что-то упустил? данные должны быть структурированы или
переданы DeepSORT?
Подробнее здесь: https://stackoverflow.com/questions/792 ... ntegration