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.

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// ExampleSegRuntime.cpp:52

SaigeInferenceHandle handle = nullptr;
SaigeHandleConfig config;
config.inspectionSizeHeight = 2496;
config.inspectionSizeWidth = 2496;
unsigned int handleFlags = SAIGE_SET_INSPECTION_SIZE;
if (optimize) {
    handleFlags |= SAIGE_OPTIMIZE_HANDLE;
}
retval = SaigeCreateInferenceHandle(&handle, kProjectTypeSEG, trainedModelPath.c_str(),
                                    deviceIndex, &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.

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// ExampleSegRuntime.cpp:164

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
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    // ExampleSegRuntime.cpp:183
    
    // 추론옵션 변경
    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.