drawController
index
/home/bedrock/Desktop/project/AlertWatch/Production/detector/drawUtil/drawController.py

Drawing Utilities for Video Frames
 
This module provides utility functions for annotating video frames with various information,
including bounding boxes, text, landmarks, head pose, and performance metrics like FPS.
 
Functions:
    - draw_bounding_box: Draws a bounding box with a detection score on the frame.
    - draw_text: Displays text at a specific location on the frame.
    - draw_landmarks: Draws detected landmarks on the frame.
    - draw_head_pose: Visualizes head pose using 3D axes on the frame. (unused)
    - display_fps: Displays current and average FPS on the frame.
    - display_blink_info: Displays blink-related information on the frame.
 
Dependencies:
    - OpenCV (cv2): For image processing and drawing operations.
    - NumPy: For numerical computations and matrix manipulations.
    - datetime: For timestamping frames.
 
Usage:
    Import the module and use the functions to annotate video frames during real-time video processing.
 
Author:
Lior Jigalo
 
License:
    MIT

 
Modules
       
cv2
datetime
numpy

 
Functions
       
display_blink_info(frame, blink_count, total_blinks, blink_durations) -> None
Displays blink count and average blink duration on the frame.
 
Args:
    frame (np.ndarray): The video frame to annotate.
    blink_count (int): Number of blinks detected in the current session.
    total_blinks (int): Total number of blinks detected.
    blink_durations (list of float): List of blink durations in seconds.
display_fps(frame, fps, avg_fps) -> None
Displays current and average FPS on the frame.
 
Args:
    frame (np.ndarray): The video frame to annotate.
    fps (float): Current frames per second.
    avg_fps (float): Average frames per second.
draw_bounding_box(frame, score, p1, p2, color=(0, 255, 0), size=2) -> None
Draws a bounding box with the detection confidence score.
 
Args:
    frame (np.ndarray): The video frame to annotate.
    score (float): Confidence score of the detection.
    p1 (tuple): Top-left corner of the bounding box (x, y).
    p2 (tuple): Bottom-right corner of the bounding box (x, y).
    color (tuple): Color of the bounding box in BGR format (default: green).
    size (int): Thickness of the bounding box (default: 2).
draw_head_pose(frame, rotation_vector, translation_vector, camera_matrix) -> cv2.Mat | numpy.ndarray
Visualizes head pose using 3D axes projected onto the frame.
 
Args:
    frame (np.ndarray): The video frame to annotate.
    rotation_vector (np.ndarray): Rotation vector of the head pose.
    translation_vector (np.ndarray): Translation vector of the head pose.
    camera_matrix (np.ndarray): Camera matrix for the projection.
 
Returns:
    np.ndarray: The annotated video frame.
draw_landmarks(frame, all_landmarks) -> None
Draws detected landmarks as points on the frame.
 
Args:
    frame (np.ndarray): The video frame to annotate.
    all_landmarks (list of list of tuple): List of detected landmarks, where each landmark
        is represented as a list of (x, y) coordinates.
draw_text(cv2, frame, offset, text, color, size=0.6)
Draws text on the frame at a specific vertical offset.
 
Args:
    frame (np.ndarray): The video frame to annotate.
    offset (int): Vertical offset from the top of the frame.
    text (str): The text to display.
    color (tuple): Color of the text in BGR format.
    size (float): Font scale of the text (default: 0.6).