-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawInfraredView.cpp
More file actions
executable file
·136 lines (106 loc) · 3.67 KB
/
DrawInfraredView.cpp
File metadata and controls
executable file
·136 lines (106 loc) · 3.67 KB
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
/**
* @file DrawInfraredView.cpp
* @ingroup Drawing Kinect
* @author Dominique Vaufreydaz, Grenoble Alpes University, Inria
* @copyright All right reserved.
*/
#include "DrawInfraredView.h"
#ifdef KINECT_1
// No infrared for Kinect1
#endif
#ifdef KINECT_2
#undef min
#undef max
#include <algorithm>
// #include <opencv2/contrib/contrib.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
namespace MobileRGBD { namespace Kinect2 {
/** @brief constructor. Draw data from the infrared stream of the Kinect2.
*
* @param Folder [in] Main folder containing the data. Body data will be search in 'Folder/infrared/' subfolder.
* @param SizeOfFrame [in] Size of each frame. Default value = InfraredWidth*InfraredHeight*InfraredBytesPerPixel.
*/
DrawInfraredView::DrawInfraredView( const std::string& Folder, int SizeOfFrame /* = InfraredWidth*InfraredHeight*InfraredBytesPerPixel */ )
: DrawRawData( Folder + InfraredFileName, Folder + RawInfraredFileName, SizeOfFrame )
{
ImageBuffer = new unsigned char[DepthWidth*DepthHeight*10]; // BGR data
}
/** @brief Virtual destructor, always.
*/
DrawInfraredView::~DrawInfraredView()
{
if ( ImageBuffer != nullptr )
{
delete ImageBuffer;
}
}
/** @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 DrawInfraredView::ProcessElement( const TimeB &RequestTimestamp, void * UserData )
{
cv::Mat& WhereToDraw = *((cv::Mat*)UserData);
try
{
unsigned short int * Table = (unsigned short int*)FrameBuffer;
int PosBuffer = 0;
int PosRef =0;
uchar * Img = (uchar*)ImageBuffer;
#ifdef USING_MAP
for( int i = 0; i < DepthWidth*DepthHeight; i++, PosBuffer++ )
{
float originalBrightnessValue = ((float)Table[PosBuffer])/(8192.f);
float amplication=1.0f;
float gamma = .32f;
// this is where the gamma and amplification levels get applied
float gammaAppliedValue = amplication*pow(originalBrightnessValue, gamma);
Img[PosRef++] = (uchar)(std::min(gammaAppliedValue, 1.0f)*255.0);
}
cv::Mat FloatImg( DepthHeight, DepthWidth, CV_8UC1, Img );
cv::Mat MatForConversion;
cv::applyColorMap(FloatImg, MatForConversion, cv::COLORMAP_JET);
#else
for( int i = 0; i < DepthWidth*DepthHeight; i++, PosBuffer++ )
{
ImageBuffer[PosRef++] = 0;
if ( Table[PosBuffer] == 0 )
{
ImageBuffer[PosRef++] = 0;
ImageBuffer[PosRef++] = 255;
}
else
{
float originalBrightnessValue = ((float)Table[PosBuffer])/(8192.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(gammaAppliedValue, 1.0f)*255.0);
ImageBuffer[PosRef++] = (uchar)intensity;
ImageBuffer[PosRef++] = 255;
}
}
cv::Mat MatForConversion(DepthHeight, DepthWidth, CV_8UC3, ImageBuffer );
#endif
// 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::Kinect2
#endif // KINECT_2