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 rotateFlag)

Rotate the image.

Parameters:

rotateFlag[in] 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[in] The target width.

  • height[in] The target height.

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

Save the preprocessed image to disk.

Parameters:

filepath[in] 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.

ErrorCode Trueface::SDK::getFaceImageRotations(const std::vector<TFImage> &tfImages, std::vector<RotateFlags> &imageRotations)

Detect the orientation of a list of face images. 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. This batch processing method increases throughput when using GPU inference.

Parameters:
  • tfImages[in] The list of input images.

  • imageRotations[out] The rotations required in order to achieve neutral orientation. These orientations can be passed directly to the Image::rotate() method in order to correctly rotate the images.

Returns:

Error code, see ErrorCode.

enum class Trueface::ColorCode

Image color formats.

Values:

enumerator bgr
enumerator rgb
enumerator bgra
enumerator rgba
enumerator gray
enumerator yuv_i420
enumerator yuv_nv12
enum class 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.