Skip to main content

Crate edgefirst_image

Crate edgefirst_image 

Source
Expand description

§EdgeFirst HAL - Image Converter

The edgefirst_image crate is part of the EdgeFirst Hardware Abstraction Layer (HAL) and provides functionality for converting images between different formats and sizes. The crate is designed to work with hardware acceleration when available, but also provides a CPU-based fallback for environments where hardware acceleration is not present or not suitable.

The main features of the edgefirst_image crate include:

  • Support for various image formats, including YUYV, RGB, RGBA, and GREY.
  • Support for source crop, destination crop, rotation, and flipping.
  • Image conversion using hardware acceleration (G2D, OpenGL) when available.
  • CPU-based image conversion as a fallback option.

The crate uses TensorDyn from edgefirst_tensor to represent images, with PixelFormat metadata describing the pixel layout. The ImageProcessor struct manages the conversion process, selecting the appropriate conversion method based on the available hardware.

§Examples

let image = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../testdata/zidane.jpg"));
let src = load_image(image, Some(PixelFormat::Rgba), None)?;
let mut converter = ImageProcessor::new()?;
let mut dst = converter.create_image(640, 480, PixelFormat::Rgb, DType::U8, None)?;
converter.convert(&src, &mut dst, Rotation::None, Flip::None, Crop::default())?;

§Environment Variables

The behavior of the edgefirst_image::ImageProcessor struct can be influenced by the following environment variables:

  • EDGEFIRST_FORCE_BACKEND: When set to cpu, g2d, or opengl (case-insensitive), only that single backend is initialized and no fallback chain is used. If the forced backend fails to initialize, an error is returned immediately. This is useful for benchmarking individual backends in isolation. When this variable is set, the EDGEFIRST_DISABLE_* variables are ignored.
  • EDGEFIRST_DISABLE_GL: If set to 1, disables the use of OpenGL for image conversion, forcing the use of CPU or other available hardware methods.
  • EDGEFIRST_DISABLE_G2D: If set to 1, disables the use of G2D for image conversion, forcing the use of CPU or other available hardware methods.
  • EDGEFIRST_DISABLE_CPU: If set to 1, disables the use of CPU for image conversion, forcing the use of hardware acceleration methods. If no hardware acceleration methods are available, an error will be returned when attempting to create an ImageProcessor.

Additionally the TensorMemory used by default allocations can be controlled using the EDGEFIRST_TENSOR_FORCE_MEM environment variable. If set to 1, default tensor memory uses system memory. This will disable the use of specialized memory regions for tensors and hardware acceleration. However, this will increase the performance of the CPU converter.

Structs§

CPUProcessor
CPUConverter implements the ImageProcessor trait using the fallback CPU implementation for image processing.
Crop
ImageProcessor
Image converter that uses available hardware acceleration or CPU as a fallback.
ImageProcessorConfig
Configuration for ImageProcessor construction.
MaskRegion
Region metadata for a single detection within a compact mask atlas.
Rect

Enums§

ComputeBackend
Compute backend selection for ImageProcessor.
Error
Flip
Rotation

Traits§

ImageProcessorTrait

Functions§

load_image
Load an image from raw bytes (JPEG or PNG) and return a TensorDyn.
save_jpeg
Save a TensorDyn image as a JPEG file.

Type Aliases§

Result