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

紧急更新!OpenAI API v4.5对脑筋急转弯类输出新增隐式过滤机制——立即启用这7个绕过策略,保住你的创意产能

更多请点击&#xff1a; https://codechina.net 第一章&#xff1a;OpenAI API v4.5脑筋急转弯过滤机制的底层原理与影响评估 OpenAI API v4.5 引入的脑筋急转弯过滤机制并非独立模块&#xff0c;而是深度集成于请求预处理与响应后置校验双阶段的语义安全策略。其核心依赖于轻…...

VideoSrt终极指南:3步实现视频自动字幕生成,告别手动打轴烦恼

VideoSrt终极指南&#xff1a;3步实现视频自动字幕生成&#xff0c;告别手动打轴烦恼 【免费下载链接】video-srt-windows 这是一个可以识别视频语音自动生成字幕SRT文件的开源 Windows-GUI 软件工具。 项目地址: https://gitcode.com/gh_mirrors/vi/video-srt-windows …...

前端可访问性:键盘导航的无障碍设计实践

前端可访问性&#xff1a;键盘导航的无障碍设计实践 前言 各位前端小伙伴&#xff0c;今天咱们来聊聊键盘导航的无障碍问题。想象一下&#xff1a; 你设计了一个漂亮的网站&#xff0c;所有交互都需要鼠标视力正常的用户觉得"交互流畅"但键盘用户完全无法使用视障用户…...

CSS背景效果完全指南

CSS背景效果完全指南 引言 CSS背景效果是美化网页的重要手段&#xff0c;通过合理使用背景属性&#xff0c;可以创造出丰富的视觉效果。本文将深入探讨CSS背景的各种属性和高级技巧。 一、背景基础 1.1 background-color .element {background-color: #4CAF50;background-color…...

Chrome抓包失败原因与Burp代理设置全解析

1. 这不是“装个插件就完事”的操作&#xff0c;而是理解代理本质的第一课很多人点开Burp Suite&#xff0c;双击启动&#xff0c;看到界面就以为“抓包开始了”——结果在谷歌浏览器里按F12&#xff0c;Network标签页刷半天&#xff0c;连个请求影子都看不到&#xff1b;或者点…...

多模态AI Agent架构:如何无缝融合文本、图像与行动?

多模态AI Agent架构:如何无缝融合文本、图像与行动? 摘要 随着GPT-4V、Gemini等多模态大模型的普及,AI已经从“能读会写”的文本时代进入“能看会认”的多模态时代,但当前绝大多数多模态应用仍停留在“感知-回答”的表层交互,缺乏将多模态感知结果转化为实际行动的能力。…...

【信息科学与工程学】【通信工程】第四篇 通信网络的数学架构 03 城域网中的组合数学方程02

城域网深度融合优化方程组(编号501-550) 基于前文建立的综合优化框架,以下是新增的50个(编号501-550)深度融合地理、人口、业务、物理、架构、经济、环境等多维度的优化方程组,构建完整的城域网数字孪生优化模型。 城市级网络综合优化方程组 编号 耦合维度 优化目标 …...

Open5GS实战指南:构建企业级5G核心网解决方案

Open5GS实战指南&#xff1a;构建企业级5G核心网解决方案 【免费下载链接】open5gs Open5GS is a C-language Open Source implementation for 5G Core and EPC, i.e. the core network of LTE/NR network (Release-17) 项目地址: https://gitcode.com/gh_mirrors/op/open5gs…...

深度解析unrpa:Ren‘Py游戏资源提取工具的核心技术与实践指南

深度解析unrpa&#xff1a;RenPy游戏资源提取工具的核心技术与实践指南 【免费下载链接】unrpa A program to extract files from the RPA archive format. 项目地址: https://gitcode.com/gh_mirrors/un/unrpa unrpa是一款专为RenPy视觉小说引擎设计的RPA归档格式提取工…...

为OpenClaw配置Taotoken作为OpenAI兼容供应商的完整流程

&#x1f680; 告别海外账号与网络限制&#xff01;稳定直连全球优质大模型&#xff0c;限时半价接入中。 &#x1f449; 点击领取海量免费额度 为OpenClaw配置Taotoken作为OpenAI兼容供应商的完整流程 OpenClaw是一款流行的AI智能体开发工具&#xff0c;它允许开发者便捷地接…...