0
0
Intro to Computingfundamentals~10 mins

Computer vision basics in Intro to Computing - Interactive Code Practice

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

Complete the code to load an image using OpenCV.

Intro to Computing
import cv2
image = cv2.[1]('image.jpg')
Drag options to blanks, or click blank then click option'
Aimshow
Bresize
Cimwrite
Dimread
Attempts:
3 left
💡 Hint
Common Mistakes
Using imshow instead of imread
Using imwrite which saves images
Using resize which changes image size
2fill in blank
medium

Complete the code to convert a color image to grayscale using OpenCV.

Intro to Computing
gray_image = cv2.cvtColor(image, cv2.[1])
Drag options to blanks, or click blank then click option'
ACOLOR_BGR2GRAY
BCOLOR_GRAY2BGR
CCOLOR_BGR2RGB
DCOLOR_RGB2BGR
Attempts:
3 left
💡 Hint
Common Mistakes
Using COLOR_BGR2RGB which changes color space but not to grayscale
Using COLOR_GRAY2BGR which converts grayscale to color
Using COLOR_RGB2BGR which swaps color channels
3fill in blank
hard

Fix the error in the code to display an image using OpenCV.

Intro to Computing
cv2.[1]('Image Window', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Drag options to blanks, or click blank then click option'
Aimread
Bimshow
Cresize
Dimwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using imread which loads images
Using imwrite which saves images
Using resize which changes image size
4fill in blank
hard

Fill both blanks to create a binary threshold on a grayscale image.

Intro to Computing
_, binary_image = cv2.threshold(gray_image, [1], [2], cv2.THRESH_BINARY)
Drag options to blanks, or click blank then click option'
A127
B255
C128
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as threshold which makes all pixels black
Using 128 as max value which is not standard
Swapping threshold and max value
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps image filenames to their grayscale shapes.

Intro to Computing
shapes = {filename: cv2.imread(filename, [1]).shape[:[2]] for filename in files if cv2.imread(filename, [3]) is not None}
Drag options to blanks, or click blank then click option'
Acv2.IMREAD_GRAYSCALE
B2
Ccv2.IMREAD_COLOR
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using IMREAD_COLOR which loads 3 channels
Using 3 for slicing shape which is for color images
Using different flags for loading images in comprehension