Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load an image using OpenCV.
Computer Vision
import cv2 image = cv2.[1]('image.jpg')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using imshow instead of imread
Using imwrite which saves images
✗ Incorrect
The function imread loads an image from a file into memory.
2fill in blank
mediumComplete the code to convert an image to grayscale.
Computer Vision
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 which changes color space but not to grayscale
✗ Incorrect
cv2.COLOR_BGR2GRAY converts a color image to grayscale.
3fill in blank
hardFix the error in the code to detect edges using Canny.
Computer Vision
edges = cv2.Canny(image, [1], 100)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing threshold as a string
Passing None or image instead of a number
✗ Incorrect
The first threshold for the Canny edge detector must be a number, not a string or None.
4fill in blank
hardFill both blanks to create a dictionary of image sizes for images with width greater than 100.
Computer Vision
sizes = {img: (img.shape[[1]], img.shape[[2]]) for img in images if img.shape[1] > 100} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping height and width indices
Using invalid indices like 3
✗ Incorrect
In OpenCV images, shape[1] is width and shape[0] is height.
5fill in blank
hardFill all three blanks to filter images by height and create a dictionary of their shapes.
Computer Vision
filtered = {img: img.shape for img in images if img.shape[[1]] [2] [3] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using width index 1 instead of height 0
Using '<' instead of '>'
Using wrong threshold value
✗ Incorrect
This code filters images with height greater than 200 pixels and stores their shapes.