Hello to all,
I would like to use my ANAFI Ai for detection with pre-trained deep learning models.
When I launch the code below, it works fine for 20-30 seconds and then it stops detecting, any idea on what could be the issue here ?
Also I had to resize the image, because the frame size fluctuates greatly for the time it is working, any idea of what is happening ?
import os import cv2 import torch import olympe import time IP = "192.168.42.1" RTSP_URL ='rtsp://192.168.42.1/live' os.environ['OPENCV_FFMPEG_CAPTURE_OPTIONS']="rtsp_transport;udp" model = torch.hub.load('./yolov5', 'custom', path='./model/custom-COCO-tiny.pt', source='local') model.conf = 0.3 drone = olympe.Drone(IP) drone.connect() def start_detection(): cap = cv2.VideoCapture(RTSP_URL) if not cap.isOpened(): raise IOError("Cannot open webcam") while cap.isOpened(): ret, frame = cap.read() if ret: height = frame.shape width = frame.shape frame_resized = cv2.resize(frame, (1280, int(1280*height/width))) frame_detected = model(frame_resized) frame_detected.render() time.sleep(0.5) # Our operations on the frame come here elif not ret: print("could not receive the frame, trying to reconnect ...") drone.disconnect() drone.connect() time.sleep(0.5) # Display the resulting frame cv2.imshow('frame', frame_detected.imgs) if cv2.waitKey(1) == ord('q'): break # When everything done, release the capture cap.release() cv2.destroyAllWindows() drone.disconnect() if __name__ == "__main__": start_detection()
Tried to disconnect and reconnect olympe to the drone when that happens without success,
tried to add some sleep time between the frames without success too,
When I exit and restart the code, it works again for 20-30 seconds …
Is this drone not supposed to work with image detection ?