vitis::ai::BoundingBox - 3.0 English

Vitis AI Library User Guide (UG1354)

Document ID
UG1354
Release Date
2023-01-12
Version
3.0 English
Base class for detecting persons and feats from an image (cv::Mat).

Input is an image (cv::Mat).

Output is the enlarged image.

Sample code:

Note: The input image size is 640x480
auto image_file = string(argv[2]);
Mat input_img = imread(image_file);
if (input_img.empty()) {
  cerr << "can't load image! " << argv[2] << endl;
  return -1;
}
auto det = vitis::ai::FairMot::create(argv[1]);
auto result = det->run(input_img);
auto feats = result.feats;
auto bboxes = result.bboxes;
auto img = input_img.clone();
for (auto i = 0u; i < bboxes.size(); ++i) {
  auto box = bboxes[i];
  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);

  LOG(INFO) << "RESULT " << box.label << " :\t" << xmin << "\t" << ymin
            << "\t" << xmax << "\t" << ymax << "\t" << score << "\n";
  LOG(INFO) << "feat size: " << feats[i].size()
            << " First 5 digits: " << feats[i].data[0] + 0.0f << " "
            << feats[i].data[1] + 0.0f << " " << feats[i].data[2] + 0.0f
            << " " << feats[i].data[3] + 0.0f << " "
            << feats[i].data[4] + 0.0f << endl;
  cv::rectangle(img, cv::Point(xmin, ymin), cv::Point(xmax, ymax),
                cv::Scalar(0, 255, 0), 1, 1, 0);
}
auto out = image_file.substr(0, image_file.size() - 4) + "_out.jpg";
LOG(INFO) << "write result to " << out;
cv::imwrite(out, img);

Display of the model results:

Figure 1. result image
result image

Struct of an object coordinates and confidence.

Declaration

typedef struct
{
  float x;
  float y;
  float width;
  float height;
  int label;
  float score;

} vitis::ai::BoundingBox;
Table 1. Structure vitis::ai::BoundingBox Member Description
Member Description
x

x-coordinate. x is normalized relative to the input image columns. Range from 0 to 1.

y

y-coordinate. y is normalized relative to the input image rows. Range from 0 to 1.

width

Body width. Width is normalized relative to the input image columns, Range from 0 to 1.

height

Body height. Heigth is normalized relative to the input image rows, Range from 0 to 1.

label Body detection label. The value ranges from 0 to 21.
score Body detection confidence. The value ranges from 0 to 1.