Input Image

In order to use many of the Trueface AI inference functions (face detection, face recognition, etc), you must first preprocess your image. Once you have preprocessed your image, you are ready to start calling the various Trueface AI inference functions.

class Image

Class which is used to manage a decoded image which is in the format expected by inference functions. Should populate Image using the preprocessImage functions. An Image can be in CPU memory or GPU memory.

Trueface::Image::Image() = default

Default constructor.

void Trueface::Image::rotate(RotateFlags rotateFlags)

Rotate the image.

Parameters

rotateFlag – the RotateFlags.

void Trueface::Image::saveImage(const std::string &filepath)

Save the preprocessed image to disk.

Parameters

filepath – the filepath where the image should be saved, including the image extension

unsigned int Trueface::Image::getHeight()

Get the image height in pixels.

Returns

Returns the image height in pixels.

unsigned int Trueface::Image::getWidth()

Get the image width in pixels.

Returns

Returns the image width in pixels.

bool Trueface::Image::isManagedBuffer()

Is the memory managed by the class. If the memory is managed by the class, the image data will be freed when the instance storage duration ends. If the memory is not managed by the class, then it is up to the user to free the allocated memory.

Returns

Returns true if the memory is managed by the class.

bool Trueface::Image::isGPUImage()

Is the image in in GPU memory.

Returns

Returns true if the image is in GPU memory.

uint8_t *Trueface::Image::getData()

Get the decoded image buffer.

Returns

Returns the decoded image buffer.

using Trueface::TFImage = std::shared_ptr<Image>
ErrorCode Trueface::SDK::preprocessImage(const std::string &imageFile, TFImage &tfImage)

Preprocess the image to be used by the other methods.

Parameters
  • imageFile[in] the path of a JPEG, JPG, PNG, BMP, or TIFF file (path must not contain ~ ).

  • tfImage[out] the preprocesses image.

Returns

error code, see ErrorCode.

ErrorCode Trueface::SDK::preprocessImage(uint8_t *image, uint16_t width, uint16_t height, ColorCode color, TFImage &tfImage, int stride = 0)

Preprocess the image to be used by the other methods. Creates a copy of the image buffer.

Parameters
  • image[in] an 8-bit decoded image array, in the CPU memory or the GPU memory.

  • width[in] the image width.

  • height[in] the image height.

  • color[in] the image color model, see ColorCode.

  • tfImage[out] the preprocesses image.

  • stride[in] the distance between image array rows in bytes, also known as step size (used only for pointers to the GPU memory).

Returns

error code, see ErrorCode.

ErrorCode Trueface::SDK::preprocessImage(const std::vector<uint8_t> &encodedImageBuffer, TFImage &tfImage)

Preprocess the image to be used by the other methods.

Parameters
  • encodedImageBuffer[in] encoded image buffer, supports JPG, PNG, BMP, and TIFF.

  • tfImage[out] the preprocesses image.

Returns

error code, see ErrorCode.

ErrorCode Trueface::SDK::preprocessRgbImage(uint8_t *image, uint16_t width, uint16_t height, TFImage &tfImage, int stride = 0)

Preprocess the image to be used by other methods. Buffer is not copied and memory should be managed by the caller. More efficient than preprocessImage() as the data is referenced and not copied. Buffer must remain valid until the TFImage is no longer needed, at which point the caller is responsible for freeing the allocated memory. Note: If a CPU memory image is provided when using the GPU SDK, the SDK will copy the image to GPU memory, and thus the image will not be referenced. To optimize performance with the GPU SDK, ensure the image is already loaded into GPU memory before calling this method.

Parameters
  • image – an 8-bit decoded image array in RGB format, in the CPU memory or the GPU memory.

  • width – the image width.

  • height – the image height.

  • tfImage – the preprocessed image.

  • stride – the distance between image array rows in bytes, also known as step size (used only for pointers to the GPU memory).

Returns

enum Trueface::ColorCode

Image color formats.

Values:

enumerator bgr
enumerator rgb
enumerator bgra
enumerator rgba
enumerator gray
enumerator yuv_i420
enumerator yuv_nv12
enum Trueface::RotateFlags

Flags used for rotating images.

Values:

enumerator ROTATE_90_CLOCKWISE

Rotate 90 degrees clockwise.

enumerator ROTATE_180

Rotate 180 degrees clockwise.

enumerator ROTATE_90_COUNTERCLOCKWISE

Rotate 270 degrees clockwise.