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 tfsdk.TFImage
TFImage.rotate(self: tfsdk.TFImage, rot_angle_degrees: float)None

Rotate the image.

Parameters

rot_angle_degrees - rotation angle in degrees. Positive values mean counter-clockwise rotation (the coordinate origin is assumed to be the top-left corner).

TFImage.save_image(self: tfsdk.TFImage, filepath: str)None

Save the preprocessed image to disk.

Parameters

filepath - the filepath where the image should be saved, including the image extension.

SDK.preprocess_image(*args, **kwargs)

Overloaded function.

  1. preprocess_image(self: tfsdk.SDK, pixel_array: numpy.ndarray[numpy.uint8], width: int, height: int, color_code: tfsdk.COLORCODE) -> Tuple[tfsdk.ERRORCODE, tfsdk.TFImage]

    Preprocess the image to be used by other methods. Loads an image from the given pixel array in memory. Creates a copy of the underlying data. Note, it is highly encouraged to check the return value from setImage before proceeding. If the license is invalid, the tfsdk.ERRORCODE.INVALID_LICENSE error will be returned.

    Parameters
    • pixel_array - decoded pixel array in memory.

    • width - the image width in pixels.

    • height - the image height in pixels.

    • color_code - the pixel array color code, see COLORCODE.

    Returns

    Error code, see ERRORCODE, and TFImage.

  2. preprocess_image(self: tfsdk.SDK, pointer: int, width: int, height: int, color_code: tfsdk.COLORCODE, stride: int) -> Tuple[tfsdk.ERRORCODE, tfsdk.TFImage]

    Preprocess the image to be used by other methods. Load an image from the given memory pointer. The underlying data is copied. Note, it is highly encouraged to check the return value from setImage before proceeding. If the license is invalid, the tfsdk.ERRORCODE.INVALID_LICENSE error will be returned.

    Parameters
    • pointer - pointer to decoded pixel array in memory.

    • width - the image width in pixels.

    • height - the image height in pixels.

    • color_code - the pixel array color code, see COLORCODE.

    • stride - 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, and TFImage.

  3. preprocess_image(self: tfsdk.SDK, image_filepath: str) -> Tuple[tfsdk.ERRORCODE, tfsdk.TFImage]

    Preprocess the image to be used by the other methods. Load an image from the given JPEG, JPG, PNG, BMP, or TIFF file. Note, it is highly encouraged to check the return value from setImage before proceeding. If the license is invalid, the tfsdk.ERRORCODE.INVALID_LICENSE error will be returned.

    Parameters

    image_filepath - the path to the image. Must not contain “~”. Can be a relative path.

    Returns

    Error code, see ERRORCODE, and TFImage.

  4. preprocess_image(self: tfsdk.SDK, encoded_image_buffer: List[int]) -> Tuple[tfsdk.ERRORCODE, tfsdk.TFImage]

    Preprocess the image to be used by the other methods. Load an image from an encoded image buffer, supports JPG, PNG, BMP, and TIFF. Note, it is highly encouraged to check the return value from setImage before proceeding. If the license is invalid, the tfsdk.ERRORCODE.INVALID_LICENSE error will be returned.

    Parameters

    encoded_image_buffer - encoded image buffer, supports JPG, PNG, BMP, and TIFF.

    Returns

    Error code, see ERRORCODE, and TFImage.

You can set the image using an OpenCV cv::Mat by passing the image buffer as follows:

1 cv_img = cv2.imread(img_path)
2 res, image = sdk.set_image(cv_img, cv_img.shape[1], cv_img.shape[0], tfsdk.COLORCODE.bgr)
class tfsdk.COLORCODE

Members:

bgr

rgb

bgra

rgba

gray

yuv_i420

yuv_nv12