Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to read 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 cv2.imshow instead of cv2.imread to load the image.
Using cv2.imwrite which saves an image instead of loading.
✗ Incorrect
The cv2.imread function reads an image from a file into memory.
2fill in blank
mediumComplete the code to convert the image to grayscale.
Computer Vision
gray = cv2.[1](image, cv2.COLOR_BGR2GRAY) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.imread again instead of converting color.
Using cv2.blur which smooths the image, not changes color.
✗ Incorrect
cv2.cvtColor converts images between color spaces, here from BGR to grayscale.
3fill in blank
hardFix the error in the code to apply Canny edge detection.
Computer Vision
edges = cv2.Canny(gray, [1], 150)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing threshold as a string instead of integer.
Passing None which causes runtime error.
✗ Incorrect
The first threshold must be a number, here 50, not a string or None.
4fill in blank
hardFill both blanks to display the edges image and wait for a key press.
Computer Vision
cv2.[1]('Edges', edges) cv2.[2](0)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.imread instead of imshow to display.
Forgetting to wait for a key press causing window to close immediately.
✗ Incorrect
cv2.imshow shows the image window, and cv2.waitKey(0) waits indefinitely for a key press.
5fill in blank
hardFill all three blanks to save the edges image, close windows, and print success message.
Computer Vision
cv2.[1]('edges_output.jpg', edges) cv2.[2]() print([3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using imshow instead of imwrite to save image.
Not closing windows causing program to hang.
Printing without quotes causing error.
✗ Incorrect
cv2.imwrite saves the image, cv2.destroyAllWindows() closes all windows, and print outputs the message.