ntt.frames package#
Submodules#
ntt.frames.display module#
- ntt.frames.display.display_frame(frame: ndarray) None#
- ntt.frames.display.display_video_as_frames(video: list | None = None) None#
ntt.frames.exif module#
EXIF metadata extraction and injection for images.
Two extraction backends are provided with the same interface:
extract_exif_pillow– uses Pillow (built-in EXIF support via _getexif)extract_exif_exifread– uses ExifRead (richer tag coverage, raw strings)
One injection function:
inject_exif– embeds a metadata dict into a JPEG file (pure stdlib, no piexif)
All functions:
- Accept an image file path (JPEG, TIFF for extraction; JPEG only for injection).
- Raise FileNotFoundError if the file does not exist.
- ntt.frames.exif.extract_exif_exifread(image_path: str) dict#
Extract EXIF metadata from an image using ExifRead.
- Parameters:
image_path (str) – Path to the image file.
- Returns:
- Mapping of tag keys (e.g.
"Image Make") to string values, or
{}if no EXIF is present.
- Mapping of tag keys (e.g.
- Return type:
dict
- Raises:
FileNotFoundError – If the file does not exist.
- ntt.frames.exif.extract_exif_pillow(image_path: str) dict#
Extract EXIF metadata from an image using Pillow.
- Parameters:
image_path (str) – Path to the image file.
- Returns:
Mapping of EXIF tag names to values, or
{}if no EXIF is present.- Return type:
dict
- Raises:
FileNotFoundError – If the file does not exist.
- ntt.frames.exif.inject_exif(image_path: str, metadata: dict) None#
Embed EXIF metadata into a JPEG file (in-place).
Supports ASCII string tags: ImageDescription, Make, Model, Software, DateTime, Artist, Copyright.
Per the TIFF spec, ASCII values whose byte count (including null terminator) fits in 4 bytes are stored inline in the IFD entry value field; longer values are stored in a separate data area and referenced by offset.
- Parameters:
image_path (str) – Path to the JPEG file to modify.
metadata (dict) – Tag name to string value mapping. Unknown keys are silently ignored.
- Raises:
FileNotFoundError – If the file does not exist.
ValueError – If the file is not a JPEG.
ntt.frames.frame_crop module#
- ntt.frames.frame_crop.crop(image: ndarray, x1: int, y1: int, x2: int, y2: int) ndarray#
Crops an image given 2 points (top left and bottom right)
- Parameters:
image (np.ndarray) – the image to crop
x1 (int) – top left x coordinate
y1 (int) – top left y coordinate
x2 (int) – bottom right x coordinate
y2 (int) – bottom right y coordinate
- Raises:
ValueError – if the coordinates are out of bounds
- Returns:
the cropped image
- Return type:
np.ndarray
ntt.frames.frame_extraction module#
- ntt.frames.frame_extraction.compare_frames(video_path, frame_number)#
This function compares the frames extracted by extract_frame_ffmpeg and extract_frame_opencv
- Parameters:
video_path (string) – path to the folder conataining the input video
frame_number (int) – the number of the frame to extract.
- Returns:
True if all pixels are alike between frame_opencv and frame_ffmpeg else False
- Return type:
Boolean
- ntt.frames.frame_extraction.extract_first_frame(video_path_in: str, video_name_in: str, frame_path_out: str, frame_name_out: str, video_URL=None) str#
This function extracts the first frame of a given video.
- Parameters:
video_path_in (string) – path to the folder conataining the input video
video_name_in (string) – name of the input video
frame_path_out (string) – path to the folder conataining the output frame
frame_name_out (string) – name of the output frame
video_URL (string, optional) – URL of the video if it is not stored locally
- Returns:
full path of the output frame
- Return type:
string
- ntt.frames.frame_extraction.extract_frame_ffmpeg(video_path, frame_number)#
Extracts a frame given its number from a video with ffmpeg
- Parameters:
video_path (string) – path to the folder conataining the input video
frame_number (int) – the number of the frame to extract.
- Returns:
the frame with number = frame_number
- Return type:
np.ndarray
- ntt.frames.frame_extraction.extract_frame_opencv(video_path, frame_number=1)#
Extracts a frame given its number from a video with opencv
- Parameters:
video_path (string) – path to the folder conataining the input video
frame_number (int, optional) – the number of the frame to extract. Defaults to 1.
- Returns:
the frame with number = frame_number
- Return type:
np.ndarray
- ntt.frames.frame_extraction.extract_last_frame(video_path_in: str, video_name_in: str, frame_path_out: str, frame_name_out: str, video_URL=None) str#
Extracts the last frame of a given video.
- Parameters:
video_path_in (string) – path to the folder conataining the input video
video_name_in (string) – name of the input video
frame_path_out (string) – path to the folder conataining the output frame
frame_name_out (string) – name of the output frame
video_URL (string, optional) – URL of the video if it is not stored locally
- Returns:
full path of the output frame
- Return type:
string
- ntt.frames.frame_extraction.extract_nth_frame(video_path_in: str, video_name_in: str, frame_path_out: str, frame_name_out: str, nth_frame=0, video_URL=None) str#
This function extracts the nth frame of a given video.
- Parameters:
video_path_in (string) – path to the folder conataining the input video
video_name_in (string) – name of the input video
frame_path_out (string) – path to the folder conataining the output frame
frame_name_out (string) – name of the output frame
nth_frame (int) – the number of the frame to be extracted
video_URL (string, optional) – URL of the video if it is not stored locally
- Returns:
full path of the output frame
- Return type:
string
ntt.frames.frame_generation module#
- ntt.frames.frame_generation.empty_frame(width: int, height: int, nb_colors=3) ndarray#
Return a black frame (all zeros).
- Parameters:
width (int) – Frame width in pixels.
height (int) – Frame height in pixels.
nb_colors (int) – Number of color channels. Defaults to 3 (BGR).
- Returns:
Zero-filled array of shape (height, width, nb_colors).
- Return type:
np.ndarray
- ntt.frames.frame_generation.frame_from_image_file(image_path: str) ndarray#
- ntt.frames.frame_generation.full_frame(width: int, height: int, color: tuple) ndarray#
Return a frame filled with a solid color.
- Parameters:
width (int) – Frame width in pixels.
height (int) – Frame height in pixels.
color (tuple) – BGR color tuple, e.g.
(255, 0, 0)for blue.
- Returns:
Constant-color array of shape (height, width, 3).
- Return type:
np.ndarray
- ntt.frames.frame_generation.number_frame(width: int, height: int, number=123) ndarray#
- ntt.frames.frame_generation.random_frame(width: int = 640, height: int = 480) ndarray#
Return a frame filled with random pixel values.
- Parameters:
width (int) – Frame width in pixels. Defaults to 640.
height (int) – Frame height in pixels. Defaults to 480.
- Returns:
Random uint8 array of shape (height, width, 3).
- Return type:
np.ndarray
ntt.frames.frame_loading module#
ntt.frames.frame_overlay module#
- ntt.frames.frame_overlay.overlay_n_frames(path_frames, frames, opacities, path_output_frame)#
- ntt.frames.frame_overlay.overlay_two_frames(path_frames, name_frame1, name_frame2, opacities, path_output_frame)#
ntt.frames.n_frame_extraction module#
- ntt.frames.n_frame_extraction.extract_frame_opencv(video_path, frame_number)#
This function extracts a frame given its number from a video with opencv
- Parameters:
video_path (string) – path to the folder conataining the input video
frame_number (int, optional) – the number of the frame to extract. Defaults to 1.
- Returns:
the frame with number = frame_number
- Return type:
np.ndarray
- ntt.frames.n_frame_extraction.extract_n_frame(video_path_in, video_name_in, n)#
This function extracts the nth frame of a given video.
- Parameters:
video_path_in (string) – path to the folder conataining the input video
video_name_in (string) – name of the input video
n (int) – the number of the frame to be extracted
- Returns:
full path of the output frame
- Return type:
string
ntt.frames.processing module#
- ntt.frames.processing.blur_frame(frame, kernel_size=(5, 5), region=None)#
Apply Gaussian blur to a frame (NumPy array).
- Parameters:
frame (numpy.ndarray) – Input frame as a NumPy array.
kernel_size (tuple) – Size of the Gaussian kernel for blurring.
region (tuple) – Region of interest (x, y, width, height) to blur. If None, the entire frame will be blurred.
- Returns:
Blurred frame as a NumPy array.
- Return type:
numpy.ndarray
- ntt.frames.processing.experiment_blur()#
- ntt.frames.processing.rotate(frame, angle)#
- ntt.frames.processing.translate_horizontally(frame, translation_rate)#
- ntt.frames.processing.translate_vertically(frame, translation_rate)#