-
Notifications
You must be signed in to change notification settings - Fork 0
/
DimensionConvertor.h
175 lines (141 loc) · 3.2 KB
/
DimensionConvertor.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
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
170
171
172
173
174
175
#ifndef UNIVERSAL_DIMENSION_CONVERTOR_H
#define UNIVERSAL_DIMENSION_CONVERTOR_H
#include <cuda.h>
#include <cuda_runtime.h>
#include "thrust\device_ptr.h"
#include "thrust\device_vector.h"
#include "thrust\transform.h"
#include "thrust\iterator\counting_iterator.h"
#include "thrust\iterator\transform_iterator.h"
#include "thrust\iterator\zip_iterator.h"
#include "thrust\fill.h"
#include "thrust\reduce.h"
#include <opencv2\opencv.hpp>
class DimensionConvertor{
public:
struct convert_ptr{
float fx;
float fy;
int width, height;
int cx;
int cy;
__host__ convert_ptr(int width, int height, float fx, float fy, int cx, int cy){
this->fx = fx;
this->fy = fy;
this->cx = cx;
this->cy = cy;
this->width = width;
this->height = height;
}
__host__ __device__ float3 operator()(float3 in){
in.y = cy - in.y;
in.x = in.x - cx;
in.x /= fx;
in.y /= fy;
in.x *= in.z;
in.y *= in.z;
//in.x /= 1000.0f;
//in.y /= 1000.0f;
//in.z /= 1000.0f;
return in;
}
__host__ __device__ float3 operator()(thrust::tuple<float, int> in){
float3 r;
//Depth
r.z = (float)thrust::get<0>(in);
//Decompose 1D index to (x, y)
r.y = (float)(thrust::get<1>(in) / width);
r.x = (float)(thrust::get<1>(in) % width);
return operator()(r);
}
};
struct convert_ptr_int{
float fx;
float fy;
int width, height;
int cx;
int cy;
__host__ convert_ptr_int(int width, int height, float fx, float fy, int cx, int cy){
this->fx = fx;
this->fy = fy;
this->cx = cx;
this->cy = cy;
this->width = width;
this->height = height;
}
__host__ __device__ float3 operator()(float3 in){
in.y = cy - in.y/2.0f;
in.x = in.x/2.0f - cx;
in.x /= fx;
in.y /= fy;
in.x *= in.z;
in.y *= in.z;
return in;
}
__host__ __device__ float3 operator()(thrust::tuple<float, int> in){
float3 r;
//Depth
r.z = thrust::get<0>(in);
//Decompose 1D index to (x, y)
r.y = (float)(thrust::get<1>(in) / (width*2));
r.x = (float)(thrust::get<1>(in) % (width*2));
return operator()(r);
}
};
struct convert_rtp {
float fx;
float fy;
int cx;
int cy;
int width;
int height;
__host__ convert_rtp(
int width,
int height,
float fx,
float fy,
int cx,
int cy ) {
this->fx = fx;
this->fy = fy;
this->cx = cx;
this->cy = cy;
this->width = width;
this->height = height;
}
__host__ __device__ float3 operator()(float3 in){
float3 out;
//画像内に投影されないとき
if(abs(in.z) < 1.0){
out.x = -1.0;
out.y = -1.0;
}
//投影に成功したとき
else {
out.x = in.x / in.z;
out.y = in.y / in.z;
out.x *= fx;
out.y *= fy;
out.x = out.x + cx;
out.y = cy - out.y;
}
out.z = in.z;
return out;
}
};
DimensionConvertor(){};
~DimensionConvertor();
void setCameraParameters(const cv::Mat_<double> intrinsic, int width, int height);
void projectiveToReal(float* data, float3* out);
void projectiveToReal(float3* data, float3* out);
void projectiveToRealInterp(float* data, float3* out);
void realToProjective(float3* data, float3* out);
private:
float Fx;
float Fy;
int Cx;
int Cy;
int Width;
int Height;
};
#endif