vitis::ai::RoadLine - 2.5 简体中文

Vitis AI Library 用户指南 (UG1354)

Document ID
UG1354
Release Date
2022-06-15
Version
2.5 简体中文
此基本类用于检测来自图像 (cv::Mat) 的车道线检测。

输入为图像 (cv::Mat)。

输出道路标线类型和标记为道路标线的点。

代码样本:

注释: 输入图像大小为 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);
 }

显示模型结果:

图 1. 输出图像

函数快速参考

下表列出了 vitis::ai::RoadLine 类中定义的所有函数:

表 1. 函数快速参考
类型 成员 实参
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