nnspike.utils.image

This module provides utility functions for image and video processing using OpenCV and NumPy.

Functions:
normalize_image(image: np.ndarray) -> np.ndarray:

Normalize an input image by converting its color space, applying Gaussian blur, resizing, and scaling pixel values.

draw_driving_info(image: np.ndarray, info: dict, roi: tuple[int, int, int, int]) -> np.ndarray:

Draws driving information on an image by overlaying a tracing point, a region of interest (ROI) rectangle, and various text annotations based on the provided info dictionary.

extract_video_frames(video_path: str, frame_path: str) -> None:

Extracts frames from a video file and saves them as individual image files in the specified directory.

Functions

draw_driving_info(image, info, roi)

Draws driving information on an image.

normalize_image(image)

Normalize an input image by converting its color space, applying Gaussian blur, resizing, and scaling pixel values.

nnspike.utils.image.normalize_image(image)[source]

Normalize an input image by converting its color space, applying Gaussian blur, resizing, and scaling pixel values.

This function performs the following steps: 1. Converts the image from RGB to YUV color space. 2. Applies a Gaussian blur with a kernel size of 5x5. 3. Resizes the image to dimensions 200x66. 4. Scales the pixel values to the range [0, 1].

Parameters:

image (np.ndarray) – Input image in RGB format as a NumPy array.

Returns:

Normalized image as a NumPy array.

Return type:

np.ndarray

nnspike.utils.image.draw_driving_info(image, info, roi)[source]

Draws driving information on an image.

This function overlays driving-related information onto a given image. It draws a tracing point, a region of interest (ROI) rectangle, and various text annotations based on the provided info dictionary.

Parameters:
  • image (np.ndarray) – The input image on which to draw the information.

  • info (dict) –

    A dictionary containing the driving information to be displayed. Expected keys are:

    • ”trace_x” (int or str): The x-coordinate for the tracing point.

    • ”trace_y” (int or str): The y-coordinate for the tracing point.

    • ”text” (dict): A dictionary of text annotations where keys are the labels and values are the corresponding data.

  • roi (tuple[int, int, int, int]) – A tuple defining the region of interest in the format (x1, y1, x2, y2).

Returns:

The image with the overlaid driving information.

Return type:

np.ndarray