putText renders text onto an OpenCV image at a chosen position, using a selected font, scale, and color. It adds labels to drawn images and camera frames. section 8.3.2 section 8.3.3
Render text on a drawn image
Create a 640×480 image, then draw the lowercase alphabet in red with FONT_HERSHEY_SIMPLEX at position (10, 380): cv2.putText(img, text, org=pos, fontFace=font, fontScale=1, color=RED). Display the result with imshow and wait for a key press. section 8.3.2
Display a temporary camera message
A snapshot application stores a message and overlays it on the live frame for ten frames: cv2.putText(frame, messages.pop(), TEXT_POS, FONT, 1, BLUE). This displays “saving photo...” after the spacebar triggers a snapshot. section 8.3.3
text = string.ascii_lowercase font = cv2.FONT_HERSHEY_SIMPLEX pos = (10, 380) cv2.putText(img, text, org=pos, fontFace=font, fontScale=1, color=RED)
Inspect the complete text-rendering call with its alphabet, font, position, scale, and color values. section 8.3.2
def show_image(frame, messages):
if messages:
cv2.putText(frame, messages.pop(), TEXT_POS, FONT, 1, BLUE)
cv2.imshow('preview', frame)
Inspect the reusable show_image function that overlays queued messages before displaying camera frames. section 8.3.3
