Загрузка данных


from djitellopy import Tello
import cv2
from ultralytics import YOLO

# Загружаем лёгкую модель YOLO (первый запуск — скачает веса ~6 МБ)
model = YOLO('yolov8n.pt')

tello = Tello()
tello.connect()
tello.streamon()

print("Ищу людей в кадре. Нажмите 'q' для выхода.")

while True:
    frame = tello.get_frame_read().frame
    if frame is None:
        continue
    
    # Уменьшаем кадр для скорости
    frame = cv2.resize(frame, (640, 480))
    
    # Ищем только людей (класс 0)
    results = model(frame, classes=[0], verbose=False, conf=0.5)
    
    # Рисуем рамки вокруг найденных людей
    for r in results:
        if r.boxes is not None:
            for box in r.boxes:
                x1, y1, x2, y2 = map(int, box.xyxy[0])
                cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
                cv2.putText(frame, "Person", (x1, y1-10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0,255,0), 2)
    
    cv2.imshow("YOLO Detection", frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

tello.streamoff()
cv2.destroyAllWindows()