Coding4Fun Drone posts
- Introduction to DJI Tello
- Analyzing Python samples code from the official SDK
- Drone Hello World ! Takeoff and land
- Tips to connect to Drone WiFi in Windows 10
- Reading data from the Drone, Get battery level
- Sample for real time data read, Get Accelerometer data
- How the drone camera video feed works, using FFMPEG to display the feed
- Open the drone camera video feed using OpenCV
- Performance and OpenCV, measuring FPS
- Detect faces using the drone camera
- Detect a banana and land!
- Flip when a face is detected!
Now that I started to understand how UDP works, I also did my research to find which are the best options to access an UDP video feed. Lucky for me, there are plenty of resources about doing this task using my old friend OpenCV.
Most of the OpenCV documentation is written in C++. However at the end, it all goes down to these basic lines of code
# open UDP videoUDP = 'udp://192.168.10.1:11111' cap = cv2.VideoCapture(videoUDP) # read a frame from the feed ret, frame = cap.read() img = cv2.resize(frame, (320, 240)) # diplay the frame in openCV video window cv2.imshow('Video', img)
Note: At the references section below I shared some of my posts with my experiences on how to install OpenCV in Windows 10.
Let’s go back to our sample Python App. Using the previous sample that display the battery level, I changed this code to be alive all the time and displaying the video feed in a 320*240 window.
The following video display how fast this works:
And of course the complete code with this notes:
- Line 96-100. Open video feed and wait 2 seconds
- Line 104-118. Main App.
- Get and display battery level
- Get UDP video frame
- Resize frame to 320×240
- Display frame
- When Q key is pressed, exit app
- Line 121. Close video stream