Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the OpenCV library in Python.
Computer Vision
import [1] as cv
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'opencv' instead of 'cv2' causes import errors.
Trying to import 'opencv-python' directly is incorrect.
✗ Incorrect
The OpenCV library is imported in Python using 'cv2'.
2fill in blank
mediumComplete the code to read an image file using OpenCV.
Computer Vision
image = cv.[1]('image.jpg')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'load' or 'open' causes attribute errors.
Trying 'read_image' is not a valid OpenCV function.
✗ Incorrect
The function 'imread' reads an image file into OpenCV.
3fill in blank
hardFix the error in the code to convert an image to grayscale.
Computer Vision
gray = cv.cvtColor(image, [1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'COLOR_RGB2GRAY' causes wrong color conversion.
Using 'COLOR_BGR2RGB' changes color space but not to grayscale.
✗ Incorrect
To convert a BGR image to grayscale, use 'cv.COLOR_BGR2GRAY'.
4fill in blank
hardFill both blanks to resize an image to 100x100 pixels.
Computer Vision
resized = cv.resize(image, ([1], [2]))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different numbers for width and height changes aspect ratio.
Using values other than 100 does not meet the requirement.
✗ Incorrect
The size tuple (100, 100) resizes the image to 100 pixels width and height.
5fill in blank
hardFill all three blanks to display an image window and wait for a key press.
Computer Vision
cv.imshow('[1]', [2]) cv.[3](0) cv.destroyAllWindows()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'show' instead of 'waitKey' causes errors.
Passing wrong variable names causes runtime errors.
✗ Incorrect
Use 'imshow' to show the image in a window named 'window', pass the image variable, then 'waitKey(0)' waits for a key press.