0
0
Drone Programmingprogramming~30 mins

Image stitching for mapping in Drone Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Image Stitching for Mapping
📖 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
Need a 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
Need a 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
Need a 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
Need a hint?

Just write print(stitch_pairs) to see the pairs.