20CameraInfo::CameraInfo (
void)
24 std::fill(this->ppoint, this->ppoint + 2, 0.5f);
25 std::fill(this->dist, this->dist + 2, 0.0f);
27 std::fill(this->trans, this->trans + 3, 0.0f);
34CameraInfo::fill_camera_pos (
float* pos)
const
36 pos[0] = -rot[0] * trans[0] - rot[3] * trans[1] - rot[6] * trans[2];
37 pos[1] = -rot[1] * trans[0] - rot[4] * trans[1] - rot[7] * trans[2];
38 pos[2] = -rot[2] * trans[0] - rot[5] * trans[1] - rot[8] * trans[2];
44CameraInfo::fill_camera_translation (
float* trans)
const
46 std::copy(this->trans, this->trans + 3, trans);
52CameraInfo::fill_viewing_direction (
float* viewdir)
const
54 for (
int i = 0; i < 3; ++i)
55 viewdir[i] = this->rot[6 + i];
61CameraInfo::fill_world_to_cam (
float* mat)
const
63 mat[0] = rot[0]; mat[1] = rot[1]; mat[2] = rot[2]; mat[3] = trans[0];
64 mat[4] = rot[3]; mat[5] = rot[4]; mat[6] = rot[5]; mat[7] = trans[1];
65 mat[8] = rot[6]; mat[9] = rot[7]; mat[10] = rot[8]; mat[11] = trans[2];
66 mat[12] = 0.0f; mat[13] = 0.0f; mat[14] = 0.0f; mat[15] = 1.0f;
72CameraInfo::fill_gl_viewtrans (
float* mat)
const
74 mat[0] = rot[0]; mat[1] = rot[1]; mat[2] = rot[2]; mat[3] = trans[0];
75 mat[4] = -rot[3]; mat[5] = -rot[4]; mat[6] = -rot[5]; mat[7] = -trans[1];
76 mat[8] = -rot[6]; mat[9] = -rot[7]; mat[10] = -rot[8]; mat[11] = -trans[2];
77 mat[12] = 0.0f; mat[13] = 0.0f; mat[14] = 0.0f; mat[15] = 1.0f;
83CameraInfo::fill_cam_to_world (
float* mat)
const
85 mat[0] = rot[0]; mat[1] = rot[3]; mat[2] = rot[6];
86 mat[4] = rot[1]; mat[5] = rot[4]; mat[6] = rot[7];
87 mat[8] = rot[2]; mat[9] = rot[5]; mat[10] = rot[8];
88 mat[3] = -(rot[0] * trans[0] + rot[3] * trans[1] + rot[6] * trans[2]);
89 mat[7] = -(rot[1] * trans[0] + rot[4] * trans[1] + rot[7] * trans[2]);
90 mat[11] = -(rot[2] * trans[0] + rot[5] * trans[1] + rot[8] * trans[2]);
91 mat[12] = 0.0f; mat[13] = 0.0f; mat[14] = 0.0f; mat[15] = 1.0f;
97CameraInfo::fill_world_to_cam_rot (
float* mat)
const
99 std::copy(this->rot, this->rot + 9, mat);
105CameraInfo::fill_cam_to_world_rot (
float* mat)
const
107 mat[0] = rot[0]; mat[1] = rot[3]; mat[2] = rot[6];
108 mat[3] = rot[1]; mat[4] = rot[4]; mat[5] = rot[7];
109 mat[6] = rot[2]; mat[7] = rot[5]; mat[8] = rot[8];
115CameraInfo::set_transformation (
float const* mat)
117 rot[0] = mat[0]; rot[1] = mat[1]; rot[2] = mat[2]; trans[0] = mat[3];
118 rot[3] = mat[4]; rot[4] = mat[5]; rot[5] = mat[6]; trans[1] = mat[7];
119 rot[6] = mat[8]; rot[7] = mat[9]; rot[8] = mat[10]; trans[2] = mat[11];
125CameraInfo::fill_calibration (
float* mat,
float width,
float height)
const
127 float dim_aspect = width / height;
128 float image_aspect = dim_aspect * this->paspect;
130 if (image_aspect < 1.0f)
132 ax = this->flen * height / this->paspect;
133 ay = this->flen * height;
137 ax = this->flen * width;
138 ay = this->flen * width * this->paspect;
141 mat[0] = ax; mat[1] = 0.0f; mat[2] = width * this->ppoint[0];
142 mat[3] = 0.0f; mat[4] = ay; mat[5] = height * this->ppoint[1];
143 mat[6] = 0.0f; mat[7] = 0.0f; mat[8] = 1.0f;
149CameraInfo::fill_gl_projection (
float* mat,
float width,
float height,
150 float znear,
float zfar)
const
152 float dim_aspect = width / height;
153 float image_aspect = dim_aspect * this->paspect;
155 if (image_aspect < 1.0f)
157 ax = this->flen / image_aspect;
163 ay = this->flen * image_aspect;
166 std::fill(mat, mat + 16, 0.0f);
168 mat[4 * 0 + 0] = 2.0f * ax;
169 mat[4 * 0 + 2] = 2.0f * (this->ppoint[0] - 0.5f);
170 mat[4 * 1 + 1] = 2.0f * ay;
171 mat[4 * 1 + 2] = 2.0f * (this->ppoint[1] - 0.5f);
172 mat[4 * 2 + 2] = -(zfar + znear) / (zfar - znear);
173 mat[4 * 2 + 3] = -2.0f * zfar * znear / (zfar - znear);
174 mat[4 * 3 + 2] = -1.0f;
180CameraInfo::fill_inverse_calibration (
float* mat,
181 float width,
float height)
const
183 float dim_aspect = width / height;
184 float image_aspect = dim_aspect * this->paspect;
186 if (image_aspect < 1.0f)
188 ax = this->flen * height / this->paspect;
189 ay = this->flen * height;
193 ax = this->flen * width;
194 ay = this->flen * width * this->paspect;
197 mat[0] = 1.0f / ax; mat[1] = 0.0f; mat[2] = -width * this->ppoint[0] / ax;
198 mat[3] = 0.0f; mat[4] = 1.0f / ay; mat[5] = -height * this->ppoint[1] / ay;
199 mat[6] = 0.0f; mat[7] = 0.0f; mat[8] = 1.0f;
206 float src_width,
float src_height,
float dst_width,
float dst_height,
207 float* mat,
float* vec)
const
214 this->fill_cam_to_world_rot(src_Ri.
begin());
215 this->fill_inverse_calibration(src_Ki.
begin(), src_width, src_height);
216 this->fill_camera_translation(src_t.
begin());
219 math::Vec3f ret_vec = dst_K * (dst_t - dst_R * src_Ri * src_t);
220 std::copy(ret_mat.
begin(), ret_mat.
end(), mat);
221 std::copy(ret_vec.
begin(), ret_vec.
end(), vec);
227CameraInfo::get_rotation_string (
void)
const
229 std::stringstream ss;
230 ss << std::setprecision(10);
231 for (
int i = 0; i < 9; ++i)
232 ss << this->rot[i] << (i < 8 ?
" " :
"");
237CameraInfo::get_translation_string (
void)
const
239 std::stringstream ss;
240 ss << std::setprecision(10);
241 for (
int i = 0; i < 3; ++i)
242 ss << this->trans[i] << (i < 2 ?
" " :
"");
247CameraInfo::set_translation_from_string (std::string
const& trans_string)
249 std::stringstream ss(trans_string);
250 for (
int i = 0; i < 3; ++i)
251 ss >> this->trans[i];
255CameraInfo::set_rotation_from_string (std::string
const& rot_string)
257 std::stringstream ss(rot_string);
258 for (
int i = 0; i < 9; ++i)
265CameraInfo::debug_print (
void)
const
267 std::cout <<
"Extrinsic camera parameters:" << std::endl
268 <<
" Trans: " <<
math::Vec3f(this->trans) << std::endl
269 <<
" Rot: " <<
math::Vec3f(&this->rot[0]) << std::endl
272 <<
"Intrinsic camera parameters:" << std::endl
273 <<
" Focal Length: " << this->flen << std::endl
274 <<
" Principal Point: " <<
math::Vec2f(this->ppoint) << std::endl
275 <<
" Pixel aspect: " << this->paspect << std::endl
276 <<
" Radial distortion: " <<
math::Vec2f(this->dist) << std::endl
Matrix class for arbitrary dimensions and types.
Vector class for arbitrary dimensions and types.
#define MVE_NAMESPACE_BEGIN
#define MVE_NAMESPACE_END
Matrix< T, N, N > & matrix_set_identity(Matrix< T, N, N > *mat)
Sets the given square matrix to the identity matrix.
Per-view camera information with various helper functions.
void fill_camera_translation(float *trans) const
Stores the camera translation 3-vector into array pointed to by pos.
void fill_calibration(float *mat, float width, float height) const
Stores the 3x3 calibration (or projection) matrix (K-matrix in Hartley, Zisserman).
void fill_world_to_cam_rot(float *mat) const
Stores the world to camera 3x3 rotation matrix in mat.