Skip to content

Segmentation.h

Go to the source code of this file.

Segmentation finds the area in an image that corresponds to the class specified by the user.

SAIGE VISION returns the inspection results of Segmentation as a SaigeSegmentedObject structure. The detected area is represented as a free-form curve called a Contour and is represented as an array of points.

Inference Options

Inspection Size Width, Height

This is one of the options that can be set when creating a handle using the SaigeHandleConfig structure. Like SaigeInferenceOption::batchSize, it is an option that affects memory settings when creating a handle and cannot be changed after the handle is created.

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// ExampleSegRuntime.cpp:64

SaigeInferenceHandle handle = nullptr;
SaigeInferenceHandle handle2 = nullptr;
SaigeInferenceHandle handle3 = nullptr;
SaigeHandleConfig config;
config.inspectionSizeHeight = 2496;
config.inspectionSizeWidth = 2496;
unsigned int handleFlags = 0;
if (optimize) {
    handleFlags |= SAIGE_OPTIMIZE_HANDLE;
}
retval = SaigeCreateInferenceHandle(&handle, kProjectTypeSEG, trainedModelPath2.c_str(),
                                    1, &config, handleFlags);
if (retval < 0) {
    std::cerr << "SaigeCreateInferenceHandle failed - " << SaigeStrError(retval) << std::endl;
    return retval;
}

retval = SaigeCreateInferenceHandle(&handle2, kProjectTypeSEG, trainedModelPath.c_str(),
                                    0, &config, handleFlags);
if (retval < 0) {
    std::cerr << "SaigeCreateInferenceHandle failed - " << SaigeStrError(retval) << std::endl;
    return retval;
}

retval = SaigeCreateInferenceHandle(&handle3, kProjectTypeSEG, trainedModelPath.c_str(), 1,
                                    &config, handleFlags);
if (retval < 0) {
    std::cerr << "SaigeCreateInferenceHandle failed - " << SaigeStrError(retval) << std::endl;
    return retval;
}

calcMask, calcScoremap, calcObject

The Segmentation function can calculate not only the SaigeSegmentedObject, which is the Contour area information specified by the class, but also the Mask that indicates which class each pixel belongs to in the image and the Scoremap that indicates the Score value for each class.

To calculate these inspection results, set the options as follows. Also, if the calcObject option is true, you can filter the detected objects by applying Score and Area Threshold values for each class.

Note

All three options cannot be set to false to calculate no values.

190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// ExampleSegRuntime.cpp:192

options->calcMask = true;
options->calcScoremap = true;
options->calcObjectAreaAndApplyThreshold = true;
options->calcObjectScoreAndApplyThreshold = true;
unsigned int flags = SAIGE_SET_CALC_SCOREMAP | SAIGE_SET_CALC_MASK |
                     SAIGE_SET_CALC_OBJECT_AREA_AND_APPLY_THRESHOLD |
                     SAIGE_SET_CALC_OBJECT_SCORE_AND_APPLY_THRESHOLD;
retval = SaigeSetInferenceOption(handle, options, flags);
if (retval < 0) {
    std::cerr << "SaigeSetInferenceOption() failed - " << SaigeStrError(retval)
              << std::endl;
    SaigeDestroyInferenceHandle(handle);
    SaigeDestroyInferenceResult(result);
    return retval;
}

Score, Area Thresholds

Like Object Detection, Segmentation can set Score and Area Threshold values per class. In addition, Segmentation can set the Object Boundary Threshold value. All Threshold options cannot be set for the 0th OK class. The default values for the 0th class are as follows.

  • objectBoundaryThreshold[0] = 100
  • objectScoreThreshold[0] = 0
  • objectAreaThreshold[0] = 0
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    // ExampleSegRuntime.cpp:211
    
    // 추론옵션 변경
    options->objectAreaThresholdPerClass[1] = 500;
    options->objectAreaThresholdPerClass[2] = 500;
    flags = SAIGE_SET_OBJECT_AREA_THRESHOLD;
    retval = SaigeSetInferenceOption(handle, options, flags);
    if (retval < 0) {
        std::cerr << "SaigeSetInferenceOption() failed - " << SaigeStrError(retval)
                  << std::endl;
        SaigeDestroyInferenceHandle(handle);
        SaigeDestroyInferenceResult(result);
        return retval;
    }
    options->objectScoreThresholdPerClass[1] = 200.0;
    options->objectScoreThresholdPerClass[2] = 200.0;
    flags = SAIGE_SET_OBJECT_SCORE_THRESHOLD;
    retval = SaigeSetInferenceOption(handle, options, flags);
    if (retval < 0) {
        std::cerr << "SaigeSetInferenceOption() failed - " << SaigeStrError(retval)
                  << std::endl;
        SaigeDestroyInferenceHandle(handle);
        SaigeDestroyInferenceResult(result);
        return retval;
    }
    options->objectBoundaryThresholdPerClass[1] = 150;
    options->objectBoundaryThresholdPerClass[2] = 150;
    flags = SAIGE_SET_OBJECT_BOUNDARY_THRESHOLD;
    retval = SaigeSetInferenceOption(handle, options, flags);
    if (retval < 0) {
        std::cerr << "SaigeSetInferenceOption() failed - " << SaigeStrError(retval)
                  << std::endl;
        SaigeDestroyInferenceHandle(handle);
        SaigeDestroyInferenceResult(result);
        return retval;
    }
    

Inspection Results

The inspection results of Segmentation are divided into Mask, Scoremap, and Segmented Object.

Mask and Scoremap are received as arrays in the unsigned char* pointer variable.

Segmented Object first receives the number of detected objects in the int numSegObj variable and then uses the SaigeSegmentedObject structure array to receive the object information. Here, we use the C++ STL vector to handle memory allocation/deallocation in the vector.