vitis::ai::RefineDet - 2.0 English

Vitis AI Library User Guide (UG1354)

Document ID
UG1354
Release Date
2022-01-20
Version
2.0 English
Base class for detecting pedestrians in the input image (cv::Mat).

Input is an image (cv::Mat).

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

Sample code:

auto det = vitis::ai::RefineDet::create("refinedet_pruned_0_8");
auto image = cv::imread("sample_refinedet.jpg");
cout << "load image" << endl;
if (image.empty()) {
  cerr << "cannot load " << argv[1] << endl;
  abort();
}

auto results = det->run(image);

auto img = image.clone();
for (auto &box : results.bboxes) {
    float x = box.x * (img.cols);
    float y = box.y * (img.rows);
    int xmin = x;
    int ymin = y;
    int xmax = x + (box.width) * (img.cols);
    int ymax = y + (box.height) * (img.rows);
    float score = box.score;
    xmin = std::min(std::max(xmin, 0), img.cols);
    xmax = std::min(std::max(xmax, 0), img.cols);
    ymin = std::min(std::max(ymin, 0), img.rows);
    ymax = std::min(std::max(ymax, 0), img.rows);

    cv::rectangle(img, cv::Point(xmin, ymin), cv::Point(xmax, ymax),
                    cv::Scalar(0, 255, 0), 1, 1, 0);
}
auto out = "sample_refinedet_result.jpg";
LOG(INFO) << "write result to " << out;
cv::imwrite(out, img);

Display of the model results:

Figure 1. result image
Image sample_refinedet_result.jpg

Quick Function Reference

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

Table 1. Quick Function Reference
Type Name Arguments
std::unique_ptr< RefineDet > create
  • const std::string & model_name
  • bool need_preprocess
RefineDetResult run
  • const cv::Mat & image
std::vector< RefineDetResult > run
  • const std::vector< cv::Mat > & images
std::vector< vitis::ai::RefineDetResult > run
  • const std::vector< vart::xrt_bo_t > & input_bos