当前位置: 首页 > 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…...

Office RibbonX Editor:让Office界面定制变得像搭积木一样简单

Office RibbonX Editor&#xff1a;让Office界面定制变得像搭积木一样简单 【免费下载链接】office-ribbonx-editor An overhauled fork of the original Custom UI Editor for Microsoft Office, built with WPF 项目地址: https://gitcode.com/gh_mirrors/of/office-ribbon…...

HDI 高密度互连板阶数的深度理解

一、概述高密度互连板&#xff08;High Density Interconnector, HDI&#xff09;是通过激光微孔技术和逐层积层工艺实现高密度布线的印制电路板。其阶数划分是行业内统一的技术标准&#xff0c;核心依据为独立积层压合次数与配套激光盲孔制程次数&#xff0c;而非单面层数或钻…...

通过curl命令快速测试Taotoken大模型API的连通性与返回格式

&#x1f680; 告别海外账号与网络限制&#xff01;稳定直连全球优质大模型&#xff0c;限时半价接入中。 &#x1f449; 点击领取海量免费额度 通过curl命令快速测试Taotoken大模型API的连通性与返回格式 在集成大模型能力到应用时&#xff0c;开发者通常需要一种快速、轻量的…...

告别Postman!用APIfox搞定接口测试+自动化,这份保姆级教程带你从环境配置到报告生成

从Postman到APIfox&#xff1a;接口测试自动化的高效迁移指南如果你还在为接口测试中的重复劳动和多环境切换头疼&#xff0c;是时候考虑从Postman迁移到APIfox了。作为一名经历过这个转型过程的开发者&#xff0c;我想分享一些实战经验&#xff0c;帮助你平滑过渡并最大化利用…...

【审计专栏】【财务领域】 第四十九篇 人在企业中的核心资产和核心利益01

编号 类型 企业 (行业/企业产品/企业利益链/生态位与层级) 业务领域 企业性质 企业中人的角色/岗位/利益矩阵 人在企业中的核心资产/附属资产 资产的业务-财务数学模型及数字/数值 关联知识 1 核心经营性资产(如IP、数据、品牌) 行业:人工智能 产品:工业视觉检…...

ComfyUI-Manager完全指南:掌握AI工作流管理的核心技术

ComfyUI-Manager完全指南&#xff1a;掌握AI工作流管理的核心技术 【免费下载链接】ComfyUI-Manager ComfyUI-Manager is an extension designed to enhance the usability of ComfyUI. It offers management functions to install, remove, disable, and enable various custo…...

3分钟上手:NBTExplorer终极指南 - 可视化编辑Minecraft游戏数据的免费神器

3分钟上手&#xff1a;NBTExplorer终极指南 - 可视化编辑Minecraft游戏数据的免费神器 【免费下载链接】NBTExplorer A graphical NBT editor for all Minecraft NBT data sources 项目地址: https://gitcode.com/gh_mirrors/nb/NBTExplorer 你是否曾经想要修改Minecraf…...

如何快速实现U盘文件自动备份:USBCopyer终极指南

如何快速实现U盘文件自动备份&#xff1a;USBCopyer终极指南 【免费下载链接】USBCopyer &#x1f609; 用于在插上U盘后自动按需复制该U盘的文件。”备份&偷U盘文件的神器”&#xff08;写作USBCopyer&#xff0c;读作USBCopier&#xff09; 项目地址: https://gitcode.…...

实测对比,使用Taotoken聚合接口后Agent任务延迟与稳定性观感

&#x1f680; 告别海外账号与网络限制&#xff01;稳定直连全球优质大模型&#xff0c;限时半价接入中。 &#x1f449; 点击领取海量免费额度 实测记录&#xff1a;使用 Taotoken 聚合接口后 Agent 任务延迟与稳定性观感 效果展示类&#xff0c;记录将原有基于单一 API 的 A…...

计算机视觉的实战项目:从0到1搭建属于自己的图像识别系统

作为软件测试从业者&#xff0c;我们每天都在和各类功能验证、兼容性测试、自动化测试框架打交道&#xff0c;对AI领域的实战项目往往觉得“门槛高”“和日常工作不沾边”。但随着AI技术在互联网产品中的落地越来越深入&#xff0c;图像识别功能已经成为很多APP、智能硬件的核心…...