Classes

Class ColorConverter

class ColorConverter : public tcim::ImageOps::ImageRunner

A class for converting images from YUV420SP, YUV422SP, or YUV444SP format to RGB Planar format.

Data Types

struct Option

struct Option {
  Option(tcim::DataFmt fmt = tcim::DataFmt::YUV422SP, int dev_id = 0)
  Option& SetMaxSize(int64_t w, int64_t h)
  tcim::DataFmt fmt;
  int64_t device_id = 0;
  int64_t max_w = 1920;
  int64_t max_h = 1080;
};
struct Option

Struct describing the configurations for initializing a ColorConverter object.

Public Functions

inline Option(tcim::DataFmt fmt = tcim::DataFmt::YUV422SP, int dev_id = 0)

Constructs an Option object.

Parameters:
  • fmt -- [in] The format of the YUV image, defined in DataFmt.

  • dev_id -- [in] The logical ID of the Houmo device used for image format conversion. The device 0 is used by default. You can retrieve the logical device IDs via SMI tool. See "SMI Tool User Guide" for details.

inline Option &SetMaxSize(int64_t w, int64_t h)

Sets the maximum width and height of the input image.

Parameters:
  • w -- [in] Maximum width of the input image.

  • h -- [in] Maximum height of the input image.

Returns:

Reference to the current Option object.

Public Members

int64_t device_id = 0

The logical ID of the Houmo device used for image format conversion.

tcim::DataFmt fmt

The input image format.

int64_t max_h = 1080

The maximum height of the input image.

int64_t max_w = 1920

The maximum width of the input image.

Functions

ColorConverter

tcim::ImageOps::ColorConverter::ColorConverter()

Default constructor.

~ColorConverter

virtual tcim::ImageOps::ColorConverter::~ColorConverter()

ColorConverter destructor.

GetInputNum

virtual size_t tcim::ImageOps::ColorConverter::GetInputNum() override

Retrieves the total number of input tensors.

Returns:

Returns the total number of input tensors.

GetInputTensor

virtual tcim::Tensor &tcim::ImageOps::ColorConverter::GetInputTensor(size_t indx) override

Retrieves input tensor with given index.

Parameters:

indx -- [in] The index of the input tensor.

Returns:

A reference to the input tensor at the specified index.

GetOutputNum

virtual size_t tcim::ImageOps::ColorConverter::GetOutputNum() override

Retrieves the total number of output tensors.

Returns:

Returns the total number of output tensors.

GetOutputTensor

virtual tcim::Tensor &tcim::ImageOps::ColorConverter::GetOutputTensor(size_t indx) override

Retrieves output tensor with given index.

Parameters:

indx -- [in] The index of the output tensor.

Returns:

A reference to the output tensor at the specified index.

GetStream

virtual tcim::Stream &tcim::ImageOps::ColorConverter::GetStream() override

Retrieves the stream used for image format conversion.

Returns:

A reference to the stream object.

Init

virtual Status tcim::ImageOps::ColorConverter::Init(const Option &option = Option())

Initializes the ColorConverter object with the provided configuration.

Parameters:

option -- [in] Configuration for the image format conversion.

Returns:

Returns the status of the constructor function.

Note

You must call this function before image format conversion.

Run

Status tcim::ImageOps::ColorConverter::Run(const tcim::Tensor &input, tcim::Tensor &output, bool sync = false)

Converts images from YUV420SP, YUV422SP, or YUV444SP format to RGB Planar format.

Parameters:
  • input -- [in] The input tensor containing the image in YUV format. This tensor can be stored either on host or Houmo device memory.

  • output -- [out] The output tensor where the converted RGB Planar image will be stored. This tensor can be stored either on host or Houmo device memory.

  • sync -- [in] A flag to indicate if to automatically synchronize the stream. If set to true, this function will wait for all tasks related to format conversion in the stream to complete before returning. If set to false, this function will be executed asynchronously, returning immediately without waiting.

Returns:

Returns the status of the constructor function.

SetStream

virtual Status tcim::ImageOps::ColorConverter::SetStream(tcim::Stream &stream) override

Sets the stream used for image format conversion.

Parameters:

stream -- [in] A reference to the stream used for image format conversion.

Returns:

Returns the status of the function call.

Sync

virtual Status tcim::ImageOps::ColorConverter::Sync() override

Synchronizes the stream, ensuring that all tasks in the stream are completed.

Returns:

Returns the status of the function call.

Class Config

class Config

Manages global configuration settings for image processing operations.

Functions

Global

static Config &tcim::ImageOps::Config::Global()

Retrieves the global configuration object.

Returns:

A reference to the global Config object.

GetDirPath

std::string tcim::ImageOps::Config::GetDirPath() const

Retrieves the directory path configured for the image processing configuration files.

Returns:

The directory path as a string.

SetDirPath

Config &tcim::ImageOps::Config::SetDirPath(const std::string &path)

Sets the directory path for image processing configuration files.

TCIM provides configurations files for image processing. By default, these files are located in:

  • /usr/local/houmo/data within the software platform in the provided Docker image.

  • ${PATH}/houmo-tcim-runtime_<release>_${distro}_$arch/houmo-tcim-runtime/data within the TCIM runtime software package.

Parameters:

path -- [in] The directory path where the configuration files are stored.

Returns:

A reference to the Config object.

Note

The directory path to the configuration files must be set before processing images.

SetEnvName

Config &tcim::ImageOps::Config::SetEnvName(const std::string &env_name)

Sets the environment variable name used to specify the directory path for image processing configuration files.

Parameters:

env_name -- [in] The environment variable name.

Returns:

A reference to the Config object.

Config

tcim::ImageOps::Config::Config() = default

Class ImageRunner

class ImageRunner

A class to provide base APIs for image processing operations.

Subclassed by tcim::ImageOps::ColorConverter, tcim::ImageOps::Resizer

Functions

GetInputNum

virtual size_t tcim::ImageOps::ImageRunner::GetInputNum() = 0

Retrieves the total number of input tensors.

Returns:

Returns the total number of input tensors.

GetInputTensor

virtual tcim::Tensor &tcim::ImageOps::ImageRunner::GetInputTensor(size_t indx) = 0

Retrieves input tensor with given index.

Parameters:

indx -- [in] The index of the input tensor.

Returns:

A reference to the input tensor at the specified index.

GetOutputNum

virtual size_t tcim::ImageOps::ImageRunner::GetOutputNum() = 0

Retrieves the total number of output tensors.

Returns:

Returns the total number of output tensors.

GetOutputTensor

virtual tcim::Tensor &tcim::ImageOps::ImageRunner::GetOutputTensor(size_t indx) = 0

Retrieves output tensor with given index.

Parameters:

indx -- [in] The index of the output tensor.

Returns:

A reference to the output tensor at the specified index.

GetStream

virtual tcim::Stream &tcim::ImageOps::ImageRunner::GetStream() = 0

Retrieves the stream used for image processing operations.

Returns:

A reference to the stream object.

SetStream

virtual Status tcim::ImageOps::ImageRunner::SetStream(tcim::Stream &stream) = 0

Sets the stream used for image processing operations.

Parameters:

stream -- [in] A reference to the stream used for image processing operations.

Returns:

Returns the status of the function call.

Sync

virtual Status tcim::ImageOps::ImageRunner::Sync() = 0

Synchronizes the stream, ensuring that all tasks in the stream are completed.

Returns:

Returns the status of the function call.

Class Resizer

class Resizer : public tcim::ImageOps::ImageRunner

A class for image processing operations including cropping, resizing, padding, and implementation with multiple interpolation modes.

Data Types

struct Option

struct Option {
  tcim::DataFmt format;
  int64_t max_w = 1920;
  int64_t max_h = 1080;
  int64_t device_id;
  int device_id = 0;
  explicit Option(tcim::DataFmt fmt = tcim::DataFmt::YUV422SP, int dev_id = 0)
  Option& SetMaxSize(int64_t w, int64_t h)
};
struct Option

Struct describing the configurations for initializing a Resizer object.

Public Functions

inline explicit Option(tcim::DataFmt fmt = tcim::DataFmt::YUV422SP, int dev_id = 0)

Constructs an Option object.

Parameters:
  • fmt -- [in] The input format of the YUV image, defined in DataFmt.

  • dev_id -- [in] The logical ID of the Houmo device used for image processing. The device 0 is used by default. You can retrieve the logical device IDs via SMI tool. See "SMI Tool User Guide" for details.

inline Option &SetMaxSize(int64_t w, int64_t h)

Sets the maximum width and height of the output image.

Parameters:
  • w -- [in] Maximum width of the output image.

  • h -- [in] Maximum height of the output image.

Returns:

Reference to the current Option object.

Public Members

int64_t device_id

The logical ID of the Houmo device used for image processing.

tcim::DataFmt format

The input data format.

int64_t max_h = 1080

The maximum height of output.

int64_t max_w = 1920

The maximum width of output.

struct RunOption

struct Option {
  RectRoi crop;
  RectPad pad;
  EnInterpMode interp_mode;
  EnAlignMode align_mode;
  std::array<int32_t, 3> pad_val = {0, 128, 128};
  RunOption() = delete;
  explicit RunOption(const RectRoi& roi, const RectPad& pad = {0, 0, 0, 0},
                     EnInterpMode interp_mod = EnInterpMode::Bilinear,
                     EnAlignMode align_mod = EnAlignMode::AlignCornerFalse)
  RunOption& SetCrop(RectRoi& roi)
  RunOption& SetPad(RectPad& padsz)
  RunOption& SetPadVal(const std::array<int32_t, 3>& val)
};
struct RunOption

Struct describing the runtime options for image processing operations including resizing, cropping, padding, and interpolation.

Public Functions

inline explicit RunOption(const RectRoi &roi, const RectPad &pad = {0, 0, 0, 0}, EnInterpMode interp_mod = EnInterpMode::Bilinear, EnAlignMode align_mod = EnAlignMode::AlignCornerFalse)

Constructor to initialize runtime options for image processing operations.

This constructor allows users to specify the crop region, padding configuration, interpolation method, and alignment mode for the resizing operation.

Parameters:
  • roi -- [in] The region of interest (ROI) to crop, defined in RectRoi.

  • pad -- [in] The padding configuration, defined in RectPad. By default, no padding is applied.

  • interp_mod -- [in] The interpolation method, defined in Resizer::EnInterpMode. The default is Bilinear.

  • align_mod -- [in] The alignment mode, defined in Resizer::EnAlignMode. The default is AlignCornerFalse.

inline RunOption &SetCrop(RectRoi &roi)

Sets the region of interest (ROI) for cropping.

This function allows the user to specify a region of interest (ROI) that defines the area to crop from the image before the resizing operation is applied.

Parameters:

roi -- [in] The region of interest (ROI) for cropping, defined in RectRoi.

Returns:

A reference to the current RunOption object.

inline RunOption &SetPad(RectPad &padsz)

Sets the configuration for padding.

Parameters:

padsz -- [in] The padding configuration, defined in RectPad.

Returns:

A reference to the current RunOption object.

inline RunOption &SetPadVal(const std::array<int32_t, 3> &val)

Sets the padding values for each channel.

This function sets the padding values for each channel, which are applied to the image after resizing.

Parameters:

val -- [in] An array containing the padding values for each channel.

Returns:

A reference to the current RunOption object.

Public Members

EnAlignMode align_mode

The alignment mode to apply during resizing.

RectRoi crop

The region to crop from the original image before image resizing.

EnInterpMode interp_mode

The alignment mode to apply during resizing.

RectPad pad

The padding to apply to the image after resizing.

std::array<int32_t, 3> pad_val = {0, 128, 128}

The padding values for each channel.

enum EnInterpMode

enum EnInterpMode : int32_t {
  Nearest = 0,
  Bilinear = 1
};
enum tcim::ImageOps::Resizer::EnInterpMode

Interpolation modes used in image processing.

Values:

enumerator Nearest = 0
enumerator Bilinear = 1

Nearest neighbor interpolation.

enum EnAlignMode

enum EnAlignMode : int32_t {
  AlignCornerFalse = 0,
  AlignCornerTrue = 1
};
enum tcim::ImageOps::Resizer::EnAlignMode

The alignment modes for scaling operations.

Values:

enumerator AlignCornerFalse = 0
enumerator AlignCornerTrue = 1

The image corners are not aligned during scaling.

Functions

Resizer

tcim::ImageOps::Resizer::Resizer()

Default constructor.

~Resizer

virtual tcim::ImageOps::Resizer::~Resizer()

Resizer destructor.

GetInputNum

virtual size_t tcim::ImageOps::Resizer::GetInputNum() override

Retrieves the total number of input tensors.

Returns:

Returns the total number of input tensors.

GetInputTensor

virtual tcim::Tensor &tcim::ImageOps::Resizer::GetInputTensor(size_t indx) override

Retrieves input tensor with the given index.

Parameters:

indx -- [in] The index of the input tensor.

Returns:

A reference to the input tensor at the specified index.

GetOutputNum

virtual size_t tcim::ImageOps::Resizer::GetOutputNum() override

Retrieves the total number of output tensors.

Returns:

Returns the total number of output tensors.

GetOutputTensor

virtual tcim::Tensor &tcim::ImageOps::Resizer::GetOutputTensor(size_t indx) override

Retrieves output tensor with the given index.

Parameters:

indx -- [in] The index of the output tensor.

Returns:

A reference to the output tensor at the specified index.

GetStream

virtual tcim::Stream &tcim::ImageOps::Resizer::GetStream() override

Retrieves the stream used for image processing.

Returns:

A reference to the stream object.

Init

Status tcim::ImageOps::Resizer::Init(const Option &option = Option())

Initializes the Resizer object with the provided configuration.

Parameters:

option -- [in] Configuration for the image processing.

Returns:

Returns the status of the constructor function.

Note

You must call this function before processing images.

Run

Status tcim::ImageOps::Resizer::Run(const tcim::Tensor &input, tcim::Tensor &output, const RunOption &run_option, bool sync = false)

Processing images with the given configurations.

Parameters:
  • input -- [in] The input tensor containing the image in YUV format. This tensor can be stored either on host or Houmo device memory.

  • output -- [out] The output tensor where the processed image will be stored. This tensor can be stored either on host or Houmo device memory.

  • sync -- [in] A flag to indicate if to automatically synchronize the stream. If set to true, this function will wait for all tasks related to image processing in the stream to complete before returning. If set to false, this function will be executed asynchronously, returning immediately without waiting.

Returns:

Returns the status of the constructor function.

SetStream

virtual Status tcim::ImageOps::Resizer::SetStream(tcim::Stream &stream) override

Sets the stream used for image processing.

Parameters:

stream -- [in] A reference to the stream used for image processing.

Returns:

Returns the status of the function call.

Sync

virtual Status tcim::ImageOps::Resizer::Sync() override

Synchronizes the stream, ensuring that all tasks in the stream are completed.

Returns:

Returns the status of the function call.