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

kinect v2获取人体骨骼数据

#include <iostream>
#include <string>
#include <WS2tcpip.h>
#pragma comment (lib, "ws2_32.lib")
#include <chrono>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>        // 核心功能,包括矩阵和数组操作
#include <opencv2/imgproc.hpp>     // 图像处理功能
#include <opencv2/highgui.hpp>     // 图形用户界面相关功能,用于显示图像和交互
#include <opencv2/video.hpp>       // 视频处理功能
#include <Kinect.h>
#include <fstream>
#include<chrono>
#include<thread>using namespace cv;void DrawLine(cv::Mat& Img, const Joint& r1, const Joint& r2, ICoordinateMapper* pMapper)
{if (r1.TrackingState == TrackingState_Tracked && r2.TrackingState == TrackingState_Tracked){ColorSpacePoint p1, p2;pMapper->MapCameraPointToColorSpace(r1.Position, &p1);pMapper->MapCameraPointToColorSpace(r2.Position, &p2);line(Img, Point(p1.X, p1.Y), Point(p2.X, p2.Y), Vec3b(0, 0, 255), 5);circle(Img, Point(p1.X, p1.Y), 10, (0, 0, 255), -1);circle(Img, Point(p2.X, p2.Y), 10, (0, 0, 255), -1);}
}int main()
{IKinectSensor* pSensor = nullptr;GetDefaultKinectSensor(&pSensor); pSensor->Open(); IColorFrameSource* pFrameSource = nullptr;pSensor->get_ColorFrameSource(&pFrameSource);int iWidth = 0, iHeight = 0;IFrameDescription* pFrameDescription = nullptr;pFrameSource->get_FrameDescription(&pFrameDescription);pFrameDescription->get_Width(&iWidth);pFrameDescription->get_Height(&iHeight);IColorFrameReader* pColorFrameReader = nullptr;pFrameSource->OpenReader(&pColorFrameReader);pFrameDescription->Release();pFrameDescription = nullptr;pFrameSource->Release();pFrameSource = nullptr;UINT uBufferSize = 0;cv::Mat mColorImg(iHeight, iWidth, CV_8UC4);uBufferSize = iHeight * iWidth * 4 * sizeof(BYTE);IBodyFrameReader* pBodyFrameReader = nullptr;IBody** aBodyData = nullptr;INT32 iBodyCount = 0;IBodyFrameSource* pBodySource = nullptr;pSensor->get_BodyFrameSource(&pBodySource);pBodySource->get_BodyCount(&iBodyCount);aBodyData = new IBody*[iBodyCount];for (int i = 0; i < iBodyCount; ++i)aBodyData[i] = nullptr;		pBodySource->OpenReader(&pBodyFrameReader);pBodySource->Release();pBodySource = nullptr;ICoordinateMapper* pCoordinateMapper = nullptr;pSensor->get_CoordinateMapper(&pCoordinateMapper);cv::namedWindow("Body Image", cv::WINDOW_NORMAL);cv::resizeWindow("Body Image", 560, 360);	while (true){IColorFrame* pColorFrame = nullptr;if (pColorFrameReader->AcquireLatestFrame(&pColorFrame) == S_OK){pColorFrame->CopyConvertedFrameDataToArray(uBufferSize, mColorImg.data, ColorImageFormat_Bgra);pColorFrame->Release();}cv::Mat mImg = mColorImg.clone();IBodyFrame* pBodyFrame = nullptr;if (pBodyFrameReader->AcquireLatestFrame(&pBodyFrame) == S_OK){// std::cout << "读取人体帧数据成功" << std::endl;if (pBodyFrame->GetAndRefreshBodyData(iBodyCount, aBodyData) == S_OK){// std::cout << "获取骨骼帧中的骨骼数据成功" << std::endl;for (int i = 0; i < iBodyCount; ++i){IBody* pBody = aBodyData[i];BOOLEAN bTracked = false;if ((pBody->get_IsTracked(&bTracked) == S_OK) && bTracked){// std::cout << "骨骼已被跟踪" << std::endl;// std::cout << "跟踪序号:" << i << std::endl;Joint aJoints[JointType_Count];if (pBody->GetJoints(JointType_Count, aJoints) == S_OK){//脊柱DrawLine(mImg, aJoints[JointType_SpineBase], aJoints[JointType_SpineMid], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_SpineMid], aJoints[JointType_SpineShoulder], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_SpineShoulder], aJoints[JointType_Neck], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_Neck], aJoints[JointType_Head], pCoordinateMapper);//左 armDrawLine(mImg, aJoints[JointType_SpineShoulder], aJoints[JointType_ShoulderLeft], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_ShoulderLeft], aJoints[JointType_ElbowLeft], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_ElbowLeft], aJoints[JointType_WristLeft], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_WristLeft], aJoints[JointType_HandLeft], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_HandLeft], aJoints[JointType_HandTipLeft], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_WristLeft], aJoints[JointType_ThumbLeft], pCoordinateMapper);//右armDrawLine(mImg, aJoints[JointType_SpineShoulder], aJoints[JointType_ShoulderRight], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_ShoulderRight], aJoints[JointType_ElbowRight], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_ElbowRight], aJoints[JointType_WristRight], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_WristRight], aJoints[JointType_HandRight], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_HandRight], aJoints[JointType_HandTipRight], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_WristRight], aJoints[JointType_ThumbRight], pCoordinateMapper);//左legDrawLine(mImg, aJoints[JointType_SpineBase], aJoints[JointType_HipLeft], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_HipLeft], aJoints[JointType_KneeLeft], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_KneeLeft], aJoints[JointType_AnkleLeft], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_AnkleLeft], aJoints[JointType_FootLeft], pCoordinateMapper);//右legDrawLine(mImg, aJoints[JointType_SpineBase], aJoints[JointType_HipRight], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_HipRight], aJoints[JointType_KneeRight], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_KneeRight], aJoints[JointType_AnkleRight], pCoordinateMapper);DrawLine(mImg, aJoints[JointType_AnkleRight], aJoints[JointType_FootRight], pCoordinateMapper);// *************************保存TXT数据*************************//创建一个名为"data.txt"的文本文件,并清空其中的内容std::ofstream outfile("data_test139.txt", std::ios::trunc);for (int s = 0; s < JointType_Count; s++){outfile << aJoints[s].Position.X << "\t" << aJoints[s].Position.Y << "\t" << aJoints[s].Position.Z << std::endl;}outfile << std::endl;std::cout << "骨骼关节点数据写入成功" << std::endl;}}//追踪失败else {if (pBody->get_IsTracked(&bTracked) != S_OK) {std::cerr << "骨骼追踪失败,Failed to read body tracking state. Error code: " << pBody->get_IsTracked(&bTracked) << std::endl;}//未被追踪else if (!bTracked){std::cerr << "骨骼未被追踪,Body is not being tracked." << std::endl;}}}}else{std::cerr << "Can't read body data" << std::endl;}pBodyFrame->Release();}cv::imshow("Body Image", mImg);if (cv::waitKey(5) == VK_ESCAPE){break;}}pSensor->Close();pSensor->Release();pSensor = nullptr;return 0;
}

相关文章:

kinect v2获取人体骨骼数据

#include <iostream> #include <string> #include <WS2tcpip.h> #pragma comment (lib, "ws2_32.lib") #include <chrono> #include <opencv2/opencv.hpp> #include <opencv2/core.hpp> // 核心功能&#xff0c;包括矩阵…...

JDK、JRE及JVM的关系及作用

1、JDK JDK&#xff08;Java Development Kit&#xff09;是java程序的开发工具集&#xff0c;包含了运行环境JRE、开发工具及基础类库等。 注意&#xff1a; 生产环境&#xff0c;目前使用JDK同时作为开发和运行环境的比较多&#xff0c;主要是为了排查问题方便的同时不用切…...

组学数据上传(六)|GEO数据库数据上传实操

最近有些老师反馈文章发表时要求提供GEO登录号,如:GSEXXXX&#xff0c;问要怎么获取这种登录号?这时就需要把数据上传至GEO数据库了。还在等什么&#xff0c;跟着小编了解下GEO数据库&#xff0c;手把手教您上传数据至GEO数据库。 GEO数据库全称GENE EXPRESSION OMNIBUS&…...

洛谷,Hydro,Vijos,博客园,GitHub 分别是什么?

洛谷&#xff08;luogu.com.cn&#xff09;是一个在线的算法竞赛平台&#xff0c;提供了大量的算法题目&#xff0c;可以进行刷题、比赛、交流等。Hydro 是一个开源的在线评测系统&#xff0c;用于处理洛谷和其他OJ平台的算法评测。Vijos&#xff08;vijos.org&#xff09;是另…...

自学VUE笔记

一、基础语法学习 1、Attribute 绑定 a、绑定单个属性&#xff1a;给这个div 增加id 属性 ​ <div v-bind:id"dynamicId"></div>简写&#xff1a; <div :id"dynamicId"></div> b、绑定多个属性值 data() {return {objectOf…...

系列四十二、Spring的事务传播行为案例演示(二)#REQUIRED

一、演示Spring的默认传播行为&#xff08;REQUIRED&#xff09; 1.1、运行之前表中的数据 1.2、StockServiceImpl /*** Author : 一叶浮萍归大海* Date: 2023/10/30 15:43* Description:*/ Service(value "stockServiceREQUIRED") public class StockServiceImpl…...

oracle rac-归档满处理

有客户反馈数据库无法使用了&#xff0c;客户手动启动报错如下 SQL> startup; ORACLE instance started. Total System Global Area 2.6924E10 bytes Fixed Size 2265984 bytes Variable Size 1.3959E10 bytes Database Buffers 1.2952E10 bytes R…...

Python Django 之全局配置 settings 详解

文章目录 1 概述1.1 Django 目录结构 2 常用配置&#xff1a;settings.py2.1 注册 APP&#xff1a;INSTALLED_APPS2.2 模板路径&#xff1a;TEMPLATES2.3 静态文件&#xff1a;STATICFILES_DIRS2.4 数据库&#xff1a;DATABASES2.5 允许访问的主机&#xff1a;ALLOWED_HOSTS 1 …...

挑选MES系统供应商,需要考虑哪些重要因素?

挑选MES系统供应商时&#xff0c;需要考虑下述几个重要因素&#xff1a; 1.功能与特性&#xff1a;MES系统的功能和特性尤为重要。切实保障挑选的服务商可以满足企业的实际需求&#xff0c;包含生产计划管理、物料追踪、质量管理、机器设备等多个方面的功能。 2.系统可扩展性&a…...

Ai创作系统ChatGPT网站源码+图文搭建教程+支持GPT4.0+支持ai绘画(Midjourney)

一、AI创作系统 SparkAi创作系统是基于OpenAI很火的ChatGPT进行开发的Ai智能问答系统AI绘画系统&#xff0c;支持OpenAI GPT全模型国内AI全模型。本期针对源码系统整体测试下来非常完美&#xff0c;可以说SparkAi是目前国内一款的ChatGPT对接OpenAI软件系统。那么如何搭建部署…...

基于计算机视觉的坑洼道路检测和识别-MathorCup A(深度学习版本)

1 2023 年 MathorCup 高校数学建模挑战赛——大数据竞赛 赛道 A&#xff1a;基于计算机视觉的坑洼道路检测和识别 使用深度学习模型&#xff0c;pytorch版本进行图像训练和预测&#xff0c;使用ResNet50模型 2 文件夹预处理 因为给定的是所有图片都在一个文件夹里面&#xf…...

【考研数学】概率论与数理统计 —— 第七章 | 参数估计(1,基本概念及点估计法)

文章目录 引言一、参数估计的概念二、参数的点估计2.1 矩估计法2.2 最大似然估计法 写在最后 引言 我们之前学了那么多分布&#xff0c;如正态分布 N ( μ , σ 2 ) N(\mu,\sigma^2) N(μ,σ2)&#xff0c;泊松分布 P ( λ ) P(\lambda) P(λ) 等等&#xff0c;都是在已知 …...

获取文本长度

使用TextView的getLineCount方法&#xff0c;它可以返回TextView当前显示的行数。但是&#xff0c;这个方法只有在TextView绘制完成后才能返回正确的值&#xff0c;否则可能返回0。因此&#xff0c;需要在TextView的post方法中调用&#xff0c;或者在onWindowFocusChanged方法中…...

python html(文件/url/html字符串)转pdf

安装库 pip install pdfkit第二步 下载程序wkhtmltopdf https://wkhtmltopdf.org/downloads.html 下载7z压缩包 解压即可, 无需安装 解压后结构应该是这样, 我喜欢放在项目里, 相对路径引用(也可以使用绝对路径, 放其他地方) import pdfkit# 将 wkhtmltopdf.exe程序 路径 p…...

Spring概述

Spring概述 Spring 是最受欢迎的企业级 Java 应用程序开发框架&#xff0c;数以百万的来自世界各地的开发人员使用 Spring 框架来创建性能好、易于测试、可重用的代码。 Spring 框架是一个开源的 Java 平台&#xff0c;它最初是由 Rod Johnson 编写的&#xff0c;并且于 2003 …...

Linux网卡

网卡 网卡&#xff08;Network Interface Card&#xff0c;NIC&#xff09;是一种计算机硬件设备&#xff0c;也称为网络适配器或网络接口控制器。一个网卡就是一个接口 网卡组成和工作原理参考https://blog.csdn.net/tao546377318/article/details/51602298 每个网卡都拥有唯…...

【Python机器学习】零基础掌握ElasticNet变量选择回归器

如何优雅地解决房价预测问题? 房价预测一直是一个热门而复杂的话题。假设一个地产商希望准确地预测不同城市区域的房价,以便更有效地进行房地产投资。问题在于,房价是由多种因素共同决定的,例如地段、房屋面积、交通便利程度等。 为了解决这个问题,一个可行的思路是使用…...

【数据结构】模拟实现Vecotr

namespace my_vector {template <class T>class vector{public:typedef T* iterator;typedef const T* const_iterator;//常量指针&#xff0c;指针指向的值不可以变&#xff1b;//构造函数vector():start(nullptr),finish(nullptr),end_of_storage(nullptr){}//析构函数…...

Qt开发: 利用Qt的charts模块绘制曲线、饼图、柱状图、折线图等各种图表

一、前言 Qt Charts模块是Qt提供的一个用于创建各种类型图表的功能模块。为开发人员提供了一种简单而强大的方式来可视化数据。Qt Charts模块基于Qt GUI框架构建,可以与其他Qt模块无缝集成,例如Qt Widgets、Qt Quick和Qt OpenGL。 Qt Charts模块包含了几个核心类: (1)Q…...

Redis:加速你的应用响应时间,提升用户体验

绝大部分写业务的程序员&#xff0c;在实际开发中使用 Redis 的时候&#xff0c;只会 Set Value 和 Get Value 两个操作&#xff0c;对 Redis 整体缺乏一个认知。这里对 Redis 常见问题做一个总结&#xff0c;解决大家的知识盲点。 1、为什么使用 Redis 在项目中使用 Redis&am…...

PvZ Toolkit:让经典游戏重获新生的开源魔法棒

PvZ Toolkit&#xff1a;让经典游戏重获新生的开源魔法棒 【免费下载链接】pvztoolkit 植物大战僵尸 PC 版综合修改器 项目地址: https://gitcode.com/gh_mirrors/pv/pvztoolkit 还记得小时候熬夜玩《植物大战僵尸》的时光吗&#xff1f;阳光总是不够用&#xff0c;最后…...

网盘直链下载助手:轻松获取八大主流网盘真实下载链接的实用工具

网盘直链下载助手&#xff1a;轻松获取八大主流网盘真实下载链接的实用工具 【免费下载链接】Online-disk-direct-link-download-assistant 一个基于 JavaScript 的网盘文件下载地址获取工具。基于【网盘直链下载助手】修改 &#xff0c;支持 百度网盘 / 阿里云盘 / 中国移动云…...

国央企如何推动内部技术创新与外部合作?

观点作者&#xff1a;科易网-国家科技成果转化&#xff08;厦门&#xff09;示范基地 一、现状概述&#xff1a;国央企科技创新的双重困境 在数字经济时代&#xff0c;技术创新与外部合作已成为国央企提升核心竞争力、实现高质量发展的关键路径。然而&#xff0c;当前国央企在推…...

移动端CV模型新选择:实测MobileViTv3在图像分类、分割、检测三大任务上的表现(附复现指南)

MobileViTv3实战评测&#xff1a;轻量化视觉Transformer在三大CV任务中的突破表现 当我们在移动设备上运行图像识别应用时&#xff0c;常常面临一个两难选择——要么接受低精度的轻量级模型&#xff0c;要么忍受高延迟的大型模型。MobileViTv3的出现打破了这一僵局&#xff0c;…...

nli-MiniLM2-L6-H768保姆级教程:Windows/Mac/Linux三平台NLI本地化部署

nli-MiniLM2-L6-H768保姆级教程&#xff1a;Windows/Mac/Linux三平台NLI本地化部署 1. 引言 nli-MiniLM2-L6-H768是一个专为自然语言推理(NLI)与零样本分类设计的轻量级交叉编码器(Cross-Encoder)模型。它虽然体积小巧&#xff0c;但在精度上接近BERT-base模型&#xff0c;同…...

暗黑3智能宏工具D3KeyHelper:一键解放双手的游戏效率革命

暗黑3智能宏工具D3KeyHelper&#xff1a;一键解放双手的游戏效率革命 【免费下载链接】D3keyHelper D3KeyHelper是一个有图形界面&#xff0c;可自定义配置的暗黑3鼠标宏工具。 项目地址: https://gitcode.com/gh_mirrors/d3/D3keyHelper 还在为暗黑3中重复的技能操作感…...

从“工具叠加”到“工作流革命”:龙虾与 IMA 的深度整合重塑了人机协作的边界

2026年3月&#xff0c;当行业还在争论Agent的实用性边界时&#xff0c;腾讯 ima skill 与 OpenClaw&#xff08;龙虾&#xff09;的深度打通&#xff0c;悄然完成了从概念验证到生产力落地的关键一跃。这不再是一次简单的功能更新&#xff0c;而是一个范式转移的信号&#xff1…...

Mattermost Desktop社区支持与安全漏洞报告流程

Mattermost Desktop社区支持与安全漏洞报告流程 【免费下载链接】desktop Mattermost Desktop application for Windows, Mac and Linux 项目地址: https://gitcode.com/gh_mirrors/desktop1/desktop Mattermost Desktop是一款适用于Windows、Mac和Linux的开源桌面应用&…...

C/C++程序设计的基本概念详解

学C语言有很长一段时间了&#xff0c;想做做笔记&#xff0c;把C和C相关的比较容易忽视的地方记下来&#xff0c;也希望可以给需要的同学一些帮助。我的这些文章不想对C和C的语法进行讲解和罗列&#xff0c;这些东西随便找一本书就讲的比我清楚&#xff0c;我只是想把一般人忽视…...

ClawShield:为AI代理构建纵深防御安全架构的实战指南

1. 项目概述&#xff1a;为AI代理穿上“防弹衣”如果你正在企业内部或自己的项目中部署AI代理&#xff0c;比如基于OpenClaw、LangChain或AutoGPT构建的智能助手&#xff0c;那么一个无法回避的挑战正摆在面前&#xff1a;如何确保这些拥有强大能力的“数字员工”不会泄露敏感信…...