-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawDepthView.cpp
executable file
·169 lines (128 loc) · 4.37 KB
/
DrawDepthView.cpp
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/**
* @file DrawDepthView.cpp
* @ingroup Drawing Kinect
* @author Dominique Vaufreydaz, Grenoble Alpes University, Inria
* @copyright All right reserved.
*/
#include "DrawDepthView.h"
#undef min
#include <algorithm>
#ifdef KINECT_1
namespace MobileRGBD { namespace Kinect1 {
/** @brief ProcessElement is a callback function called by mother classes when data are ready.
*
* @param RequestTimestamp [in] The timestamp of the data.
* @param UserData [in] User pointer to working data. Here a pointer to a cv:Mat to draw in.
*/
bool DrawDepthView::ProcessElement( const TimeB &RequestTimestamp, void * UserData /* = nullptr */ )
{
cv::Mat& WhereToDraw = *((cv::Mat*)UserData);
try
{
ushort * ImageBuffer2 = (ushort*)FrameBuffer;
// Remove player detection information (cause noisy depth)
const int LineSize = 640;
for( int line = 0; line < 480; line++ )
{
for( int col = 0; col < 640; col++ )
{
Users[line][col] = (uchar)(ImageBuffer2[line*LineSize+col] & 0x07);
ImageBuffer2[line*LineSize+col] = ImageBuffer2[line*LineSize+col] >> 3;
}
}
cv::Mat MatInit( 480, 640, CV_16UC1, FrameBuffer );
cv::Mat MatScaled( 480, 640, CV_8UC1 );
cv::Mat MatForConversion( 480, 640, CV_8UC3 );
MatInit.convertTo( MatScaled, 1.0/16.0, 0.0 );
// Concert color space
cvtColor( MatScaled, MatForConversion, CV_GRAY2BGR, 0 );
// Resize it to finel size
if ( MatForConversion.rows != WhereToDraw.rows || MatForConversion.cols != WhereToDraw.cols )
{
cv::Mat MatForFinal( WhereToDraw.rows, WhereToDraw.cols, CV_8UC3 );
cv::resize( MatForConversion, MatForFinal, cv::Size(WhereToDraw.cols,WhereToDraw.rows), 0, 0 );
MatForFinal.copyTo( WhereToDraw );
}
else
{
MatForConversion.copyTo( WhereToDraw );
}
} catch ( cv::Exception )
{
}
return true;
}
}} // namespace MobileRGBD::Kinect1
#endif // KINECT_1
#ifdef KINECT_2
#include <System/TypedMemoryBuffer.h>
namespace MobileRGBD { namespace Kinect2 {
void DrawDepthView::Draw( cv::Mat& WhereToDraw, void * FrameBuffer, void * DrawingBuffer /* = nullptr */ )
{
try
{
Omiscid::TypedMemoryBuffer<unsigned char> TempBuff;
unsigned char * ImageBuffer;
if ( DrawingBuffer == nullptr )
{
TempBuff.SetNewNumberOfElementsInBuffer(DepthWidth*DepthHeight*3); // RGB
ImageBuffer = TempBuff;
}
else
{
ImageBuffer = (unsigned char *)DrawingBuffer;
}
unsigned short int * Table = (unsigned short int*)FrameBuffer;
int PosBuffer = 0;
int PosRef = 0;
for( int i = 0; i < DepthWidth*DepthHeight; i++, PosBuffer++ )
{
if ( Table[PosBuffer] == 0 )
{
ImageBuffer[PosRef++] = 0;
ImageBuffer[PosRef++] = 0;
ImageBuffer[PosRef++] = 0;
}
else
{
float originalBrightnessValue = ((float)Table[PosBuffer])/(65536.f);
float amplication=1.0f;
float gamma = .32f;
// this is where the gamma and amplification levels get applied
float gammaAppliedValue = amplication*pow(originalBrightnessValue, gamma);
// here we convert it to the desired 0 - 255 range for a byte
uchar intensity = (uchar)(std::min((float)gammaAppliedValue, 1.0f)*255.0f);
ImageBuffer[PosRef++] = intensity;
ImageBuffer[PosRef++] = intensity;
ImageBuffer[PosRef++] = intensity;
}
}
cv::Mat MatForConversion(DepthHeight, DepthWidth, CV_8UC3, ImageBuffer );
// Resize it to finel size
if ( MatForConversion.rows != WhereToDraw.rows || MatForConversion.cols != WhereToDraw.cols )
{
cv::Mat MatForFinal( WhereToDraw.rows, WhereToDraw.cols, CV_8UC3 );
cv::resize( MatForConversion, MatForFinal, cv::Size(WhereToDraw.cols,WhereToDraw.rows), 0, 0 );
MatForFinal.copyTo( WhereToDraw );
}
else
{
MatForConversion.copyTo( WhereToDraw );
}
} catch ( cv::Exception )
{
}
}
/** @brief ProcessElement is a callback function called by mother classes when data are ready.
*
* @param RequestTimestamp [in] The timestamp of the data.
* @param UserData [in] User pointer to working data. Here a pointer to a cv:Mat to draw in.
*/
bool DrawDepthView::ProcessElement( const TimeB &RequestTimestamp, void * UserData /* = nullptr */ )
{
cv::Mat& WhereToDraw = *((cv::Mat*)UserData);
Draw(WhereToDraw, FrameBuffer, ImageBuffer);
return true;
}
}} // namespace MobileRGBD::Kinect2
#endif // KINECT_2