vitis::ai::Segmentation

Base class for Segmentation.

Declaration Segmentation Network number of segmentation classes label 0 name: "unlabeled" label 1 name: "ego vehicle" label 2 name: "rectification border" label 3 name: "out of roi" label 4 name: "static" label 5 name: "dynamic" label 6 name: "ground" label 7 name: "road" label 8 name: "sidewalk" label 9 name: "parking" label 10 name: "rail track" label 11 name: "building" label 12 name: "wall" label 13 name: "fence" label 14 name: "guard rail" label 15 name: "bridge" label 16 name: "tunnel" label 17 name: "pole"

Input is an image (cv:Mat).

Output is result of running the Segmentation network.

Sample code :

   auto det =vitis::ai::Segmentation::create("fpn", true);

   auto img= cv::imread("sample_segmentation.jpg");
   int width = det->getInputWidth();
   int height = det->getInputHeight();
   cv::Mat image;
   cv::resize(img, image, cv::Size(width, height), 0, 0,
              cv::INTER_LINEAR);
   auto result = det->run_8UC1(image);
   for (auto y = 0; y < result.segmentation.rows; y++) {
     for (auto x = 0; x < result.segmentation.cols; x++) {
           result.segmentation.at<uchar>(y,x) *= 10;
       }
   }
   cv::imwrite("segres.jpg",result.segmentation);

   auto resultshow = det->run_8UC3(image);
   resize(resultshow.segmentation, resultshow.segmentation,
cv::Size(resultshow.cols * 2, resultshow.rows * 2));
   cv::imwrite("sample_segmentation_result.jpg",resultshow.segmentation);
Figure 1: segmentation Visualization Result Image

Image sample_segmentation_result.jpg

Quick Function Reference

The following table lists all the functions defined in the vitis::ai::Segmentation class:

Table 1. Quick Function Reference
TypeNameArguments
std::unique_ptr< Segmentation >create
  • const std::string & model_name
  • bool need_preprocess
intgetInputWidth
  • void
intgetInputHeight
  • void
size_tget_input_batch
  • void
SegmentationResultrun_8UC1
  • const cv::Mat & image
std::vector< SegmentationResult >run_8UC1
  • const std::vector< cv::Mat > & images
SegmentationResultrun_8UC3
  • const cv::Mat & image
std::vector< SegmentationResult >run_8UC3
  • const std::vector< cv::Mat > & images

create

Factory function to get an instance of derived classes of class Segmentation.

Prototype

std::unique_ptr< Segmentation > create(const std::string &model_name, bool need_preprocess=true);

Parameters

The following table lists the create function arguments.

Table 2. create Arguments
Type Name Description
const std::string & model_name Model name
bool need_preprocess Normalize with mean/scale or not, default value is true.

Returns

An instance of Segmentation class.

getInputWidth

Function to get InputWidth of the segmentation network (input image columns).

Prototype

int getInputWidth() const =0;

Returns

InputWidth of the segmentation network.

getInputHeight

Function to get InputHeight of the segmentation network (input image rows).

Prototype

int getInputHeight() const =0;

Returns

InputHeight of the segmentation network.

get_input_batch

Function to get the number of images processed by the DPU at one time.

Note: Different DPU core the batch size may be different. This depends on the IP used.

Prototype

size_t get_input_batch() const =0;

Returns

Batch size.

run_8UC1

Function to get running result of the segmentation network.

Note: The type of CV_8UC1 of the segmentation result.

Prototype


            SegmentationResult run_8UC1(const cv::Mat &image)=0;

Parameters

The following table lists the run_8UC1 function arguments.

Table 3. run_8UC1 Arguments
Type Name Description
const cv::Mat & image Input data of input image (cv::Mat).

Returns

A result that includes segmentation output data.

run_8UC1

Function to get running results of the segmentation neuron network in batch mode.

Note: The type of CV_8UC1 of the segmentation result.

Prototype

std::vector< SegmentationResult > run_8UC1(const std::vector< cv::Mat > &images)=0;

Parameters

The following table lists the run_8UC1 function arguments.

Table 4. run_8UC1 Arguments
Type Name Description
const std::vector< cv::Mat > & images Input data of input images (std:vector<cv::Mat>). The size of input images equals batch size obtained by get_input_batch.

Returns

The vector of SegmentationResult.

run_8UC3

Function to get running result of the segmentation network.

Note: The type of CV_8UC3 of the segmentation result.

Prototype


            SegmentationResult run_8UC3(const cv::Mat &image)=0;

Parameters

The following table lists the run_8UC3 function arguments.

Table 5. run_8UC3 Arguments
Type Name Description
const cv::Mat & image Input data of input image (cv::Mat).

Returns

A result that include segmentation image and shape;.

run_8UC3

Function to get running results of the segmentation neuron network in batch mode.

Note: The type of CV_8UC3 of the segmentation result.

Prototype

std::vector< SegmentationResult > run_8UC3(const std::vector< cv::Mat > &images)=0;

Parameters

The following table lists the run_8UC3 function arguments.

Table 6. run_8UC3 Arguments
Type Name Description
const std::vector< cv::Mat > & images Input data of input images (std:vector<cv::Mat>). The size of input images equals batch size obtained by get_input_batch.

Returns

The vector of SegmentationResult.