0
0
Drone Programmingprogramming~30 mins

Color-based tracking in Drone Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Color-based tracking
📖 Scenario: You are programming a drone to follow a red ball in a room. The drone uses a camera to see colors and moves to keep the red ball centered in its view.
🎯 Goal: Build a simple program that detects the red color in the camera feed and decides the drone's movement direction to follow the red ball.
📋 What You'll Learn
Create a dictionary called camera_feed with pixel colors as keys and their counts as values
Create a variable called red_threshold to decide when red is dominant
Use a for loop with variables color and count to iterate over camera_feed.items()
Create a variable called red_count to sum counts of red pixels
Print the drone's movement direction based on red detection
💡 Why This Matters
🌍 Real World
Drones use color tracking to follow objects like balls or markers in sports, delivery, or search and rescue.
💼 Career
Understanding color-based tracking helps in robotics, drone programming, and computer vision jobs.
Progress0 / 4 steps
1
DATA SETUP: Create the camera feed data
Create a dictionary called camera_feed with these exact entries: 'red': 15, 'green': 5, 'blue': 10, 'yellow': 3
Drone Programming
Need a hint?

Use curly braces to create a dictionary with the exact colors and counts.

2
CONFIGURATION: Set the red detection threshold
Create a variable called red_threshold and set it to 10
Drone Programming
Need a hint?

Just assign the number 10 to the variable red_threshold.

3
CORE LOGIC: Count red pixels in the camera feed
Create a variable called red_count and set it to 0. Then use a for loop with variables color and count to iterate over camera_feed.items(). Inside the loop, add count to red_count only if color is equal to 'red'.
Drone Programming
Need a hint?

Use an if statement inside the loop to check if color is 'red' and add count to red_count.

4
OUTPUT: Print the drone's movement direction
Write a print statement that prints "Move forward" if red_count is greater than red_threshold. Otherwise, print "Search for red ball".
Drone Programming
Need a hint?

Use an if-else statement to decide what to print based on red_count and red_threshold.