Drawing on Video Frames
Adding annotations, overlays, and graphics to video frames.
6 min•By Priygop Team•Updated 2026
Annotations and Overlays
Annotations and Overlays
import cv2
import numpy as np
import time
def annotate_video_frame(frame, frame_num, fps, extra_text=""):
"""Add standard annotations to a video frame."""
h, w = frame.shape[:2]
overlay = frame.copy()
# Semi-transparent top bar
cv2.rectangle(overlay, (0, 0), (w, 50), (0, 0, 0), -1)
cv2.addWeighted(overlay, 0.6, frame, 0.4, 0, frame)
# Frame number and FPS
timestamp = f"Frame: {frame_num:04d} | FPS: {fps:.1f}"
cv2.putText(frame, timestamp, (10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 255), 1)
# Extra text in top-right
if extra_text:
text_size = cv2.getTextSize(extra_text, cv2.FONT_HERSHEY_SIMPLEX, 0.6, 1)[0]
cv2.putText(frame, extra_text, (w - text_size[0] - 10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 255), 1)
# Crosshair at centre
cx, cy = w // 2, h // 2
cv2.line(frame, (cx-20, cy), (cx+20, cy), (255, 255, 255), 1)
cv2.line(frame, (cx, cy-20), (cx, cy+20), (255, 255, 255), 1)
return frame
# Usage in video loop:
# annotated = annotate_video_frame(frame, frame_count, current_fps, "RECORDING")
print("Annotation function ready for use in video pipeline")Diagram
Loading diagram…
Machine Learning follows a structured pipeline from data to deployment