-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdetectBody.h
127 lines (104 loc) · 3.28 KB
/
detectBody.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#pragma once
#include <Kinect.h>
#include<iostream>
#include<time.h>
#include<fstream>
#include"generateBody.h"
#include"KinectJointFilter.h"
#define Joint_count 24
#pragma comment(lib, "kinect20.lib")
using namespace std;
template<class Interface>
inline void SafeRelease(Interface *& pInterfaceToRelease)
{
if (pInterfaceToRelease != NULL) {
pInterfaceToRelease->Release();
pInterfaceToRelease = NULL;
}
}
mat JointTransform(Joint *prejoint);
bool detectJoint(HRESULT hResult, IBodyFrameReader *pBodyReader,mat &trans_joint)
{
IBodyFrame *pBodyFrame = nullptr;
hResult = pBodyReader->AcquireLatestFrame(&pBodyFrame);
if (SUCCEEDED(hResult)) {
IBody *pBody[BODY_COUNT] = { 0 };
hResult = pBodyFrame->GetAndRefreshBodyData(BODY_COUNT, pBody);
if (SUCCEEDED(hResult)) {
for (int count = 0; count < BODY_COUNT; count++) {
BOOLEAN bTracked = false;
hResult = pBody[count]->get_IsTracked(&bTracked);
if (SUCCEEDED(hResult) && bTracked) {
Joint joint[JointType::JointType_Count];
/////////////////////////////
hResult = pBody[count]->GetJoints(JointType::JointType_Count, joint);//joint
trans_joint = JointTransform(joint);
cout << " OK" << endl;
return TRUE;
}
}
}
for (int count = 0; count < BODY_COUNT; count++) {
SafeRelease(pBody[count]);
}
}
SafeRelease(pBodyFrame);
return FALSE;
}
//Joint transform
mat JointTransform(Joint *prejoint)
{
mat tmp = zeros(24,3);
//get index0
tmp(0, 0) = prejoint[0].Position.X;
tmp(1, 0) = prejoint[12].Position.X;
tmp(2, 0) = prejoint[16].Position.X;
tmp(4, 0) = prejoint[13].Position.X;
tmp(5, 0) = prejoint[17].Position.X;
tmp(6, 0) = prejoint[1].Position.X;
tmp(7, 0) = prejoint[14].Position.X;
tmp(8, 0) = prejoint[18].Position.X;
tmp(12, 0) = prejoint[2].Position.X;
tmp(15, 0) = prejoint[3].Position.X;
tmp(16, 0) = prejoint[4].Position.X;
tmp(17, 0) = prejoint[8].Position.X;
tmp(18, 0) = prejoint[5].Position.X;
tmp(19, 0) = prejoint[9].Position.X;
tmp(20, 0) = prejoint[6].Position.X;
tmp(21, 0) = prejoint[10].Position.X;
//get index1
tmp(0, 1) = prejoint[0].Position.Y;
tmp(1, 1) = prejoint[12].Position.Y;
tmp(2, 1) = prejoint[16].Position.Y;
tmp(4, 1) = prejoint[13].Position.Y;
tmp(5, 1) = prejoint[17].Position.Y;
tmp(6, 1) = prejoint[1].Position.Y;
tmp(7, 1) = prejoint[14].Position.Y;
tmp(8, 1) = prejoint[18].Position.Y;
tmp(12, 1) = prejoint[2].Position.Y;
tmp(15, 1) = prejoint[3].Position.Y;
tmp(16, 1) = prejoint[4].Position.Y;
tmp(17, 1) = prejoint[8].Position.Y;
tmp(18, 1) = prejoint[5].Position.Y;
tmp(19, 1) = prejoint[9].Position.Y;
tmp(20, 1) = prejoint[6].Position.Y;
tmp(21, 1) = prejoint[10].Position.Y;
//get index2
tmp(0, 2) = prejoint[0].Position.Z;
tmp(1, 2) = prejoint[12].Position.Z;
tmp(2, 2) = prejoint[16].Position.Z;
tmp(4, 2) = prejoint[13].Position.Z;
tmp(5, 2) = prejoint[17].Position.Z;
tmp(6, 2) = prejoint[1].Position.Z;
tmp(7, 2) = prejoint[14].Position.Z;
tmp(8, 2) = prejoint[18].Position.Z;
tmp(12, 2) = prejoint[2].Position.Z;
tmp(15, 2) = prejoint[3].Position.Z;
tmp(16, 2) = prejoint[4].Position.Z;
tmp(17, 2) = prejoint[8].Position.Z;
tmp(18, 2) = prejoint[5].Position.Z;
tmp(19, 2) = prejoint[9].Position.Z;
tmp(20, 2) = prejoint[6].Position.Z;
tmp(21, 2) = prejoint[10].Position.Z;
return tmp;
}