vitis::ai::Segmentation8UC1

The Class of Segmentation8UC1. This class run function run(const cv::Mat& image) return a cv::Mat with the type is cv_8UC1. Sample code :
   auto det =
vitis::ai::Segmentation8UC1::create(vitis::ai::SEGMENTATION_FPN);
  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(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);

Quick Function Reference

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

Table 1. Quick Function Reference
TypeNameArguments
std::unique_ptr< Segmentation8UC1 >create
  • const std::string & model_name
  • bool need_preprocess
intgetInputWidth
  • void
intgetInputHeight
  • void
size_tget_input_batch
  • void
SegmentationResultrun
  • const cv::Mat & image
std::vector< SegmentationResult >run
  • const std::vector< cv::Mat > & images

create

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

Prototype

std::unique_ptr< Segmentation8UC1 > 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 Segmentation8UC1 class.

getInputWidth

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

Prototype

int getInputWidth() const;

Returns

InputWidth of the segmentation network.

getInputHeight

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

Prototype

int getInputHeight() const;

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;

Returns

Batch size.

run

Function to get running result of the segmentation network.

Note: The result cv::Mat of the type is CV_8UC1.

Prototype


            SegmentationResult run(const cv::Mat &image);

Parameters

The following table lists the run function arguments.

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

Returns

A Struct of SegmentationResult ,the result of segmentation network.

run

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

Note: The type of CV_8UC1 of the Result's segmentation.

Prototype

std::vector< SegmentationResult > run(const std::vector< cv::Mat > &images);

Parameters

The following table lists the run function arguments.

Table 4. run 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.