Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to save an image using OpenCV.
Computer Vision
import cv2 image = cv2.imread('input.jpg') cv2.[1]('output.jpg', image)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.imshow instead of cv2.imwrite.
Trying to read the image again instead of saving.
✗ Incorrect
The cv2.imwrite function saves an image to a file.
2fill in blank
mediumComplete the code to save a grayscale image using OpenCV.
Computer Vision
import cv2 image = cv2.imread('input.jpg', [1]) cv2.imwrite('gray_output.jpg', image)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using color conversion codes instead of read flags.
Using IMREAD_COLOR which reads a color image.
✗ Incorrect
To read an image in grayscale, use cv2.IMREAD_GRAYSCALE as the flag.
3fill in blank
hardFix the error in saving an image with compression parameters.
Computer Vision
import cv2 image = cv2.imread('input.jpg') cv2.imwrite('compressed.jpg', image, [1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing parameters as a dictionary or tuple.
Using assignment syntax inside the function call.
✗ Incorrect
The compression parameters must be passed as a list of pairs: [flag, value].
4fill in blank
hardFill both blanks to save a PNG image with compression level 3.
Computer Vision
import cv2 image = cv2.imread('input.png') cv2.imwrite('output.png', image, [[1], [2]])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using JPEG flags for PNG images.
Passing quality value instead of compression level.
✗ Incorrect
Use cv2.IMWRITE_PNG_COMPRESSION flag with compression level 3 for PNG images.
5fill in blank
hardFill all three blanks to save a JPEG image with quality 85 and grayscale read.
Computer Vision
import cv2 image = cv2.imread('input.jpg', [1]) cv2.imwrite('output.jpg', image, [[2], [3]])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using color read flag instead of grayscale.
Mixing PNG compression flags with JPEG quality.
✗ Incorrect
Read the image in grayscale with cv2.IMREAD_GRAYSCALE, then save with JPEG quality 85 using cv2.IMWRITE_JPEG_QUALITY flag and value 85.