This example shows you how to track a green ball using the MATLAB® Support Package for Ryze® Tello Drones.
The MATLAB® Support Package for Ryze® Tello Drones allows you to capture images from the Ryze drone and bring those right into MATLAB for processing.
To run this example you need the following:
A fully charged Ryze drone
A computer with a WiFi connection
Power on the Ryze drone.
Connect your computer to the drone's Wifi network.
ryzeObj = ryze();
Connect to Ryze Tello drone's FPV camera
cameraObj = camera(ryzeObj);
Take off the Ryze drone from a level surface.
Execute the following command at the MATLAB command prompt to take-off of the drone.
We will call the
trackBall function on the images captured by the drone in a loop. The
trackBall function accepts the following inputs:
Connection to the Ryze Tello drone
Image captured from the drone's FPV camera
Minimum value for green component intensity for the pixel to be considered green. Adjust this value based on the flying environment
Minimum offset of drone from the image center. If the offset goes above this value, then the drone position has to be adjusted.
The drone tracks the ball for a duration for 60 seconds.
tim = tic; duration = 60; minGreenIntensity = 40; minOffset = 30; while(toc(tim) < duration) img = snapshot(cameraObj); trackBall(ryzeObj, img, minGreenIntensity, minOffset); pause(0.1); end
The green ball is outside the bounds. Move the drone to keep it within threshold.
The green ball is now within the threshold.
Land the drone.
When finished, clear the connection to the Ryze drone.
trackBall algorithm is used to:
Extract RGB color components from the FPV camera image.
Find indices of green pixels in the image.
Find the center of the green ball in the captured image.
Find the displacement of the green ball from the center of the image.
Determine the direction to move the drone to bring the ball to center of the image.
For more information on the
trackBall function, open the
TrackGreenBallExample and then execute the following command in the MATLAB command line: