Challenge - 5 Problems
Image Display Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What does this OpenCV code display?
Consider the following Python code using OpenCV to display an image. What will the window show when this code runs?
Computer Vision
import cv2 import numpy as np img = np.zeros((100, 100, 3), dtype=np.uint8) img[25:75, 25:75] = [0, 255, 0] # green square in the center cv2.imshow('Test Image', img) cv2.waitKey(0) cv2.destroyAllWindows()
Attempts:
2 left
💡 Hint
Remember that np.zeros creates a black image and the color is in BGR format.
✗ Incorrect
The image is initialized as black (all zeros). The slice sets a square region to [0, 255, 0], which in BGR is green. So the window shows a black background with a green square.
❓ Predict Output
intermediate2:00remaining
What color does matplotlib show for this image array?
Given this code using matplotlib to display an image, what color will the square appear?
Computer Vision
import matplotlib.pyplot as plt import numpy as np img = np.zeros((100, 100, 3), dtype=np.uint8) img[25:75, 25:75] = [0, 0, 255] # red square in BGR plt.imshow(img) plt.show()
Attempts:
2 left
💡 Hint
Matplotlib expects RGB format, but the array is in BGR.
✗ Incorrect
The image array is in BGR format, but matplotlib expects RGB. So [0,0,255] in BGR is red, but matplotlib reads it as blue. The square appears blue on black.
❓ Model Choice
advanced2:00remaining
Choosing the right method to display images in a real-time video feed
You want to display frames from a live webcam feed with minimal delay and allow keyboard interaction to stop the feed. Which method is best?
Attempts:
2 left
💡 Hint
Consider speed and ability to handle keyboard events.
✗ Incorrect
cv2.imshow with cv2.waitKey is designed for fast image display and keyboard input in loops, ideal for real-time video. Matplotlib is slow and blocks execution.
❓ Metrics
advanced2:00remaining
Understanding the effect of cv2.waitKey argument on image display
What happens if you call cv2.waitKey(0) versus cv2.waitKey(1) after cv2.imshow?
Attempts:
2 left
💡 Hint
Think about how waitKey controls the pause duration.
✗ Incorrect
cv2.waitKey(0) pauses the program until a key is pressed. cv2.waitKey(1) pauses for 1 millisecond and then continues, useful for video loops.
🔧 Debug
expert3:00remaining
Why does this matplotlib image display show a distorted color?
You run this code to display an image loaded by OpenCV, but the colors look wrong. What is the cause?
Computer Vision
import cv2 import matplotlib.pyplot as plt img = cv2.imread('image.jpg') plt.imshow(img) plt.show()
Attempts:
2 left
💡 Hint
Check the color channel order between OpenCV and matplotlib.
✗ Incorrect
OpenCV loads images in BGR order, but matplotlib expects RGB. Without converting, colors appear distorted.