Why computer vision enables intelligent flight in Drone Programming - Performance Analysis
We want to understand how the time a drone takes to process images grows as it sees more data.
This helps us know how fast the drone can react using computer vision.
Analyze the time complexity of the following code snippet.
function processFrame(frame) {
let detectedObjects = []
for (let pixel of frame.pixels) {
if (isFeature(pixel)) {
detectedObjects.push(pixel)
}
}
return detectedObjects
}
function flyIntelligently(frames) {
for (let frame of frames) {
let objects = processFrame(frame)
adjustFlight(objects)
}
}
This code processes each video frame pixel by pixel to find features, then uses that info to adjust flight.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through every pixel in each frame to detect features.
- How many times: For each frame, it checks all pixels once.
As the number of frames or pixels grows, the work grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 frames × 100 pixels | 1,000 checks |
| 100 frames × 100 pixels | 10,000 checks |
| 1,000 frames × 100 pixels | 100,000 checks |
Pattern observation: The total work grows directly with the number of frames and pixels combined.
Time Complexity: O(n × m)
This means the time grows proportionally with the number of frames (n) and pixels per frame (m).
[X] Wrong: "Processing one pixel means the whole frame is done quickly regardless of size."
[OK] Correct: Each pixel must be checked, so more pixels mean more work, not the same time.
Understanding how image data size affects processing time helps you explain drone responsiveness clearly.
"What if the drone only processed every other pixel? How would that change the time complexity?"