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

30-Java 继承

Java 继承 在本教程中&#xff0c;我们将借助示例学习Java中的继承。 继承是OOP&#xff08;面向对象编程&#xff09;的重要功能之一&#xff0c;它使我们能够从现有类中定义一个新类。例如&#xff0c; class Animal {// eat() 方法// sleep() 方法 } class Dog extends A…...

5分钟学会LongCat-Image-Edit:上传图片输入提示词,等待生成结果

5分钟学会LongCat-Image-Edit&#xff1a;上传图片输入提示词&#xff0c;等待生成结果 1. 快速了解LongCat-Image-Edit 你有没有遇到过这样的情况&#xff1a;拍了一张完美的照片&#xff0c;但想修改其中的某个细节&#xff1f;比如把照片里的猫换成狗&#xff0c;或者给产…...

深度学习图像恢复实战:基于Blurr库的统一处理框架与应用

1. 项目概述&#xff1a;当图像处理遇上深度学习最近在折腾一个图像处理相关的项目&#xff0c;需要快速实现一套从模糊图像中恢复细节的流程。说实话&#xff0c;这活儿听起来简单&#xff0c;做起来坑不少。传统的图像锐化滤镜&#xff0c;比如Photoshop里的USM&#xff0c;对…...

告别C++!用Python给SolidWorks 2022写插件,5步搞定自定义菜单(附完整源码)

Python驱动SolidWorks二次开发&#xff1a;5步构建高效插件体系 在工业设计领域&#xff0c;SolidWorks长期占据着三维CAD软件的领导地位&#xff0c;但其传统的C/VB二次开发方式让许多现代开发者望而却步。当Python遇上SolidWorks&#xff0c;我们不仅获得了语法简洁的开发体验…...

医疗C项目必须建立的5级代码审查漏斗:覆盖DO-178C/IEC 62304/FDA SWCG的三重合规验证机制

更多请点击&#xff1a; https://intelliparadigm.com 第一章&#xff1a;医疗嵌入式C语言FDA 2026合规编码的监管演进与范式跃迁 FDA于2024年发布的《Digital Health Center of Excellence Guidance v3.1》正式确立了2026年起对Class II及以上嵌入式医疗设备实施强制性“可追…...

医学影像AI的幻觉问题与CCD解决方案

1. 医学影像AI的幻觉困境与临床需求放射科医生每天需要解读数十甚至上百张医学影像&#xff0c;这项高强度工作正面临AI技术的变革。多模态大语言模型(MLLMs)通过结合视觉编码器和语言模型&#xff0c;展现出令人惊艳的影像描述能力。但当我在实际测试最新模型时&#xff0c;发…...

基于Hermes Agent与Railway的自主AI智能体一键部署实战

1. 项目概述&#xff1a;一键部署你的智能AI助手 最近在折腾AI智能体&#xff0c;发现了一个挺有意思的项目&#xff1a;Hermes Agent。简单来说&#xff0c;这是一个能自我进化的自主AI智能体&#xff0c;最吸引我的是它原生支持Telegram&#xff0c;这意味着你可以直接在Tel…...

nli-MiniLM2-L6-H768批量处理优化:利用GPU并行计算加速大规模文本对推理

nli-MiniLM2-L6-H768批量处理优化&#xff1a;利用GPU并行计算加速大规模文本对推理 1. 引言 处理海量文本对&#xff08;如百万级&#xff09;的自然语言推理任务时&#xff0c;传统的单条处理方式效率极低。以nli-MiniLM2-L6-H768模型为例&#xff0c;当面对大规模数据时&a…...

LLM性别偏见评估:Wino Bias测试与实践

1. 项目背景与核心目标最近在自然语言处理领域&#xff0c;大型语言模型(LLM)在各类基准测试中展现出惊人表现。但作为从业者&#xff0c;我们更关心这些模型在实际应用中可能存在的隐性偏见。这个项目聚焦于一个具体但重要的问题&#xff1a;如何系统评估LLM在性别-职业刻板印…...

告别调参玄学:用PANNs预训练模型搞定音频分类,附AudioSet实战代码

告别调参玄学&#xff1a;用PANNs预训练模型搞定音频分类实战指南 音频分类任务在实际应用中常常面临数据稀缺、模型调优困难等痛点。想象一下这样的场景&#xff1a;你需要开发一个智能家居系统&#xff0c;要求能准确识别婴儿哭声、烟雾报警声等关键声音事件&#xff1b;或者…...