Module src.processing.drawing

Drawing functions.

These functions use opencv to draw on the provided frames. For performance, they draw in place, mutating the provided image.

Functions

def draw_fps_counter(img: numpy.ndarray, fps: int) ‑> NoneType

Draws fps counter in the bottom left

Args

fps
rounded down fps estimate
def label_bounding_box(img: numpy.ndarray, text: str, orig: Tuple[int, int]) ‑> NoneType

Draws label with text on bounding box in place.

Calculates size of text, draws a background of textsize and draws the input text over it. Both the drawing of background rectangle and text is done in place.

Args

img
image buffer
text
name of gesture
orig
upper left of hand bounding box
def draw_mode_indicator(img: numpy.ndarray, color: str) ‑> NoneType

Draws circular indicator in place.

Based on input bool it sets color as either green or red and draws a circle in the top left corner in place.

Args

img
Image buffer as numpy array.
color
Color of mode indicator, One of {"BLACK", "BLUE", "WHITE", "RED", "GREEN", "GRAY"}.
def bounding_box(img: numpy.ndarray, landmarks: Iterable[mediapipe.framework.formats.landmark_pb2.NormalizedLandmark], gesture: str, padding: int = 15) ‑> NoneType

Draws bounding box in place.

Takes in keypoints and predicted gesture, creates bounding box around hand with extra padding and draws the estimated gesture. Draws in place

Args

img
Image buffer as numpy array.
landmarks
List of hand landmarks for a single hand.
gesture
Name of gesture.
padding
Extra width and height to add outside the outermost points in landmarks
def draw_landmarks(img: numpy.ndarray, hand_landmarks: Iterable[mediapipe.framework.formats.landmark_pb2.NormalizedLandmark]) ‑> NoneType

Draws landmarks on image in place.

Draws joints as circles and the connection of joints as lines on image in place.

Args

img
image buffer
hand_landmarks
List of hand landmarks for a single hand
def draw_slider(img: numpy.ndarray, bounds: Tuple[float, float], slider_pos: float, slider_val: float, value_text: str, orientation: str = 'VERTICAL', size=20) ‑> NoneType

Draws a slider on the image (in place).

Draws a slider with the value text on the image. Can be oriented either horizontally or vertically. The slider will be 'filled' to the slider_val.

Args

img
Image buffer as a np array.
bounds
Normalized coordinates for the bounds, is treated as x or y coordinates depending on HORIZONTAL or VERTICAL orientation respectively.
slider_val
The normalized coordinate for the current slider value. Note: Normalized on the image
value_text
Text to display.
orientation
Orientation for the slider to be drawn, One of "VERTICAL" | "HORIZONTAL"
size
Width/height in pixels depending on orientation being "VERTICAL" or "HORIZONTAL" respectively.
def draw_func_through_points(img: numpy.ndarray, f: Callable[[float], float], normalized_points: List[Tuple[float, float]]) ‑> NoneType

Draws the function f and the provided points in place.

Draws the provided points on the image. Then draws the function f from min x to max x of the provided points. Assumes that f is defined for [x_min, x_max] of the normalized points.

Args

img
Image buffer as a np array.
f
Function to be drawn/interpolate between the points.
normalized_points
List of normalized points [(x0, y0), (x1, y1), …] Can be unsorted.