vitis::ai::BoundingBox - 3.5 日本語

Vitis AI ライブラリ ユーザー ガイド (UG1354)

Document ID
UG1354
Release Date
2023-06-29
Version
3.5 日本語
イメージ (cv::Mat) から人物と特徴を検出するためのベース クラス。

入力はイメージ (cv::Mat) です。

出力は拡大されたイメージです。

サンプル コード:

注記: 入力イメージのサイズは 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);

モデルの結果を次に示します。

図 1. 結果イメージ
result image

物体の座標と信頼度からなる構造体。

宣言

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

} vitis::ai::BoundingBox;
表 1. 構造体 vitis::ai::BoundingBox のメンバーの説明
メンバー 説明
x

x 座標。x は入力イメージの列を基準に正規化されています。範囲は 0 ~ 1 です。

y

y 座標。y は入力イメージの行を基準に正規化されています。範囲は 0 ~ 1 です。

width

身体の幅。幅は入力イメージの列を基準に正規化されており、範囲は 0 ~ 1 です。

height

身体の高さ。高さは入力イメージの行を基準に正規化されており、範囲は 0 ~ 1 です。

label 身体の検出ラベル。値の範囲は 0 ~ 21 です。
score 身体の検出の信頼度。値の範囲は 0 ~ 1 です。