opencf.io_handlers package

Submodules

File: img_opencv.py Author: Hermann Agossou Description: This module provides classes for reading and writing images using OpenCV.

class opencf.io_handlers.img_opencv.ImageToOpenCVReader

Bases: FileReader

Reads an image file and returns an OpenCV image object.

_check_input_format(content: ndarray) bool

Validates if the provided content is an OpenCV image object.

Parameters:

content (opencv_image) – The content to be validated.

Returns:

True if the content is an OpenCV image object, False otherwise.

Return type:

bool

_read_content(input_path: Path) ndarray

Reads and returns the content from the given input path as an OpenCV image object.

Parameters:

input_path (Path) – The path to the input image file.

Returns:

The OpenCV image object read from the input file.

Return type:

opencv_image

input_format

alias of ndarray

class opencf.io_handlers.img_opencv.OpenCVToImageWriter

Bases: FileWriter

Writes an OpenCV image object to an image file.

_check_output_format(content) bool

Validates if the provided content is an OpenCV image object.

Parameters:

content – The content to be validated.

Returns:

True if the content is an OpenCV image object, False otherwise.

Return type:

bool

_write_content(output_path: Path, output_content)

Writes the provided OpenCV image object to the given output path as an image file.

Parameters:
  • output_path (Path) – The path to the output image file.

  • output_content – The OpenCV image object to be written to the output file.

Image File I/O Handlers

This module provides classes for reading and writing image files using the Pillow library. It includes abstract base classes and concrete implementations for converting between image files and Pillow Image objects.

class opencf.io_handlers.img_pillow.ImageToPillowReader

Bases: FileReader

Reads an image file and returns a Pillow Image object.

_check_input_format(content: Image) bool

Validates if the provided content is a Pillow Image object.

Parameters:

content (PillowImage.Image) – The content to be validated.

Returns:

True if the content is a Pillow Image object, False otherwise.

Return type:

bool

_read_content(input_path: Path) Image

Reads and returns the content from the given input path as a Pillow Image object.

Parameters:

input_path (Path) – The path to the input image file.

Returns:

The Pillow Image object read from the input file.

Return type:

PillowImage.Image

input_format

alias of Image

class opencf.io_handlers.img_pillow.PillowToImageWriter

Bases: FileWriter

Writes a Pillow Image object to an image file.

_check_output_format(content: Image) bool

Validates if the provided content is a Pillow Image object.

Parameters:

content (PillowImage.Image) – The content to be validated.

Returns:

True if the content is a Pillow Image object, False otherwise.

Return type:

bool

_write_content(output_path: Path, output_content: Image)

Writes the provided Pillow Image object to the given output path as an image file.

Parameters:
  • output_path (Path) – The path to the output image file.

  • output_content (PillowImage.Image) – The Pillow Image object to be written to the output file.

output_format

alias of Image

PDF File I/O Handlers

This module provides classes for reading and writing PDF files using the PyPDF2 library. It includes abstract base classes and concrete implementations for converting between PDF files and PyPDF2 PdfReader objects.

class opencf.io_handlers.pdf.PdfToPyPdfReader

Bases: FileReader

Reads a PDF file and returns a [PyPDF2 PdfReader object](https://pypdf2.readthedocs.io/en/3.0.0/modules/PdfReader.html).

_check_input_format(content: PdfReader) bool

Validates if the provided content is a PyPDF2 PdfReader object.

Parameters:

content (PdfReader) – The content to be validated.

Returns:

True if the content is a PyPDF2 PdfReader object, False otherwise.

Return type:

bool

_read_content(input_path: Path) PdfReader

Reads and returns the content from the given input path as a PyPDF2 PdfReader object.

Parameters:

input_path (Path) – The path to the input PDF file.

Returns:

The PyPDF2 PdfReader object read from the input file.

Return type:

PdfReader

input_format

alias of PdfReader

class opencf.io_handlers.pdf.PyPdfToPdfWriter

Bases: FileWriter

Writes the provided [PyPDF2 PdfWriter object](https://pypdf2.readthedocs.io/en/3.0.0/modules/PdfWriter.html)

_check_output_format(content: PdfWriter) bool

Validates if the provided content is a PyPDF2 PdfWriter object.

Parameters:

content (PdfWriter) – The content to be validated.

Returns:

True if the content is a PyPDF2 PdfWriter object, False otherwise.

Return type:

bool

_write_content(output_path: Path, output_content: PdfWriter)

Writes the provided PyPDF2 PdfWriter object to the given output path as a PDF file.

Parameters:
  • output_path (Path) – The path to the output PDF file.

  • output_content (PdfWriter) – The PyPDF2 PdfWriter object to be written to the output file.

output_format

alias of PdfWriter

Spreadsheet I/O Handlers

This module provides classes for reading and writing spreadsheet files using the pandas library. It includes abstract base classes and concrete implementations for converting between spreadsheet files and pandas DataFrame objects.

class opencf.io_handlers.spreadsheet.PandasToSpreadsheetWriter

Bases: FileWriter

Writes a pandas DataFrame object to a spreadsheet file.

_check_output_format(content: DataFrame) bool

Validates if the provided content is a pandas DataFrame object.

Parameters:

content (pd.DataFrame) – The content to be validated.

Returns:

True if the content is a pandas DataFrame object, False otherwise.

Return type:

bool

_write_content(output_path: Path, output_content: DataFrame)

Writes the provided pandas DataFrame object to the given output path as a spreadsheet file.

Parameters:
  • output_path (Path) – The path to the output spreadsheet file.

  • output_content (pd.DataFrame) – The pandas DataFrame object to be written to the output file.

output_format

alias of DataFrame

class opencf.io_handlers.spreadsheet.SpreadsheetToPandasReader

Bases: FileReader

Reads a spreadsheet file and returns a pandas DataFrame object.

_check_input_format(content: DataFrame) bool

Validates if the provided content is a pandas DataFrame object.

Parameters:

content (pd.DataFrame) – The content to be validated.

Returns:

True if the content is a pandas DataFrame object, False otherwise.

Return type:

bool

_read_content(input_path: Path) DataFrame

Reads and returns the content from the given input path as a pandas DataFrame object.

Parameters:

input_path (Path) – The path to the input spreadsheet file.

Returns:

The pandas DataFrame object read from the input file.

Return type:

pd.DataFrame

input_format

alias of DataFrame

class opencf.io_handlers.video.FramesToGIFWriterWithImageIO

Bases: FileWriter

Writes a list of frames to a GIF file using imageio.

_check_output_format(content) bool

Validates if the provided content is a list of frames.

Parameters:

content – The content to be validated.

Returns:

True if the content is a list of frames, False otherwise.

Return type:

bool

_write_content(output_gif: Path, frames: List[Mat | ndarray])

Writes the provided list of frames to the given output GIF file.

Parameters:
  • output_gif (Path) – The path to the output GIF file.

  • frames (List[MatLike]) – The list of frames to be written to the GIF file.

class opencf.io_handlers.video.VideoArrayWriter

Bases: FileWriter

Writes a video to a file using a list of image arrays.

_check_output_format(content) bool

Validates if the provided content is suitable for writing as a video.

Parameters:

content – Content to be validated.

Returns:

True if the content is suitable for writing as a video, False otherwise.

Return type:

bool

_write_content(output_path: Path, output_content: ndarray | list, fps: int = 15) bool

Writes a video to a file using a list of image arrays.

Parameters:
  • output_path (Path) – Path to save the video.

  • output_content (Union[np.ndarray, list]) – Video frames as a numpy array or a list of numpy arrays.

  • fps (int, optional) – Frames per second. Defaults to 15.

Returns:

True if the video is successfully written, False otherwise.

Return type:

bool

class opencf.io_handlers.video.VideoToFramesReaderWithOpenCV

Bases: FileReader

Reads a video file and returns a list of frames in MatLike format.

_check_input_format(content: List[Mat | ndarray]) bool

Validates if the provided content is a list of MatLike objects.

Parameters:

content (List[MatLike]) – The content to be validated.

Returns:

True if the content is a list of MatLike objects, False otherwise.

Return type:

bool

_read_content(input_path: Path) List[Mat | ndarray]

Reads and returns the frames from the given video file as a list of MatLike objects.

Parameters:

input_path (Path) – The path to the input video file.

Returns:

A list containing frames read from the video file.

Return type:

List[MatLike]

input_format

alias of List[Union[Mat, ndarray]]

Module contents