#include <iostream>
const int POSE_PAIRS[3][20][2] = {
{
{1,2}, {1,5}, {2,3},
{3,4}, {5,6}, {6,7},
{1,8}, {8,9}, {9,10},
{1,11}, {11,12}, {12,13},
{1,0}, {0,14},
{14,16}, {0,15}, {15,17}
},
{
{0,1}, {1,2}, {2,3},
{3,4}, {1,5}, {5,6},
{6,7}, {1,14}, {14,8}, {8,9},
{9,10}, {14,11}, {11,12}, {12,13}
},
{
{0,1}, {1,2}, {2,3}, {3,4},
{0,5}, {5,6}, {6,7}, {7,8},
{0,9}, {9,10}, {10,11}, {11,12},
{0,13}, {13,14}, {14,15}, {15,16},
{0,17}, {17,18}, {18,19}, {19,20}
}};
int main(int argc, char **argv)
{
"{ h help | false | print this help message }"
"{ p proto | | (required) model configuration, e.g. hand/pose.prototxt }"
"{ m model | | (required) model weights, e.g. hand/pose_iter_102000.caffemodel }"
"{ i image | | (required) path to image file (containing a single person, or hand) }"
"{ width | 368 | Preprocess input image by resizing to a specific width. }"
"{ height | 368 | Preprocess input image by resizing to a specific height. }"
"{ t threshold | 0.1 | threshold or confidence value for the heatmap }"
);
String modelTxt = parser.
get<
string>(
"proto");
String modelBin = parser.
get<
string>(
"model");
int W_in = parser.
get<
int>(
"width");
int H_in = parser.
get<
int>(
"height");
float thresh = parser.
get<
float>(
"threshold");
if (parser.
get<
bool>(
"help") || modelTxt.empty() || modelBin.empty() || imageFile.empty())
{
cout << "A sample app to demonstrate human or hand pose detection with a pretrained OpenPose dnn." << endl;
return 0;
}
{
std::cerr << "Can't read image from the file: " << imageFile << std::endl;
exit(-1);
}
int midx, npairs;
int nparts = result.
size[1];
if (nparts == 19)
{
midx = 0;
npairs = 17;
nparts = 18;
}
else if (nparts == 16)
{
midx = 1;
npairs = 14;
}
else if (nparts == 22)
{
midx = 2;
npairs = 20;
}
else
{
cerr << "there should be 19 parts for the COCO model, 16 for MPI, or 22 for the hand one, but this model has " << nparts << " parts." << endl;
return (0);
}
vector<Point> points(22);
for (int n=0; n<nparts; n++)
{
double conf;
if (conf > thresh)
p = pm;
points[n] = p;
}
float SX = float(img.
cols) / W;
float SY = float(img.
rows) / H;
for (int n=0; n<npairs; n++)
{
Point2f a = points[POSE_PAIRS[midx][n][0]];
Point2f b = points[POSE_PAIRS[midx][n][1]];
if (a.
x<=0 || a.
y<=0 || b.
x<=0 || b.
y<=0)
continue;
}
return 0;
}