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::resize(unsigned int width, unsigned int height)

Resize the image to the target size. Adds padding to the bottom and right if required in order to maintain aspect ratio.

Parameters
  • width – the target width.

  • height – the target height.

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() const

Get the image height in pixels.

Returns

Returns the image height in pixels.

unsigned int Trueface::Image::getWidth() const

Get the image width in pixels.

Returns

Returns the image width in pixels.

unsigned int Trueface::Image::getChannels() const

Get the number of channels for the image.

Returns

Returns the number of channels.

unsigned int Trueface::Image::getStride() const

Get the GPU stride for GPU images.

Returns

Returns the GPU stride for the image.

bool Trueface::Image::isGPUImage() const

Is the image in in GPU memory.

Returns

Returns true if the image is in GPU memory.

uint8_t *Trueface::Image::getData() const

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::getFaceImageRotation(const TFImage &tfImage, RotateFlags &imageRotation)

Detect the orientation of a face image. Returns the rotation required to achieve neutral orientation. As this method does add overhead, we advise only adding it to your pipeline when doing offline processing (ex. reading a database of ID images where some ID images may not be oriented correctly). When consuming a video stream, this method is not necessary as you can guarantee all the frames will have the same orientation.

Parameters
  • tfImage[in] the input image returned by preprocessImage().

  • imageRotation[out] The rotation required in order to achieve neutral orientation. This can be passed directly to the Image::rotate() method in order to correctly rotate the image.

Returns

error code, see ErrorCode.

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_0

Do not rotate.

enumerator ROTATE_90_CLOCKWISE

Rotate 90 degrees clockwise.

enumerator ROTATE_180

Rotate 180 degrees clockwise.

enumerator ROTATE_90_COUNTERCLOCKWISE

Rotate 270 degrees clockwise.