vitis::ai::Hourglass
Hourglass
model, input size is 256x256. Base class for detecting poses of people.
Input is an image (cv:Mat).
Output is HourglassResult
.
Sample code:
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);
}
}
Display of the hourglass model results:
Quick Function Reference
The following table lists all the functions defined in the vitis::ai::Hourglass
class:
Type | Name | Arguments |
---|---|---|
std::unique_ptr< Hourglass > | create |
|
HourglassResult | run |
|
std::vector< HourglassResult > | run |
|
int | getInputWidth |
|
int | getInputHeight |
|
size_t | get_input_batch |
|
create
Factory function to get an instance of derived classes of class Hourglass
.
Prototype
std::unique_ptr< Hourglass
> create(const std::string &model_name, bool need_preprocess=true);
Parameters
The following table lists the create
function arguments.
Type | Name | Description |
---|---|---|
const std::string & | model_name | Model name |
bool | need_preprocess | Normalize with mean/scale or not, default value is true. |
Returns
An instance ofHourglass
class. run
Function to get running result of the hourglass neuron network.
Prototype
HourglassResult
run(const cv::Mat &image)=0;
Parameters
The following table lists the run
function arguments.
Type | Name | Description |
---|---|---|
const cv::Mat & | image | Input data of input image (cv::Mat). |
Returns
HourglassResult
. run
Function to get running results of the hourglass neuron network in batch mode.
Prototype
std::vector< HourglassResult
> run(const std::vector< cv::Mat > &images)=0;
Parameters
The following table lists the run
function arguments.
Type | Name | Description |
---|---|---|
const std::vector< cv::Mat > & | images | Input data of batch input images (vector<cv::Mat>). The size of input images equals batch size obtained by get_input_batch. |
Returns
The vector ofHourglassResult
. getInputWidth
Function to get InputWidth of the hourglass network (input image columns).
Prototype
int getInputWidth() const =0;
Returns
InputWidth of the hourglass networkgetInputHeight
Function to get InputHeight of the hourglass network (input image rows).
Prototype
int getInputHeight() const =0;
Returns
InputHeight of the hourglass network.get_input_batch
Function to get the number of images processed by the DPU at one time.
Prototype
size_t get_input_batch() const =0;