0
0
Computer Visionml~10 mins

Edge detection (Canny) 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 using OpenCV.

Computer Vision
import cv2

image = cv2.[1]('image.jpg')
Drag options to blanks, or click blank then click option'
Aimwrite
Bimshow
CcvtColor
Dimread
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.imshow instead of cv2.imread to load the image.
Using cv2.imwrite which saves an image instead of loading.
2fill in blank
medium

Complete the code to convert the image to grayscale.

Computer Vision
gray = cv2.[1](image, cv2.COLOR_BGR2GRAY)
Drag options to blanks, or click blank then click option'
Aimread
BcvtColor
Cblur
Dthreshold
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.imread again instead of converting color.
Using cv2.blur which smooths the image, not changes color.
3fill in blank
hard

Fix the error in the code to apply Canny edge detection.

Computer Vision
edges = cv2.Canny(gray, [1], 150)
Drag options to blanks, or click blank then click option'
A50
B'50'
CNone
Dgray
Attempts:
3 left
💡 Hint
Common Mistakes
Passing threshold as a string instead of integer.
Passing None which causes runtime error.
4fill in blank
hard

Fill both blanks to display the edges image and wait for a key press.

Computer Vision
cv2.[1]('Edges', edges)
cv2.[2](0)
Drag options to blanks, or click blank then click option'
Aimshow
BwaitKey
Cimread
DdestroyAllWindows
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.imread instead of imshow to display.
Forgetting to wait for a key press causing window to close immediately.
5fill in blank
hard

Fill all three blanks to save the edges image, close windows, and print success message.

Computer Vision
cv2.[1]('edges_output.jpg', edges)
cv2.[2]()
print([3])
Drag options to blanks, or click blank then click option'
Aimwrite
BdestroyAllWindows
C'Edges image saved successfully!'
Dimshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using imshow instead of imwrite to save image.
Not closing windows causing program to hang.
Printing without quotes causing error.