vitis::ai::Hourglass - 3.5 简体中文

Vitis AI Library 用户指南 (UG1354)

Document ID
UG1354
Release Date
2023-06-29
Version
3.5 简体中文
Hourglass 模型,输入大小为 256x256。

此基本类用于检测人的姿态。

输入为图像 (cv:Mat)。

输出为 HourglassResult

代码样本:

auto image = cv::imread(argv[2]);
if (image.empty()) {
  std::cerr << "cannot load " << argv[2] << std::endl;
  abort();
}
auto det = vitis::ai::Hourglass::create(argv[1]);
vector<vector<int>> limbSeq = {{0, 1},  {1, 2},   {2, 6},  {3, 6},  {3, 4}, {4, 5},
                               {6, 7},   {7, 8},  {8, 9}, {7, 12},
                               {12, 11}, {11, 10}, {7, 13}, {13, 14}, {14, 15}};

auto results = det->run(image.clone());
for (size_t i = 0; i < results.poses.size(); ++i) {
  cout<< results.poses[i].point<<endl;
  if (results.poses[i].type == 1) {
    cv::circle(image, results.poses[i].point, 5, cv::Scalar(0, 255, 0),
               -1);
  }
}
for (size_t i = 0; i < limbSeq.size(); ++i) {
  Result a = results.poses[limbSeq[i][0]];
  Result b = results.poses[limbSeq[i][1]];
  if (a.type == 1 && b.type == 1) {
    cv::line(image, a.point, b.point, cv::Scalar(255, 0, 0), 3, 4);
  }
}

显示沙漏模型结果:

图 1. 沙漏结果图像
hourglass result image

函数快速参考

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

表 1. 函数快速参考
类型 成员 实参
std::unique_ptr< Hourglass > create
  • const std::string & model_name
  • bool need_preprocess
HourglassResult run
  • const cv::Mat & image
std::vector< HourglassResult > run
  • const std::vector< cv::Mat > & images
int getInputWidth
  • void
int getInputHeight
  • void
size_t get_input_batch
  • void