vitis::ai::Segmentation
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);
Quick Function Reference
The following table lists all the functions defined in the vitis::ai::Segmentation
class:
Type | Name | Arguments |
---|---|---|
std::unique_ptr< Segmentation > | create |
|
int | getInputWidth |
|
int | getInputHeight |
|
size_t | get_input_batch |
|
SegmentationResult | run_8UC1 |
|
std::vector< SegmentationResult > | run_8UC1 |
|
SegmentationResult | run_8UC3 |
|
std::vector< SegmentationResult > | run_8UC3 |
|
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.
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 ofSegmentation
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.
Prototype
size_t get_input_batch() const =0;
Returns
Batch size.run_8UC1
Function to get running result of the segmentation network.
Prototype
SegmentationResult
run_8UC1(const cv::Mat &image)=0;
Parameters
The following table lists the run_8UC1
function 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.
Prototype
std::vector< SegmentationResult
> run_8UC1(const std::vector< cv::Mat > &images)=0;
Parameters
The following table lists the run_8UC1
function 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 ofSegmentationResult
. run_8UC3
Function to get running result of the segmentation network.
Prototype
SegmentationResult
run_8UC3(const cv::Mat &image)=0;
Parameters
The following table lists the run_8UC3
function 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.
Prototype
std::vector< SegmentationResult
> run_8UC3(const std::vector< cv::Mat > &images)=0;
Parameters
The following table lists the run_8UC3
function 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 ofSegmentationResult
.