vitis::ai::YOLOv8 - 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 objects in the input image (cv::Mat).

Input is an image (cv::Mat).

Output is the position of the pedestrians in the input image.

Sample code:

static cv::Scalar getColor(int label) {
  return cv::Scalar(label * 2, 255 - label * 2, label + 50);
}

auto yolo = vitis::ai::YOLOv8::create("yolov8", true);

Mat img = cv::imread("sample_yolov8.jpg");
auto results = yolov8->run(img);
for (const auto& result : results.bboxes) {
  int label = result.label;
  auto& box = result.box;
  LOG_IF(INFO, is_jpeg) << "RESULT: " << label << "\t" << std::fixed
                        << std::setprecision(2) << box[0] << "\t" << box[1]
                        << "\t" << box[2] << "\t" << box[3] << "\t"
                        << std::setprecision(6) << result.score << "\n";

  cv::rectangle(image, cv::Point(box[0], box[1]), cv::Point(box[2], box[3]),
                getColor(label), 1, 1, 0);
}

Quick Function Reference

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

Table 1. Quick Function Reference
Type Member Arguments
std::unique_ptr< YOLOv8 > create
  • const std::string & model_name
  • bool need_preprocess
std::unique_ptr< YOLOv8 > create
  • const std::string & model_name
  • xir::Attrs * attrs
  • bool need_preprocess
YOLOv8Result run
  • const cv::Mat & image
std::vector< YOLOv8Result > run
  • const std::vector< cv::Mat > & images