Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load an aerial image for object detection.
Drone Programming
image = cv2.imread([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the filename.
Using a function call instead of a filename string.
✗ Incorrect
The correct way to load the aerial image is by specifying the filename as a string inside quotes.
2fill in blank
mediumComplete the code to convert the aerial image to grayscale for processing.
Drone Programming
gray_image = cv2.cvtColor(image, [1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using COLOR_BGR2RGB instead of grayscale conversion.
Using COLOR_GRAY2BGR which is the reverse conversion.
✗ Incorrect
To convert a BGR image to grayscale, use cv2.COLOR_BGR2GRAY.
3fill in blank
hardFix the error in the code to detect objects using a pre-trained model.
Drone Programming
detections = model.[1](gray_image) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'predict' which is common in classification but not detection.
Using 'fit' which is for training, not detection.
✗ Incorrect
The correct method to detect objects is 'detect', not 'predict' or others.
4fill in blank
hardFill both blanks to filter detected objects by confidence and draw bounding boxes.
Drone Programming
for obj in detections: if obj.confidence [1] 0.5: cv2.rectangle(image, obj.bbox[[2]], obj.bbox[2], (0,255,0), 2)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than instead of greater than for confidence.
Using wrong bounding box index causing errors.
✗ Incorrect
We filter objects with confidence greater than 0.5 and use index 0 for the bounding box start point.
5fill in blank
hardFill all three blanks to create a dictionary of detected object labels and their counts.
Drone Programming
counts = {}
for obj in detections:
label = obj.[1]
counts[label] = counts.get(label, [2]) + [3] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'confidence' instead of 'label' for dictionary keys.
Starting counts at 1 instead of 0 causing wrong counts.
✗ Incorrect
We use obj.label to get the label, default count 0, and add 1 for each detected object.