Skip to content

SaigeVisionUtil.h

Go to the source code of this file.

  • #include "SaigeVisionAPI.h"

SaigeVision 예제를 실행하기 위해 필요한 함수가 정의되어 있습니다. 이미지 데이터 사용, 추론 결과 시각화 등에 사용됩니다.

Public Types

Type Name
enum _SaigeImageType
typedef enum _SaigeImageType SaigeImageType

Public Functions

Type Name
void SaigeInitTextFormatting (SaigeTextFormatting * formatting)
SaigeInitTextFormatting.
unsigned int SaigeConvertImageType (const int channel, const int type)
SaigeConvertImageType.
int SaigeOverlaySegmentedObjects (const void * baseImage, const SaigeSegmentedObject * objects, SaigeModelInfo * modelInfo, const int numOfSegmentedObjects, const int width, const int height, const int channels, const int type, const bool isRGB, const double overlayAlpha, void * resultImage)
SaigeOverlaySegmentedObjects.
int SaigeOverlayDetectedObjects (const void * baseImage, const SaigeDetectedObject * objects, SaigeModelInfo * modelInfo, const int numOfDetectedObjects, const int width, const int height, const int channels, const int type, const bool withClassName, const bool isRGB, const double overlayAlpha, void * resultImage)
SaigeOverlayDetectedObjects.
int SaigeOverlayTextObjects (const void * baseImage, const SaigeTextObject * objects, const int numOfTextObjects, const int width, const int height, const int channels, const int type, const bool isRGB, const double overlayAlpha, const double textScale, void * resultImage)
SaigeOverlayTextObjects.
int SaigeOverlayHeatmap (const void * baseImage, const float * heatmap, const int width, const int height, const int channels, const int type, const bool isRGB, const double overlayAlpha, void * resultImage)
SaigeOverlayHeatmaps.
int SaigeShowImage (const void * image, const int width, const int height, const int channels, const int type, const bool isRGB, const bool invert, const double alpha, const int waitMS)
SaigeShowImage.
void * SaigeGetImageData (const char * imagePath, int * width, int * height, int * channels, int * type)
SaigeGetImageData.
int SaigeFreeImageData (void * image)
SaigeFreeImageData.
int SaigeColorCodeToRGB (const char * color, unsigned char * r, unsigned char * g, unsigned char * b)
SaigeColorCodeToRGB.
int SaigeDrawDetectedObjects (const void * image, const SaigeDetectedObject * objects, SaigeModelInfo * modelInfo, const int numOfDetectedObjects, const int width, const int height, const int channels, const int type, const int waitMS)
SaigeDrawDetectedObjects.
int SaigeDrawSegmentedObjects (const void * image, const SaigeSegmentedObject * objects, SaigeModelInfo * modelInfo, const int numOfSegmentedObjects, const int width, const int height, const int channels, const int type, const double overlayAlpha, const int waitMS)
SaigeDrawSegmentedObjects.
int SaigeDrawTextObjects (const void * image, const SaigeTextObject * objects, const int numBoxes, const int width, const int height, const int channels, const int type, const int waitMS)
SaigeDrawTextObjects.
int SaigeDrawHeatmap (const float * image, const int width, const int height, const int waitMS)
SaigeDrawHeatmap.
int SaigeDrawImage (const void * image, const int width, const int height, const int channels, const double alpha, const int type, const bool invert, const int waitMS)
SaigeDrawImage.
int SaigeDrawImageOverBase (const void * base_img, const void * img, const int width, const int height, const int channels_base, const int channels_img, const int type_base, const int type_img, const double alpha, const bool invert, const int waitMS)
SaigeDrawImageOverBase.

Public Types Documentation

_SaigeImageType

enum _SaigeImageType {
    SV_U8 = 0,
    SV_U16 = 1,
    SV_F32 = 2,
    SV_F64 = 3,
    SV_FILEPATH = 4
};

SaigeImageType

enum _SaigeImageType SaigeImageType;

Public Functions Documentation

SaigeInitTextFormatting

SaigeInitTextFormatting.

void SaigeInitTextFormatting (
    SaigeTextFormatting * formatting
) 

Initializes the boolean array indicating the inclusion of character sets in the given SaigeTextFormatting to false for all values. This prepares the formatting settings for use in text recognition tasks.

Parameters:

  • formatting Pointer to the variable to be set.

SaigeConvertImageType

SaigeConvertImageType.

unsigned int SaigeConvertImageType (
    const int channel,
    const int type
) 

Converts the number of channels and SaigeImageType into the image flag macro used in SaigeInferFromByteArray. This function is useful for preparing image data for inference.

Parameters:

  • channel The number of channels in the image.
  • type The data type of the image. Refer to SaigeDrawImage for setting options.

Returns:

imageFlag Returns the converted image flag macro.

SaigeOverlaySegmentedObjects

SaigeOverlaySegmentedObjects.

int SaigeOverlaySegmentedObjects (
    const void * baseImage,
    const SaigeSegmentedObject * objects,
    SaigeModelInfo * modelInfo,
    const int numOfSegmentedObjects,
    const int width,
    const int height,
    const int channels,
    const int type,
    const bool isRGB,
    const double overlayAlpha,
    void * resultImage
) 

Draws segmented objects on a base image and stores the result in an output image. This function allows for the visualization of segmentation results overlaid on an original image.

Parameters:

  • baseImage The base image data on which segmented objects will be drawn.
  • objects The array of segmented objects detected from inference.
  • modelInfo The model information, used for class colors; if null, the color red will be used.
  • numOfSegmentedObjects The number of segmented objects.
  • width The width of the base and result images.
  • height The height of the base and result images.
  • channels The number of channels in the base and result images.
  • type The type of the image. Refer to SaigeImageType for details.
  • overlayAlpha The transparency value for visualizing segmented objects; the range is 0 to 1, where values closer to 1 make the segmented objects more transparent.
  • resultImage [out] The image data that stores the result with segmented objects drawn on it.

Returns:

errorCode Returns 0 on success, or an error code if there is a failure.

See also: SaigeGetInferenceResultNumOfSegmentedObjects, SaigeGetInferenceResultSegmentedObjects

SaigeOverlayDetectedObjects

SaigeOverlayDetectedObjects.

int SaigeOverlayDetectedObjects (
    const void * baseImage,
    const SaigeDetectedObject * objects,
    SaigeModelInfo * modelInfo,
    const int numOfDetectedObjects,
    const int width,
    const int height,
    const int channels,
    const int type,
    const bool withClassName,
    const bool isRGB,
    const double overlayAlpha,
    void * resultImage
) 

Draws the bounding boxes of detected objects on a base image and stores the result in an output image. This function allows for the visualization of detection results overlaid on an original image.

Parameters:

  • baseImage The base image data on which detected objects will be drawn.
  • objects The array of detected objects from inference.
  • modelInfo The model information, used for class names and colors; if null, the color red will be used.
  • numOfDetectedObjects The number of detected objects.
  • width The width of the base and result images.
  • height The height of the base and result images.
  • channels The number of channels in the base and result images.
  • type The type of the image. Refer to SaigeImageType for details.
  • withClassName If set to true, the class name of each detected object will also be displayed.
  • isRGB If set to true, indicates that the image data is in RGB order.
  • overlayAlpha The transparency value for visualizing detected objects; the range is 0 to 1, where values closer to 1 make the detected objects more transparent.
  • resultImage [out] The image data that stores the result with detected objects drawn on it.

Returns:

errorCode Returns 0 on success, or an error code if there is a failure.

See also: SaigeGetInferenceResultNumOfDetectedObjects, SaigeGetInferenceResultDetectedObjects

SaigeOverlayTextObjects

SaigeOverlayTextObjects.

int SaigeOverlayTextObjects (
    const void * baseImage,
    const SaigeTextObject * objects,
    const int numOfTextObjects,
    const int width,
    const int height,
    const int channels,
    const int type,
    const bool isRGB,
    const double overlayAlpha,
    const double textScale,
    void * resultImage
) 

Draws the OCR results, represented by SaigeTextObject, on a base image and stores the result in an output image. Currently, Korean text appears as '?', support for it is planned for future updates.

Parameters:

  • baseImage The base image data on which SaigeTextObject will be drawn.
  • objects The array of SaigeTextObject detected from inference.
  • numOfSaigeTextObject The number of SaigeTextObject.
  • width The width of the base and result images.
  • height The height of the base and result images.
  • channels The number of channels in the base and result images.
  • type The type of the image. Refer to SaigeImageType for details.
  • isRGB If set to true, indicates that the image data is in RGB order.
  • overlayAlpha The transparency value for visualizing SaigeTextObject; the range is 0 to 1, where values closer to 1 make the SaigeTextObject more transparent.
  • resultImage [out] The image data that stores the result with SaigeTextObject drawn on it.

Returns:

errorCode Returns 0 on success, or an error code if there is a failure.

See also: SaigeGetInferenceResultNumOfSaigeTextObject, SaigeGetInferenceResultSaigeTextObject

SaigeOverlayHeatmap

SaigeOverlayHeatmaps.

int SaigeOverlayHeatmap (
    const void * baseImage,
    const float * heatmap,
    const int width,
    const int height,
    const int channels,
    const int type,
    const bool isRGB,
    const double overlayAlpha,
    void * resultImage
) 

Draws a colorized heatmap on a base image and stores the result in an output image. This function helps visualize the heatmap data in relation to the original image.

Parameters:

  • baseImage The base image data on which the heatmap will be drawn.
  • heatmap The array of heatmap data obtained from the inspection results.
  • width The width of the base and result images.
  • height The height of the base and result images.
  • channels The number of channels in the base and result images.
  • type The type of the image. Refer to SaigeImageType for details.
  • isRGB If set to true, indicates that the image data is in RGB order.
  • overlayAlpha The transparency value for visualizing the heatmap; the range is 0 to 1, where values closer to 1 make the heatmap more transparent.
  • resultImage [out] The image data that stores the result with the heatmap drawn on it.

Returns:

errorCode Returns 0 on success, or an error code if there is a failure.

See also: SaigeGetInferenceResultHeatmap

SaigeShowImage

SaigeShowImage.

int SaigeShowImage (
    const void * image,
    const int width,
    const int height,
    const int channels,
    const int type,
    const bool isRGB,
    const bool invert,
    const double alpha,
    const int waitMS
) 

Displays an image in a separate window. This function is useful for visualizing images during development or debugging processes.

Parameters:

  • image The image data to be displayed.
  • width The width of the image.
  • height The height of the image.
  • channels The number of channels in the image.
  • type The data type of the image. Refer to SaigeImageType for setting options.
  • isRGB If set to true, indicates that the image data is in RGB order.
  • invert If set to true, the colors will be inverted during display.
  • alpha The value multiplied with the pixel values of the image data; this helps adjust the brightness of the displayed image.
  • waitMS The display duration in milliseconds; if set to 0, the display window must be closed manually.

Returns:

errorCode Returns 0 on success, or an error code if there is a failure.

SaigeGetImageData

SaigeGetImageData.

void * SaigeGetImageData (
    const char * imagePath,
    int * width,
    int * height,
    int * channels,
    int * type
) 

Retrieves image data from the specified image path. For color images, the data is always returned in RGB order.

Parameters:

  • imagePath The path to the image.
  • width [out] The width of the image.
  • height [out] The height of the image.
  • channels [out] The number of channels in the image.
  • type [out] The type of the image.

Returns:

image Returns the image data as a void* type.

See also: SaigeFreeImageData

SaigeFreeImageData

SaigeFreeImageData.

int SaigeFreeImageData (
    void * image
) 

Frees the memory of the image obtained from SaigeGetImageData.

Parameters:

  • image The image data for which to free the memory.

Returns:

errorCode Returns 0 on success, or an error code if there is a failure.

See also: SaigeGetImageData

SaigeColorCodeToRGB

SaigeColorCodeToRGB.

int SaigeColorCodeToRGB (
    const char * color,
    unsigned char * r,
    unsigned char * g,
    unsigned char * b
) 

Converts a color code to RGB values. This function is useful for interpreting the color representation of classes in a model.

Parameters:

  • color The color code to convert.
  • r [out] The R value of the RGB color.
  • g [out] The G value of the RGB color.
  • b [out] The B value of the RGB color.

Returns:

errorCode Returns 0 on success, or an error code if there is a failure.

See also: SaigeModelInfo::classColors

SaigeDrawDetectedObjects

SaigeDrawDetectedObjects.

int SaigeDrawDetectedObjects (
    const void * image,
    const SaigeDetectedObject * objects,
    SaigeModelInfo * modelInfo,
    const int numOfDetectedObjects,
    const int width,
    const int height,
    const int channels,
    const int type,
    const int waitMS
) 

Draws detected objects on the specified image and displays them. Useful for visualizing object detection results.

Parameters:

  • image The image data on which the detected objects will be drawn.
  • objects The array of detected objects from inference.
  • modelInfo The model information, used for class names and color display.
  • numOfDetectedObjects The number of detected objects.
  • width The width of the image.
  • height The height of the image.
  • channels The number of channels in the image.
  • type The type of the image. See SaigeImageType for reference.
  • waitMS The display duration in milliseconds; if set to 0, the display window must be closed manually.

Returns:

errorCode Returns 0 on success, or an error code if there is a failure.

See also: SaigeGetInferenceResultNumOfDetectedObjects, SaigeGetInferenceResultDetectedObjects

SaigeDrawSegmentedObjects

SaigeDrawSegmentedObjects.

int SaigeDrawSegmentedObjects (
    const void * image,
    const SaigeSegmentedObject * objects,
    SaigeModelInfo * modelInfo,
    const int numOfSegmentedObjects,
    const int width,
    const int height,
    const int channels,
    const int type,
    const double overlayAlpha,
    const int waitMS
) 

Draws segmented objects on the specified image and displays them. Useful for visualizing segmentation results.

Parameters:

  • image The image data on which the segmented objects will be drawn.
  • objects The array of segmented objects from inference.
  • modelInfo The model information, used for class names and color display.
  • numOfSegmentedObjects The number of segmented objects.
  • width The width of the image.
  • height The height of the image.
  • channels The number of channels in the image.
  • type The type of the image. See SaigeImageType for reference.
  • overlayAlpha The transparency value for visualizing the segmented objects; the range is 0 to 1, where values closer to 1 indicate more transparency.
  • waitMS The display duration in milliseconds; if set to 0, the display window must be closed manually.

Returns:

errorCode Returns 0 on success, or an error code if there is a failure.

See also: SaigeGetInferenceResultNumOfSegmentedObjects, SaigeGetInferenceResultSegmentedObjects

SaigeDrawTextObjects

SaigeDrawTextObjects.

int SaigeDrawTextObjects (
    const void * image,
    const SaigeTextObject * objects,
    const int numBoxes,
    const int width,
    const int height,
    const int channels,
    const int type,
    const int waitMS
) 

Displays the detected text areas as SaigeTextObject on the image. Currently, Korean characters will appear as '?', with support planned for the future.

Parameters:

  • image The image data where the detected text objects will be displayed.
  • objects The array of detected SaigeTextObject structures.
  • numBoxes The number of detected text objects.
  • width The width of the image.
  • height The height of the image.
  • channels The number of channels in the image.
  • type The type of the image. See SaigeImageType for reference.
  • waitMS The display duration in milliseconds; if set to 0, the display window must be closed manually.

See also: SaigeTextObject

SaigeDrawHeatmap

SaigeDrawHeatmap.

int SaigeDrawHeatmap (
    const float * image,
    const int width,
    const int height,
    const int waitMS
) 

Displays a heatmap image. This is useful for visualizing areas of interest or anomalies in the processed image.

Parameters:

  • image The heatmap image data.
  • width The width of the heatmap.
  • height The height of the heatmap.
  • waitMS The display duration in milliseconds; if set to 0, the display window must be closed manually.

Returns:

errorCode Returns 0 on success, or an error code if there is a failure.

See also: SaigeGetInferenceResultHeatmap

SaigeDrawImage

SaigeDrawImage.

int SaigeDrawImage (
    const void * image,
    const int width,
    const int height,
    const int channels,
    const double alpha,
    const int type,
    const bool invert,
    const int waitMS
) 

Displays an image. This function is useful for visualizing images processed or analyzed by the system.

Parameters:

  • image The image data to be displayed.
  • width The width of the image.
  • height The height of the image.
  • channels The number of channels in the image.
  • alpha The value multiplied by the pixel values of the image data.
  • type The image data type.
  • invert If set to true, the colors will be inverted.
  • waitMS The display duration in milliseconds; if set to 0, the display window must be closed manually.

Setting alpha value

When the image is of type unsigned char, it is recommended to set the pixel value range to 0-255.

When the image is of type float, it is recommended to set the pixel value range to 0-1.

Setting type

When the image is of type unsigned char, input 'SV_U8'.

When the image is of type unsigned short, input 'SV_U16'.

When the image is of type float, input 'SV_F32'.

Returns:

errorCode Returns 0 on success, or an error code if there is a failure.

See also: SaigeGetInferenceResultScoremapSEG, SaigeGetInferenceResultScoremapIAD, SaigeGetInferenceResultMask

SaigeDrawImageOverBase

SaigeDrawImageOverBase.

int SaigeDrawImageOverBase (
    const void * base_img,
    const void * img,
    const int width,
    const int height,
    const int channels_base,
    const int channels_img,
    const int type_base,
    const int type_img,
    const double alpha,
    const bool invert,
    const int waitMS
) 

Displays an image over a base image. This is useful for layering images, such as displaying annotations or overlays on top of a background image.

Parameters:

  • base_img The image data that will serve as the background.
  • img The image data to be displayed on top of the background.
  • width The width of both images; they must be the same width.
  • height The height of both images; they must be the same height.
  • channels_base The number of channels in the background image.
  • channels_img The number of channels in the overlay image.
  • type_base The data type of the background image. Refer to SaigeDrawImage for setting options.
  • type_img The data type of the overlay image. Refer to SaigeDrawImage for setting options.
  • alpha The value multiplied with the pixel values of the overlay image; it does not affect the background image.
  • invert If set to true, the colors of the overlay image will be inverted. This does not affect the background image.
  • waitMS The display duration in milliseconds; if set to 0, the display window must be closed manually.

Returns:

errorCode Returns 0 on success, or an error code if there is a failure.

See also: SaigeGetInferenceResultClassActivationMap