-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdepthrgbobserver.cpp
127 lines (102 loc) · 3.67 KB
/
depthrgbobserver.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
#include "depthrgbobserver.h"
DepthRgbObserver::DepthRgbObserver(StreamDataReceiver *channel)
: ptrCloud(&cloud)
{
connect(channel,SIGNAL(newStreamDataAvailable()),
this,SLOT(update()));
connect(channel,SIGNAL(startGetStreamData()),
this,SLOT(refreshStartTime()));
this->channel = channel;
start = end = std::chrono::steady_clock::now();
//simpleViewer.updateViewer(ptrCloud);
}
void DepthRgbObserver::refreshStartTime()
{
start = end = std::chrono::steady_clock::now();
}
void DepthRgbObserver::update()
{
PixelMap::Ptr map = channel->getStreamData();
/*
bool check = true;
int pixelCount = 0;
int i = 0;
for (i = 0; i < map->dataLength; ++i) {
if(map->data[i]!=0x45) {
check = false;
break;
}
pixelCount++;
}
end = std::chrono::steady_clock::now();
if(!check)
std::cout << "Recostruction stream time "
<< std::chrono::duration_cast<std::chrono::microseconds>(end- start).count()
<< "us. (Missing pixel: "<<(map->pixelMapSize-pixelCount/2)
<<"(at "<<i<<")"<<std::endl;
*/
cloud.width=map->sizex;
cloud.height=map->sizey;
cloud.is_dense=false;
cloud.points.resize(map->sizex*map->sizey);
const char* data = (const char*) map->data;
float scale = cloud.width / (float) 1280;
float focalLength = 1050 * scale;
//float focalLength = depth_focal_length_SXGA_ * scale;
float constant_x = 1.0f / focalLength;
float constant_y = 1.0f / focalLength;
float centerX = ((float)cloud.width - 1.f) / 2.f;
float centerY = ((float)cloud.height - 1.f) / 2.f;
float bad_point = std::numeric_limits<float>::quiet_NaN();
int depth_idx = 0;
int char_idx = 0;
for (int v = 0; v < cloud.height; ++v)
{
for (int u = 0; u < cloud.width; ++u, ++depth_idx, char_idx+=5)
{
pcl::PointXYZRGBA& pt = cloud.points[depth_idx];
int valueMSB = data[char_idx+1] & 0xFF;
int valueLSB = data[char_idx] & 0xFF;
quint16 distance = valueLSB | (valueMSB << 8);
// Check for invalid measurements
if (distance == 0
//||
//data[depth_idx] == depth_image->getNoSampleValue () ||
//data[depth_idx] == depth_image->getShadowValue ()
)
{
// not valid
pt.x = pt.y = pt.z = bad_point;
continue;
}
pt.z = distance * 0.001f;
pt.x = (static_cast<float> (u) - centerX) * pt.z * constant_x;
pt.y = (static_cast<float> (v) - centerY) * pt.z * constant_y;
pt.r = data[char_idx+2];
pt.g = data[char_idx+3];
pt.b = data[char_idx+4];
}
}
cloud.sensor_origin_.setZero ();
cloud.sensor_orientation_.w () = 1.0f;
cloud.sensor_orientation_.x () = 0.0f;
cloud.sensor_orientation_.y () = 0.0f;
cloud.sensor_orientation_.z () = 0.0f;
end = std::chrono::steady_clock::now();
meanTimeMs = (meanTimeMs+std::chrono::duration_cast<std::chrono::microseconds>(end- start).count())/2;
std::cout<<meanTimeMs<<std::endl;
emit newStreamData(ptrCloud);
}
/*
float OpenNIDevice::getDepthFocalLength (int output_x_resolution) const throw ()
00255 {
00256 if (output_x_resolution == 0)
00257 output_x_resolution = getDepthOutputMode ().nXRes;
00258
00259 float scale = output_x_resolution / (float)XN_SXGA_X_RES;
00260 if (isDepthRegistered ())
00261 return rgb_focal_length_SXGA_ * scale;
00262 else
00263 return depth_focal_length_SXGA_ * scale;
00264 }
*/