vitis::ai::RoadLine - 3.5 English

Vitis AI Library User Guide (UG1354)

Document ID
UG1354
Release Date
2023-06-29
Version
3.5 English
Base class for detecting lanedetect from an image (cv::Mat).

Input is an image (cv::Mat).

Output road line type and points marked road line.

Sample code:

Note: The input image size is 640x480
 auto det = vitis::ai::RoadLine::create("vpgnet_pruned_0_99");
 auto image = cv::imread("sample_lanedetect.jpg");
 //    Mat image;
 //    resize(img, image, Size(640, 480));
 if (image.empty()) {
   cerr << "cannot load " << argv[1] << endl;
   abort();
 }

 vector<int> color1 = {0, 255, 0, 0, 100, 255};
 vector<int> color2 = {0, 0, 255, 0, 100, 255};
 vector<int> color3 = {0, 0, 0, 255, 100, 255};

 RoadLineResult results = det->run(image);
 for (auto &line : results.lines) {
   vector<Point> points_poly = line.points_cluster;
   // for (auto &p : points_poly) {
   //  std::cout << p.x << " " << (int)p.y << std::endl;
   //}
   int type = line.type < 5 ? line.type : 5;
   if (type == 2 && points_poly[0].x < image.rows * 0.5)
     continue;
   cv::polylines(image, points_poly, false,
                 Scalar(color1[type], color2[type], color3[type]), 3,
cv::LINE_AA, 0);
 }

Display of the model results:

Figure 1. result image
result image

Quick Function Reference

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

Table 1. Quick Function Reference
Type Member Arguments
std::unique_ptr< RoadLine > create
  • const std::string & model_name
  • bool need_preprocess
int getInputWidth
  • void
int getInputHeight
  • void
size_t get_input_batch
  • void
RoadLineResult run
  • const cv::Mat & image
std::vector< RoadLineResult > run
  • const std::vector< cv::Mat > & images