当前位置: 首页 > news >正文

opencv hand openpose

使用opencv c++ 来调用caffemodel

使用opencv 得dnn 模块调用 caffemodel得程序,图片自己输入就行,不做过多得解释,看代码清单。
在这里插入图片描述

在这里插入图片描述

定义手指关节点

const int POSE_PAIRS[20][2] =
{
{0,1}, {1,2}, {2,3}, {3,4}, // thumb
{0,5}, {5,6}, {6,7}, {7,8}, // index
{0,9}, {9,10}, {10,11}, {11,12}, // middle
{0,13}, {13,14}, {14,15}, {15,16}, // ring
{0,17}, {17,18}, {18,19}, {19,20} // small
};

string protoFile = “hand/pose_deploy.prototxt”;
string weightsFile = “hand/pose_iter_102000.caffemodel”;

int nPoints = 22;

代码清单

#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>using namespace std;
using namespace cv;
using namespace cv::dnn;
#ifdef _DEBUG
#pragma comment(lib,"opencv_world455d.lib")
#else
#pragma comment(lib,"opencv_world455.lib")
#endifconst int POSE_PAIRS[20][2] =
{{0,1}, {1,2}, {2,3}, {3,4},         // thumb{0,5}, {5,6}, {6,7}, {7,8},         // index{0,9}, {9,10}, {10,11}, {11,12},    // middle{0,13}, {13,14}, {14,15}, {15,16},  // ring{0,17}, {17,18}, {18,19}, {19,20}   // small
};string protoFile = "hand/pose_deploy.prototxt";
string weightsFile = "hand/pose_iter_102000.caffemodel";int nPoints = 22;int main(int argc, char **argv)
{string imageFile = "qianbo2.jpg";// Take arguments from commmand lineif (argc == 2){imageFile = argv[1];}float thresh = 0.01;Mat frame = imread(imageFile);Mat frameCopy = frame.clone();int frameWidth = frame.cols;int frameHeight = frame.rows;float aspect_ratio = frameWidth / (float)frameHeight;int inHeight = 368;int inWidth = (int(aspect_ratio*inHeight) * 8) / 8;cout << "inWidth = " << inWidth << " ; inHeight = " << inHeight << endl;double t = (double)cv::getTickCount();Net net = readNetFromCaffe(protoFile, weightsFile);Mat inpBlob = blobFromImage(frame, 1.0 / 255, Size(inWidth, inHeight), Scalar(0, 0, 0), false, false);net.setInput(inpBlob);Mat output = net.forward();int H = output.size[2];int W = output.size[3];// find the position of the body partsvector<Point> points(nPoints);for (int n = 0; n < nPoints; n++){// Probability map of corresponding body's part.Mat probMap(H, W, CV_32F, output.ptr(0, n));resize(probMap, probMap, Size(frameWidth, frameHeight));Point maxLoc;double prob;minMaxLoc(probMap, 0, &prob, 0, &maxLoc);if (prob > thresh){circle(frameCopy, cv::Point((int)maxLoc.x, (int)maxLoc.y), 8, Scalar(0, 255, 255), -1);cv::putText(frameCopy, cv::format("%d", n), cv::Point((int)maxLoc.x, (int)maxLoc.y), cv::FONT_HERSHEY_COMPLEX, 1, cv::Scalar(0, 0, 255), 2);}points[n] = maxLoc;}int nPairs = sizeof(POSE_PAIRS) / sizeof(POSE_PAIRS[0]);for (int n = 0; n < nPairs; n++){// lookup 2 connected body/hand partsPoint2f partA = points[POSE_PAIRS[n][0]];Point2f partB = points[POSE_PAIRS[n][1]];if (partA.x <= 0 || partA.y <= 0 || partB.x <= 0 || partB.y <= 0)continue;line(frame, partA, partB, Scalar(0, 255, 255), 8);circle(frame, partA, 8, Scalar(0, 0, 255), -1);circle(frame, partB, 8, Scalar(0, 0, 255), -1);}t = ((double)cv::getTickCount() - t) / cv::getTickFrequency();cout << "Time Taken = " << t << endl;imshow("Keypoints", frameCopy);imshow("Skeleton", frame);imwrite("out.jpg", frame);waitKey();return 0;
}
http://www.lryc.cn/news/101408.html

相关文章:

  • flutter fl_chart 柱状图 柱条数量较多 实现左右滑动 固定y轴
  • CAN学习笔记1:计算机网络
  • NAND flash的坏块
  • 代码随想录算法训练营第二十五天 | 读PDF复习环节3
  • 18.Netty源码之ByteBuf 详解
  • #P0999. [NOIP2008普及组] 排座椅
  • Sentinel 容灾中心的使用
  • 深度学习中简易FC和CNN搭建
  • 【多模态】20、OVR-CNN | 使用 caption 来实现开放词汇目标检测
  • 网络编程 IO多路复用 [select版] (TCP网络聊天室)
  • 数学建模学习(7):单目标和多目标规划
  • Element UI如何自定义样式
  • protobuf入门实践2
  • adb shell使用总结
  • UG NX二次开发(C++)-Tag的含义、Tag类型与其他的转换
  • Informer 论文学习笔记
  • c语言位段知识详解
  • FFmpeg aresample_swr_opts的解析
  • CAN学习笔记3:STM32 CAN控制器介绍
  • 软工导论知识框架(二)结构化的需求分析
  • [SQL挖掘机] - 算术函数 - abs
  • vue拼接html点击事件不生效
  • 【Spring】Spring之依赖注入源码解析
  • 【微软知识】微软相关技术知识分享
  • 12.python设计模式【观察者模式】
  • 重生之我要学C++第五天
  • 复习之linux高级存储管理
  • HuggingGPT Solving AI Tasks with ChatGPT and its Friends in Hugging Face
  • java工程重写jar包中class类覆盖问题
  • Mybatis基于注解与XML开发