0
0
Computer Visionml~10 mins

Drawing on images (lines, rectangles, circles, text) 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 draw a blue line on the image.

Computer Vision
import cv2
import numpy as np

img = np.zeros((200, 200, 3), dtype=np.uint8)
cv2.line(img, (10, 10), (190, 10), [1], 3)
cv2.imwrite('line.png', img)
Drag options to blanks, or click blank then click option'
A(0, 0, 255)
B(255, 0, 0)
C(255, 255, 0)
D(0, 255, 0)
Attempts:
3 left
💡 Hint
Common Mistakes
Using RGB color instead of BGR.
Confusing blue with red color values.
2fill in blank
medium

Complete the code to draw a filled green rectangle on the image.

Computer Vision
import cv2
import numpy as np

img = np.zeros((200, 200, 3), dtype=np.uint8)
cv2.rectangle(img, (50, 50), (150, 150), [1], -1)
cv2.imwrite('rectangle.png', img)
Drag options to blanks, or click blank then click option'
A(0, 255, 255)
B(0, 0, 255)
C(255, 0, 0)
D(0, 255, 0)
Attempts:
3 left
💡 Hint
Common Mistakes
Using RGB color instead of BGR.
Using positive thickness instead of -1 for filled shapes.
3fill in blank
hard

Fix the error in the code to draw a red circle on the image.

Computer Vision
import cv2
import numpy as np

img = np.zeros((200, 200, 3), dtype=np.uint8)
cv2.circle(img, (100, 100), 50, [1], 5)
cv2.imwrite('circle.png', img)
Drag options to blanks, or click blank then click option'
A(0, 0, 255)
B(255, 0, 0)
C(0, 255, 0)
D(255, 255, 255)
Attempts:
3 left
💡 Hint
Common Mistakes
Using RGB color instead of BGR.
Using wrong color tuple causing unexpected colors.
4fill in blank
hard

Fill both blanks to draw white text on the image at position (50, 180).

Computer Vision
import cv2
import numpy as np

img = np.zeros((200, 200, 3), dtype=np.uint8)
cv2.putText(img, 'Hello', (50, 180), [1], 1, [2], 2)
cv2.imwrite('text.png', img)
Drag options to blanks, or click blank then click option'
Acv2.FONT_HERSHEY_SIMPLEX
B(255, 255, 255)
C(0, 0, 0)
Dcv2.LINE_AA
Attempts:
3 left
💡 Hint
Common Mistakes
Using black color instead of white for text.
Using invalid font constants.
5fill in blank
hard

Fill all three blanks to draw a green circle with thickness 3 and anti-aliased line.

Computer Vision
import cv2
import numpy as np

img = np.zeros((300, 300, 3), dtype=np.uint8)
cv2.circle(img, (150, 150), 75, [1], [2], [3])
cv2.imwrite('circle_aa.png', img)
Drag options to blanks, or click blank then click option'
A(0, 255, 0)
B3
Ccv2.LINE_AA
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong color format.
Using thickness 5 instead of 3.
Omitting anti-aliasing flag.