-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrgbobserver.cpp
94 lines (74 loc) · 2.58 KB
/
rgbobserver.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
#include "rgbobserver.h"
RgbObserver::RgbObserver(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 RgbObserver::refreshStartTime()
{
start = end = std::chrono::steady_clock::now();
}
void RgbObserver::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;
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+=3)
{
pcl::PointXYZRGBA& pt = cloud.points[depth_idx];
pt.z = 0.001f;
pt.x = (static_cast<float> (u) - centerX) * constant_x;
pt.y = (static_cast<float> (v) - centerY) * constant_y;
pt.r = data[char_idx];
pt.g = data[char_idx+1];
pt.b = data[char_idx+2];
}
}
cloud.sensor_origin_.setZero ();
cloud.sensor_orientation_.w () = 0.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);
}