vitis::ai::Segmentation - 2.0 English

Vitis AI Library User Guide (UG1354)

Document ID
UG1354
Release Date
2022-01-20
Version
2.0 English
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
Type Name Arguments
std::unique_ptr< Segmentation > create
  • const std::string & model_name
  • bool need_preprocess
int getInputWidth
  • void
int getInputHeight
  • void
size_t get_input_batch
  • void
SegmentationResult run_8UC1
  • const cv::Mat & image
std::vector< SegmentationResult > run_8UC1
  • const std::vector< cv::Mat > & images
SegmentationResult run_8UC3
  • const cv::Mat & image
std::vector< SegmentationResult > run_8UC3
  • const std::vector< cv::Mat > & images