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, rotation_flag: tfsdk.ROTATEFLAGS) → None¶
Rotate the image.
- Parameters
rotation_flag - The ROTATEFLAGS rotation flag).
- 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.
- TFImage.get_height(self: tfsdk.TFImage) → int¶
Get the image height in pixels.
- Returns
Returns the image height in pixels.
- TFImage.get_width(self: tfsdk.TFImage) → int¶
Get the image width in pixels.
- Returns
Returns the image width in pixels.
- SDK.preprocess_image(*args, **kwargs)¶
Overloaded function.
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.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
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.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.
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
- class tfsdk.ROTATEFLAGS¶
Members:
ROTATE_90_CLOCKWISE : Rotate 90 degrees clockwise.
ROTATE_180 : Rotate 180 degrees clockwise.
ROTATE_90_COUNTERCLOCKWISE : Rotate 270 degrees clockwise.