0
0
Computer Visionml~10 mins

Reading images (cv2.imread) in Computer Vision - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read an image from a file using OpenCV.

Computer Vision
import cv2
image = cv2.[1]('photo.jpg')
Drag options to blanks, or click blank then click option'
Aimshow
Bimread
Cimwrite
Dresize
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.imshow instead of cv2.imread to read images.
Using cv2.imwrite which is for saving images.
2fill in blank
medium

Complete the code to read an image in grayscale mode.

Computer Vision
import cv2
image = cv2.imread('photo.jpg', [1])
Drag options to blanks, or click blank then click option'
Acv2.IMREAD_UNCHANGED
Bcv2.IMREAD_COLOR
Ccv2.IMREAD_ANYCOLOR
Dcv2.IMREAD_GRAYSCALE
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.IMREAD_COLOR which loads a color image.
Using cv2.IMREAD_UNCHANGED which keeps alpha channel.
3fill in blank
hard

Fix the error in the code to correctly read an image file.

Computer Vision
import cv2
img = cv2.imread[1]
Drag options to blanks, or click blank then click option'
A[0]
B('image.png', 1)
C('image.png', cv2.IMREAD_COLOR)
D('image.png')
Attempts:
3 left
💡 Hint
Common Mistakes
Missing parentheses causing syntax errors.
Passing arguments outside parentheses.
4fill in blank
hard

Fill both blanks to read an image and check if it was loaded successfully.

Computer Vision
import cv2
image = cv2.imread('test.jpg', [1])
if image is [2]:
    print('Failed to load image')
Drag options to blanks, or click blank then click option'
Acv2.IMREAD_COLOR
BNone
Ccv2.IMREAD_GRAYSCALE
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Not checking if the image is None before using it.
Using wrong flag values for reading.
5fill in blank
hard

Fill all three blanks to read an image, convert it to grayscale, and display it.

Computer Vision
import cv2
image = cv2.imread('pic.jpg', [1])
gray = cv2.[2](image, [3])
cv2.imshow('Gray Image', gray)
cv2.waitKey(0)
cv2.destroyAllWindows()
Drag options to blanks, or click blank then click option'
Acv2.IMREAD_COLOR
BcvtColor
Ccv2.COLOR_BGR2GRAY
Dcv2.IMREAD_GRAYSCALE
Attempts:
3 left
💡 Hint
Common Mistakes
Reading image directly in grayscale and then converting again.
Using wrong conversion flags.