Challenge - 5 Problems
Color Tracking Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of color detection thresholding
What is the output of the following code snippet that processes an image to detect a red object using HSV color space thresholding?
Drone Programming
import cv2 import numpy as np # Create a 3x3 image with one red pixel in HSV image = np.zeros((3,3,3), dtype=np.uint8) image[1,1] = [0, 255, 255] # HSV red # Define red color range in HSV lower_red = np.array([0, 100, 100]) upper_red = np.array([10, 255, 255]) # Threshold the image mask = cv2.inRange(image, lower_red, upper_red) print(mask)
Attempts:
2 left
💡 Hint
Remember that cv2.inRange returns 255 for pixels within the range and 0 otherwise.
✗ Incorrect
The pixel at position (1,1) is red in HSV and falls within the threshold, so mask at that position is 255, others are 0.
🧠 Conceptual
intermediate1:30remaining
Understanding color space conversion
Why do drone programs often convert camera images from BGR to HSV color space for color-based tracking?
Attempts:
2 left
💡 Hint
Think about how lighting affects color detection.
✗ Incorrect
HSV separates hue (color) from saturation and value (brightness), so detecting colors is easier and less sensitive to light changes.
🔧 Debug
advanced2:00remaining
Identify the error in color tracking code
What error will this drone tracking code raise when run?
Drone Programming
import cv2 import numpy as np frame = np.zeros((5,5,3), dtype=np.uint8) frame[2,2] = [0, 0, 255] # Red in BGR hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) lower_blue = np.array([110,50,50]) upper_blue = np.array([130,255,255]) mask = cv2.inRange(hsv, lower_blue, upper_blue) contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) print(contours[0])
Attempts:
2 left
💡 Hint
Check what happens if no blue pixels are detected.
✗ Incorrect
Since the image has only a red pixel, the blue mask is empty, so contours list is empty and accessing contours[0] causes IndexError.
📝 Syntax
advanced1:30remaining
Find the syntax error in color mask creation
Which option contains the correct syntax to create a mask for green color in HSV using cv2.inRange?
Attempts:
2 left
💡 Hint
cv2.inRange expects numpy arrays for the color bounds.
✗ Incorrect
cv2.inRange requires numpy arrays for lower and upper bounds; lists or tuples may cause errors or unexpected behavior; sets are invalid syntax here.
🚀 Application
expert2:30remaining
Calculate the number of detected color blobs
Given the following code that detects yellow blobs in a drone camera frame, how many blobs will be detected?
Drone Programming
import cv2 import numpy as np frame = np.zeros((6,6,3), dtype=np.uint8) frame[1,1] = [0, 255, 255] # Yellow in BGR frame[4,4] = [0, 255, 255] # Yellow in BGR frame[1,4] = [0, 255, 255] # Yellow in BGR hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) lower_yellow = np.array([20, 100, 100]) upper_yellow = np.array([30, 255, 255]) mask = cv2.inRange(hsv, lower_yellow, upper_yellow) contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) print(len(contours))
Attempts:
2 left
💡 Hint
Each yellow pixel is isolated; contours detect connected regions.
✗ Incorrect
Each yellow pixel is isolated (not connected), so each forms its own contour; total 3 blobs detected.