0
0
Drone Programmingprogramming~10 mins

Color-based tracking in Drone Programming - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Color-based tracking
Start Camera
Capture Frame
Detect Color Pixels
Calculate Object Position
Adjust Drone Movement
Repeat or Stop
The drone camera captures frames, detects pixels of a target color, calculates the object's position, and moves accordingly in a loop.
Execution Sample
Drone Programming
frame = camera.capture()
color_mask = detect_color(frame, target_color)
position = find_object_position(color_mask)
drone.move_towards(position)
This code captures a frame, finds the target color pixels, calculates the object's position, and moves the drone toward it.
Execution Table
StepActionInputOutputDrone Movement
1Capture FrameCamera activeImage frame with colorsHover
2Detect Color PixelsImage frame, target_color=redMask highlighting red pixelsHover
3Calculate Object PositionColor maskCoordinates (x=150, y=100)Hover
4Adjust Drone MovementCoordinates (150,100)Movement command: move right and forwardMoves right and forward
5Capture FrameCamera activeNew image frameMoves right and forward
6Detect Color PixelsNew frame, target_color=redMask highlighting red pixelsMoves right and forward
7Calculate Object PositionNew color maskCoordinates (x=160, y=110)Moves right and forward
8Adjust Drone MovementCoordinates (160,110)Movement command: move right and forwardMoves right and forward
9Repeat or StopUser input or conditionContinue tracking or stopContinue or hover
💡 Tracking stops when user commands or target color is lost
Variable Tracker
VariableStartAfter Step 3After Step 7Final
frameNoneImage frame 1Image frame 2Image frame N
color_maskNoneMask of red pixels 1Mask of red pixels 2Mask of red pixels N
positionNone(150, 100)(160, 110)(xN, yN)
drone_movementHoverMoves right and forwardMoves right and forwardHover or move
Key Moments - 2 Insights
Why does the drone keep moving even if the color position changes slightly?
Because each new frame updates the position and the drone adjusts movement accordingly, as shown in steps 3, 4, 7, and 8 in the execution_table.
What happens if the target color is not detected in a frame?
The color_mask will be empty, so the position cannot be calculated, and the drone will hover or stop, as implied in the exit_note.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what is the position output?
A(150, 100)
B(160, 110)
CNo position
D(0, 0)
💡 Hint
Check the 'Output' column at step 3 in the execution_table.
At which step does the drone first move right and forward?
AStep 2
BStep 1
CStep 4
DStep 9
💡 Hint
Look at the 'Drone Movement' column in the execution_table.
If the color_mask is empty, what will the drone most likely do?
AMove right
BHover or stop
CMove forward
DMove backward
💡 Hint
Refer to the key_moments and exit_note about what happens when the target color is lost.
Concept Snapshot
Color-based tracking uses the drone camera to capture frames.
It detects pixels matching a target color.
Calculates the object's position from these pixels.
Drone moves toward the detected position.
This repeats continuously to follow the object.
Full Transcript
Color-based tracking works by the drone camera capturing images continuously. Each image is checked for pixels of a specific color. When these pixels are found, the program calculates where the object is in the frame. The drone then moves in the direction of the object to follow it. This process repeats, allowing the drone to track the colored object in real time. If the color is lost or the user stops the program, the drone will hover or stop moving.