📖 Scenario: You are programming a drone to create a map by stitching together images it takes while flying over a field. Each image has a unique ID and a position coordinate. Your task is to combine these images into a single stitched map based on their positions.
🎯 Goal: Build a simple program that takes a dictionary of images with their positions, sets a stitching threshold, selects images close enough to stitch, and outputs the list of images that will be stitched together.
📋 What You'll Learn
Create a dictionary called images with image IDs as keys and their (x, y) positions as values.
Create a variable called stitch_threshold to set the maximum distance between images to be stitched.
Use a for loop with variables img1 and pos1 to iterate over images.items().
Inside the loop, use another for loop with variables img2 and pos2 to iterate over images.items().
Calculate the distance between pos1 and pos2 and if it is less than or equal to stitch_threshold, add the pair (img1, img2) to a list called stitch_pairs.
Print the stitch_pairs list.
💡 Why This Matters
🌍 Real World
Drones capture many images of land or buildings. Stitching these images creates a complete map or model.
💼 Career
Understanding image stitching helps in drone programming, mapping, surveying, and geographic information systems (GIS).
Progress0 / 4 steps
1
Create the images dictionary
Create a dictionary called images with these exact entries: 'img1': (0, 0), 'img2': (3, 4), 'img3': (6, 8), 'img4': (10, 10).
Drone Programming
Hint
Use curly braces {} to create a dictionary. Each key is a string like 'img1' and each value is a tuple with two numbers.
2
Set the stitching threshold
Create a variable called stitch_threshold and set it to 5.
Drone Programming
Hint
Just write stitch_threshold = 5 on a new line.
3
Find image pairs to stitch
Create an empty list called stitch_pairs. Use a for loop with variables img1 and pos1 to iterate over images.items(). Inside it, use another for loop with variables img2 and pos2 to iterate over images.items(). Calculate the distance between pos1 and pos2 using the formula ((pos1[0] - pos2[0])**2 + (pos1[1] - pos2[1])**2)**0.5. If the distance is less than or equal to stitch_threshold and img1 is not equal to img2, add the tuple (img1, img2) to stitch_pairs.
Drone Programming
Hint
Remember to check that img1 is not the same as img2 to avoid pairing an image with itself.
4
Print the stitching pairs
Write print(stitch_pairs) to display the list of image pairs that will be stitched together.
Drone Programming
Hint
Just write print(stitch_pairs) to see the pairs.
Practice
(1/5)
1. What is the main purpose of image stitching in drone programming?
easy
A. To combine multiple drone photos into one large map
B. To control the drone's flight path
C. To improve the drone's battery life
D. To send live video feed to the operator
Solution
Step 1: Understand image stitching concept
Image stitching is about joining many photos to create a bigger picture.
Step 2: Identify the main use in drone programming
It helps create large maps from many drone images for better area coverage.
Final Answer:
To combine multiple drone photos into one large map -> Option A
Quick Check:
Image stitching = combine photos [OK]
Hint: Image stitching means joining photos into one big map [OK]
Common Mistakes:
Confusing image stitching with drone control
Thinking it improves battery life
Mixing it with live video streaming
2. Which of the following is the correct way to start stitching images side by side in a drone program?
easy
A. stitch(images, method='side_by_side')
B. stitch(images, method='fly_path')
C. stitch(images, method='battery_save')
D. stitch(images, method='live_feed')
Solution
Step 1: Identify stitching method names
Side by side stitching joins images horizontally or vertically.
Step 2: Match method to stitching task
Only 'side_by_side' matches the stitching method; others relate to flight or battery.
Final Answer:
stitch(images, method='side_by_side') -> Option A
Quick Check:
Method 'side_by_side' = stitching images side by side [OK]
Hint: Use method='side_by_side' to join images simply [OK]
Common Mistakes:
Using unrelated methods like 'fly_path' or 'battery_save'
Confusing stitching method with drone flight commands
B. The show() method does not exist for stitched images
C. The stitch function requires images to be loaded, not file names
D. The images list is empty
Solution
Step 1: Check input type for stitch function
Stitch usually needs image data, not just file names as strings.
Step 2: Identify error cause
Passing file names without loading images causes errors when stitching or showing.
Final Answer:
The stitch function requires images to be loaded, not file names -> Option C
Quick Check:
Input must be loaded images, not file names [OK]
Hint: Load images before stitching, not just file names [OK]
Common Mistakes:
Assuming method 'overlap' is invalid
Thinking show() method is missing
Ignoring that images list is not empty
5. You want to create a stitched map from drone images but only include images that have at least 30% overlap with the previous one. Which approach best applies this condition in your stitching code?
hard
A. Stitch all images first, then crop the map to overlapping areas
B. Filter images by overlap percentage before stitching using a function
C. Use method='side_by_side' to ignore overlap
D. Manually stitch images without any overlap checks
Solution
Step 1: Understand the overlap condition
Only images with at least 30% overlap should be included in stitching.
Step 2: Choose the best way to apply this condition
Filtering images before stitching ensures only suitable images are combined.
Final Answer:
Filter images by overlap percentage before stitching using a function -> Option B
Quick Check:
Filter first, then stitch = correct approach [OK]
Hint: Filter images by overlap before stitching [OK]
Common Mistakes:
Stitching all images then cropping
Ignoring overlap and stitching side by side
Manual stitching without overlap checks
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.