#include <iostream>
const int POSE_PAIRS[3][20][2] = {
{ // COCO 身体
{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}
},
{ // MPI 身体
{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 | 打印此帮助消息 }"
"{ p proto | | (必需)模型配置,例如 hand/pose.prototxt }"
"{ m model | | (必需)模型权重,例如 hand/pose_iter_102000.caffemodel }"
"{ i image | | (必需)图像文件的路径(包含单个人或手)}"
"{ d dataset | | 指定训练的模型类型。它可以是 (COCO, MPI, HAND),具体取决于数据集。}"
"{ width | 368 | 通过调整到特定宽度来预处理输入图像。}"
"{ height | 368 | 通过调整到特定高度来预处理输入图像。}"
"{ t threshold | 0.1 | 热图的阈值或置信度值 }"
"{ s scale | 0.003922 | blob 的比例 }"
);
String modelTxt = samples::findFile(parser.get<
string>(
"proto"));
String modelBin = samples::findFile(parser.get<
string>(
"model"));
String imageFile = samples::findFile(parser.get<
String>(
"image"));
int W_in = parser.get<int>("width");
int H_in = parser.get<int>("height");
float thresh = parser.get<float>("threshold");
float scale = parser.get<float>("scale");
if (parser.get<bool>("help") || modelTxt.empty() || modelBin.empty() || imageFile.empty())
{
cout << "一个演示使用预训练的 OpenPose dnn 检测人体或手部姿势的示例应用程序。" << endl;
parser.printMessage();
return 0;
}
int midx, npairs, nparts;
if (!dataset.compare("COCO")) { midx = 0; npairs = 17; nparts = 18; }
else if (!dataset.compare("MPI")) { midx = 1; npairs = 14; nparts = 16; }
else if (!dataset.compare("HAND")) { midx = 2; npairs = 20; nparts = 22; }
else
{
std::cerr << "无法解释数据集参数:" << dataset << std::endl;
exit(-1);
}
{
std::cerr << "无法从文件读取图像:" << imageFile << std::endl;
exit(-1);
}
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;
}
如果数组没有元素,则返回 true。
int64_t int64
MatSize size
定义 mat.hpp:2187
uchar * ptr(int i0=0)
返回指向指定矩阵行的指针。
cv::getTickFrequency
double getTickFrequency()
int rows
行数和列数,如果矩阵具有超过 2 个维度,则为 (-1, -1)
定义 mat.hpp:2165
_Tp y
点的 y 坐标
定义 types.hpp:202
_Tp x
点的 x 坐标
定义 types.hpp:201
用于指定图像或矩形大小的模板类。
Definition types.hpp:335
这个类允许创建和操作综合人工神经网络。
定义 dnn.hpp:475
void setInput(CV_ND InputArray blob, const String &name="", double scalefactor=1.0, const Scalar &mean=Scalar())
设置网络的新输入值。
Mat forward(const String &outputName=String())
运行前向传递以计算名称为 outputName 的图层的输出。
void minMaxLoc(InputArray src, double *minVal, double *maxVal=0, Point *minLoc=0, Point *maxLoc=0, InputArray mask=noArray())
查找数组中的全局最小值和最大值。
std::string String
定义 cvstd.hpp:151
#define CV_32F
Definition interface.h:78
@ circle
定义 gr_skig.hpp:62
Mat blobFromImage(InputArray image, double scalefactor=1.0, const Size &size=Size(), const Scalar &mean=Scalar(), bool swapRB=false, bool crop=false, int ddepth=CV_32F)
从图像创建 4 维 blob。 可选择从中心调整图像大小和裁剪图像...
Net readNet(CV_WRAP_FILE_PATH const String &model, CV_WRAP_FILE_PATH const String &config="", const String &framework="")
读取以支持的格式之一表示的深度学习网络。
void imshow(const String &winname, InputArray mat)
在指定窗口中显示图像。
int waitKey(int delay=0)
等待按键按下。
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR_BGR)
从文件加载图像。
void line(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
绘制连接两点的线段。
int main(int argc, char *argv[])
定义 highgui_qt.cpp:3