0
0
Computer Visionml~10 mins

First image processing program 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 load an image using OpenCV.

Computer Vision
import cv2

image = cv2.[1]('sample.jpg')
Drag options to blanks, or click blank then click option'
Aresize
Bimshow
Cimwrite
Dimread
Attempts:
3 left
💡 Hint
Common Mistakes
Using imshow instead of imread to load image.
2fill in blank
medium

Complete the code to display the loaded image in a window.

Computer Vision
cv2.[1]('Display Window', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Drag options to blanks, or click blank then click option'
Aimread
Bimshow
Cimwrite
Dresize
Attempts:
3 left
💡 Hint
Common Mistakes
Using imread instead of imshow to display image.
3fill in blank
hard

Fix the error in the code to convert the image to grayscale.

Computer Vision
gray_image = cv2.cvtColor(image, [1])
Drag options to blanks, or click blank then click option'
Acv2.COLOR_BGR2GRAY
Bcv2.COLOR_RGB2BGR
Ccv2.COLOR_BGR2RGB
Dcv2.COLOR_GRAY2BGR
Attempts:
3 left
💡 Hint
Common Mistakes
Using color conversions that do not produce grayscale images.
4fill in blank
hard

Fill both blanks to save the grayscale image to a file and then display it.

Computer Vision
cv2.[1]('gray_sample.jpg', gray_image)
cv2.[2]('Gray Image', gray_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Drag options to blanks, or click blank then click option'
Aimwrite
Bimshow
Cimread
Dresize
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up imread and imwrite functions.
5fill in blank
hard

Fill all three blanks to resize the image to half its size and display it.

Computer Vision
height, width = image.shape[:2]
new_size = (width [1] 2, height [2] 2)
resized_image = cv2.[3](image, new_size)
cv2.imshow('Resized Image', resized_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Drag options to blanks, or click blank then click option'
A//
B/
Cresize
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using float division causing errors in size.
Using wrong function to resize.