Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using imshow instead of imread to load image.
✗ Incorrect
The function cv2.imread loads an image from a file into memory.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using imread instead of imshow to display image.
✗ Incorrect
The function cv2.imshow shows the image in a window with a given title.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using color conversions that do not produce grayscale images.
✗ Incorrect
To convert a color image to grayscale, use cv2.COLOR_BGR2GRAY.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up imread and imwrite functions.
✗ Incorrect
cv2.imwrite saves an image to a file, and cv2.imshow displays it.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using float division causing errors in size.
Using wrong function to resize.
✗ Incorrect
Use integer division // to get new dimensions and cv2.resize to resize the image.