47 template<
class DISTORTION_T>
54 const distortion_t & distortion,
57 distortion_(distortion),
73 template<
class DISTORTION_T>
75 const Eigen::VectorXd & intrinsics)
77 if (intrinsics.cols() != NumIntrinsics) {
80 intrinsics_ = intrinsics;
85 distortion_.setParameters(
86 intrinsics.tail<distortion_t::NumDistortionIntrinsics>());
87 one_over_fu_ = 1.0 / fu_;
88 one_over_fv_ = 1.0 / fv_;
89 fu_over_fv_ = fu_ / fv_;
93 template<
class DISTORTION_T>
96 intrinsics = intrinsics_;
97 Eigen::VectorXd distortionIntrinsics;
98 if(distortion_t::NumDistortionIntrinsics > 0) {
99 distortion_.getParameters(distortionIntrinsics);
100 intrinsics.tail<distortion_t::NumDistortionIntrinsics>() = distortionIntrinsics;
108 template<
class DISTORTION_T>
110 const Eigen::Vector3d & point, Eigen::Vector2d * imagePoint)
const
113 if (fabs(point[2]) < 1.0e-12) {
118 Eigen::Vector2d imagePointUndistorted;
119 const double rz = 1.0 / point[2];
120 imagePointUndistorted[0] = point[0] * rz;
121 imagePointUndistorted[1] = point[1] * rz;
124 Eigen::Vector2d imagePoint2;
125 if (!distortion_.distort(imagePointUndistorted, &imagePoint2)) {
130 (*imagePoint)[0] = fu_ * imagePoint2[0] + cu_;
131 (*imagePoint)[1] = fv_ * imagePoint2[1] + cv_;
147 template<
class DISTORTION_T>
149 const Eigen::Vector3d & point, Eigen::Vector2d * imagePoint,
150 Eigen::Matrix<double, 2, 3> * pointJacobian,
151 Eigen::Matrix2Xd * intrinsicsJacobian)
const
154 if (fabs(point[2]) < 1.0e-12) {
159 Eigen::Vector2d imagePointUndistorted;
160 const double rz = 1.0 / point[2];
161 double rz2 = rz * rz;
162 imagePointUndistorted[0] = point[0] * rz;
163 imagePointUndistorted[1] = point[1] * rz;
165 Eigen::Matrix<double, 2, 3> pointJacobianProjection;
166 Eigen::Matrix2Xd intrinsicsJacobianProjection;
167 Eigen::Matrix2d distortionJacobian;
168 Eigen::Matrix2Xd intrinsicsJacobianDistortion;
169 Eigen::Vector2d imagePoint2;
171 bool distortionSuccess;
172 if (intrinsicsJacobian) {
174 intrinsicsJacobian->resize(2, NumIntrinsics);
176 distortionSuccess = distortion_.distort(imagePointUndistorted, &imagePoint2,
178 &intrinsicsJacobianDistortion);
180 intrinsicsJacobian->template topLeftCorner<2, 2>() =
181 imagePoint2.asDiagonal();
182 intrinsicsJacobian->template block<2, 2>(0,2) = Eigen::Matrix2d::Identity();
184 if (distortion_t::NumDistortionIntrinsics > 0) {
186 ->template bottomRightCorner<2, distortion_t::NumDistortionIntrinsics>() =
187 Eigen::Vector2d(fu_, fv_).asDiagonal() * intrinsicsJacobianDistortion;
191 distortionSuccess = distortion_.distort(imagePointUndistorted, &imagePoint2,
192 &distortionJacobian);
196 Eigen::Matrix<double, 2, 3> & J = *pointJacobian;
197 J(0, 0) = fu_ * distortionJacobian(0, 0) * rz;
198 J(0, 1) = fu_ * distortionJacobian(0, 1) * rz;
200 * (point[0] * distortionJacobian(0, 0)
201 + point[1] * distortionJacobian(0, 1)) * rz2;
202 J(1, 0) = fv_ * distortionJacobian(1, 0) * rz;
203 J(1, 1) = fv_ * distortionJacobian(1, 1) * rz;
205 * (point[0] * distortionJacobian(1, 0)
206 + point[1] * distortionJacobian(1, 1)) * rz2;
209 (*imagePoint)[0] = fu_ * imagePoint2[0] + cu_;
210 (*imagePoint)[1] = fv_ * imagePoint2[1] + cv_;
212 if (!distortionSuccess) {
229 template<
class DISTORTION_T>
231 const Eigen::Vector3d & point,
const Eigen::VectorXd & parameters,
232 Eigen::Vector2d * imagePoint, Eigen::Matrix<double, 2, 3> * pointJacobian,
233 Eigen::Matrix2Xd * intrinsicsJacobian)
const
236 if (fabs(point[2]) < 1.0e-12) {
241 const double fu = parameters[0];
242 const double fv = parameters[1];
243 const double cu = parameters[2];
244 const double cv = parameters[3];
246 Eigen::VectorXd distortionParameters;
247 if (distortion_t::NumDistortionIntrinsics > 0) {
248 distortionParameters = parameters
249 .template tail<distortion_t::NumDistortionIntrinsics>();
253 Eigen::Vector2d imagePointUndistorted;
254 const double rz = 1.0 / point[2];
255 double rz2 = rz * rz;
256 imagePointUndistorted[0] = point[0] * rz;
257 imagePointUndistorted[1] = point[1] * rz;
259 Eigen::Matrix<double, 2, 3> pointJacobianProjection;
260 Eigen::Matrix2Xd intrinsicsJacobianProjection;
261 Eigen::Matrix2d distortionJacobian;
262 Eigen::Matrix2Xd intrinsicsJacobianDistortion;
263 Eigen::Vector2d imagePoint2;
265 bool distortionSuccess;
266 if (intrinsicsJacobian) {
268 intrinsicsJacobian->resize(2, NumIntrinsics);
270 distortionSuccess = distortion_.distortWithExternalParameters(imagePointUndistorted,
271 distortionParameters, &imagePoint2,
273 &intrinsicsJacobianDistortion);
275 intrinsicsJacobian->template topLeftCorner<2, 2>() =
276 imagePoint2.asDiagonal();
277 intrinsicsJacobian->template block<2, 2>(0,2) = Eigen::Matrix2d::Identity();
279 if (distortion_t::NumDistortionIntrinsics > 0) {
281 ->template bottomRightCorner<2, distortion_t::NumDistortionIntrinsics>() =
282 Eigen::Vector2d(fu, fv).asDiagonal() * intrinsicsJacobianDistortion;
286 distortionSuccess = distortion_.distortWithExternalParameters(imagePointUndistorted,
287 distortionParameters, &imagePoint2,
288 &distortionJacobian);
293 Eigen::Matrix<double, 2, 3> & J = *pointJacobian;
294 J(0, 0) = fu * distortionJacobian(0, 0) * rz;
295 J(0, 1) = fu * distortionJacobian(0, 1) * rz;
297 * (point[0] * distortionJacobian(0, 0)
298 + point[1] * distortionJacobian(0, 1)) * rz2;
299 J(1, 0) = fv * distortionJacobian(1, 0) * rz;
300 J(1, 1) = fv * distortionJacobian(1, 1) * rz;
302 * (point[0] * distortionJacobian(1, 0)
303 + point[1] * distortionJacobian(1, 1)) * rz2;
307 (*imagePoint)[0] = fu * imagePoint2[0] + cu;
308 (*imagePoint)[1] = fv * imagePoint2[1] + cv;
310 if (!distortionSuccess) {
327 template<
class DISTORTION_T>
329 const Eigen::Matrix3Xd & points, Eigen::Matrix2Xd * imagePoints,
330 std::vector<CameraBase::ProjectionStatus> * stati)
const
332 const int numPoints = points.cols();
333 for (
int i = 0; i < numPoints; ++i) {
334 Eigen::Vector3d point = points.col(i);
335 Eigen::Vector2d imagePoint;
337 imagePoints->col(i) = imagePoint;
339 stati->push_back(status);
344 template<
class DISTORTION_T>
346 const Eigen::Vector4d & point, Eigen::Vector2d * imagePoint)
const
348 Eigen::Vector3d head = point.head<3>();
350 return project(-head, imagePoint);
352 return project(head, imagePoint);
357 template<
class DISTORTION_T>
359 const Eigen::Vector4d & point, Eigen::Vector2d * imagePoint,
360 Eigen::Matrix<double, 2, 4> * pointJacobian,
361 Eigen::Matrix2Xd * intrinsicsJacobian)
const
363 Eigen::Vector3d head = point.head<3>();
364 Eigen::Matrix<double, 2, 3> pointJacobian3;
367 status = project(-head, imagePoint,
371 status = project(head, imagePoint,
375 pointJacobian->template bottomRightCorner<2, 1>() = Eigen::Vector2d::Zero();
376 pointJacobian->template topLeftCorner<2, 3>() = pointJacobian3;
381 template<
class DISTORTION_T>
383 const Eigen::Vector4d & point,
const Eigen::VectorXd & parameters,
384 Eigen::Vector2d * imagePoint, Eigen::Matrix<double, 2, 4> * pointJacobian,
385 Eigen::Matrix2Xd * intrinsicsJacobian)
const
387 Eigen::Vector3d head = point.head<3>();
388 Eigen::Matrix<double, 2, 3> pointJacobian3;
391 status = projectWithExternalParameters(-head, parameters, imagePoint,
395 status = projectWithExternalParameters(head, parameters, imagePoint,
399 pointJacobian->template bottomRightCorner<2, 1>() = Eigen::Vector2d::Zero();
400 pointJacobian->template topLeftCorner<2, 3>() = pointJacobian3;
405 template<
class DISTORTION_T>
407 const Eigen::Matrix4Xd & points, Eigen::Matrix2Xd * imagePoints,
408 std::vector<ProjectionStatus> * stati)
const
410 const int numPoints = points.cols();
411 for (
int i = 0; i < numPoints; ++i) {
412 Eigen::Vector4d point = points.col(i);
413 Eigen::Vector2d imagePoint;
415 imagePoints->col(i) = imagePoint;
417 stati->push_back(status);
425 template<
class DISTORTION_T>
427 const Eigen::Vector2d & imagePoint, Eigen::Vector3d * direction)
const
430 Eigen::Vector2d imagePoint2;
431 imagePoint2[0] = (imagePoint[0] - cu_) * one_over_fu_;
432 imagePoint2[1] = (imagePoint[1] - cv_) * one_over_fv_;
435 Eigen::Vector2d undistortedImagePoint;
436 bool success = distortion_.undistort(imagePoint2, &undistortedImagePoint);
439 (*direction)[0] = undistortedImagePoint[0];
440 (*direction)[1] = undistortedImagePoint[1];
441 (*direction)[2] = 1.0;
447 template<
class DISTORTION_T>
449 const Eigen::Vector2d & imagePoint, Eigen::Vector3d * direction,
450 Eigen::Matrix<double, 3, 2> * pointJacobian)
const
453 Eigen::Vector2d imagePoint2;
454 imagePoint2[0] = (imagePoint[0] - cu_) * one_over_fu_;
455 imagePoint2[1] = (imagePoint[1] - cv_) * one_over_fv_;
458 Eigen::Vector2d undistortedImagePoint;
459 Eigen::Matrix2d pointJacobianUndistortion;
460 bool success = distortion_.undistort(imagePoint2, &undistortedImagePoint,
461 &pointJacobianUndistortion);
464 (*direction)[0] = undistortedImagePoint[0];
465 (*direction)[1] = undistortedImagePoint[1];
466 (*direction)[2] = 1.0;
469 Eigen::Matrix<double, 3, 2> outProjectJacobian =
470 Eigen::Matrix<double, 3, 2>::Zero();
471 outProjectJacobian(0, 0) = one_over_fu_;
472 outProjectJacobian(1, 1) = one_over_fv_;
474 (*pointJacobian) = outProjectJacobian * pointJacobianUndistortion;
480 template<
class DISTORTION_T>
482 const Eigen::Matrix2Xd & imagePoints, Eigen::Matrix3Xd * directions,
483 std::vector<bool> * success)
const
485 const int numPoints = imagePoints.cols();
486 directions->row(3) = Eigen::VectorXd::Ones(numPoints);
487 for (
int i = 0; i < numPoints; ++i) {
488 Eigen::Vector2d imagePoint = imagePoints.col(i);
489 Eigen::Vector3d point;
490 bool suc = backProject(imagePoint, &point);
492 success->push_back(suc);
493 directions->col(i) = point;
499 template<
class DISTORTION_T>
501 const Eigen::Vector2d & imagePoint, Eigen::Vector4d * direction)
const
504 bool success = backProject(imagePoint, &ray);
505 direction->template head<3>() = ray;
506 (*direction)[4] = 1.0;
511 template<
class DISTORTION_T>
513 const Eigen::Vector2d & imagePoint, Eigen::Vector4d * direction,
514 Eigen::Matrix<double, 4, 2> * pointJacobian)
const
517 Eigen::Matrix<double, 3, 2> pointJacobian3;
518 bool success = backProject(imagePoint, &ray, &pointJacobian3);
519 direction->template head<3>() = ray;
520 (*direction)[4] = 1.0;
521 pointJacobian->template bottomRightCorner<1,2>() = Eigen::Vector2d::Zero();
522 pointJacobian->template topLeftCorner<3, 2>() = pointJacobian3;
527 template<
class DISTORTION_T>
529 const Eigen::Matrix2Xd & imagePoints, Eigen::Matrix4Xd * directions,
530 std::vector<bool> * success)
const
532 const int numPoints = imagePoints.cols();
533 directions->row(3) = Eigen::VectorXd::Ones(numPoints);
534 for (
int i = 0; i < numPoints; ++i) {
535 Eigen::Vector2d imagePoint = imagePoints.col(i);
536 Eigen::Vector3d point;
537 bool suc = backProject(imagePoint, &point);
539 success->push_back(suc);
540 directions->template block<3, 1>(0, i) = point;
ProjectionStatus
Definition: CameraBase.hpp:67
PinholeCamera()=delete
No default constructor.
bool backProjectHomogeneousBatch(const Eigen::Matrix2Xd &imagePoints, Eigen::Matrix4Xd *directions, std::vector< bool > *success) const
Back-project 2d image points into homogeneous points (direction vectors).
Definition: PinholeCamera.hpp:528
double fu_
focalLengthU
Definition: PinholeCamera.hpp:319
double one_over_fu_
1.0 / fu_
Definition: PinholeCamera.hpp:323
double fv_
focalLengthV
Definition: PinholeCamera.hpp:320
double fu_over_fv_
fu_ / fv_
Definition: PinholeCamera.hpp:325
bool isInImage(const Eigen::Vector2d &imagePoint) const
Check if the keypoint is in the image.
Definition: CameraBase.hpp:95
CameraBase::ProjectionStatus project(const Eigen::Vector3d &point, Eigen::Vector2d *imagePoint) const
Projects a Euclidean point to a 2d image point (projection). Uses projection including distortion mod...
Definition: PinholeCamera.hpp:109
Eigen::Matrix< double, NumIntrinsics, 1 > intrinsics_
summary of all intrinsics parameters
Definition: PinholeCamera.hpp:318
bool backProjectHomogeneous(const Eigen::Vector2d &imagePoint, Eigen::Vector4d *direction) const
Back-project a 2d image point into homogeneous point (direction vector).
Definition: PinholeCamera.hpp:500
CameraBase::ProjectionStatus projectWithExternalParameters(const Eigen::Vector3d &point, const Eigen::VectorXd ¶meters, Eigen::Vector2d *imagePoint, Eigen::Matrix< double, 2, 3 > *pointJacobian, Eigen::Matrix2Xd *intrinsicsJacobian=NULL) const
Projects a Euclidean point to a 2d image point (projection). Uses projection including distortion mod...
Definition: PinholeCamera.hpp:230
bool backProjectBatch(const Eigen::Matrix2Xd &imagePoints, Eigen::Matrix3Xd *directions, std::vector< bool > *success) const
Back-project 2d image points into Euclidean space (direction vectors).
Definition: PinholeCamera.hpp:481
CameraBase::ProjectionStatus projectHomogeneousWithExternalParameters(const Eigen::Vector4d &point, const Eigen::VectorXd ¶meters, Eigen::Vector2d *imagePoint, Eigen::Matrix< double, 2, 4 > *pointJacobian=NULL, Eigen::Matrix2Xd *intrinsicsJacobian=NULL) const
Projects a point in homogenous coordinates to a 2d image point (projection). Uses projection includin...
Definition: PinholeCamera.hpp:382
bool backProject(const Eigen::Vector2d &imagePoint, Eigen::Vector3d *direction) const
Back-project a 2d image point into Euclidean space (direction vector).
Definition: PinholeCamera.hpp:426
double cu_
imageCenterU
Definition: PinholeCamera.hpp:321
void projectBatch(const Eigen::Matrix3Xd &points, Eigen::Matrix2Xd *imagePoints, std::vector< CameraBase::ProjectionStatus > *stati) const
Projects Euclidean points to 2d image points (projection) in a batch. Uses projection including disto...
Definition: PinholeCamera.hpp:328
bool setIntrinsics(const Eigen::VectorXd &intrinsics)
overwrite all intrinsics - use with caution !
Definition: PinholeCamera.hpp:74
CameraBase::ProjectionStatus projectHomogeneous(const Eigen::Vector4d &point, Eigen::Vector2d *imagePoint) const
Projects a point in homogenous coordinates to a 2d image point (projection). Uses projection includin...
Definition: PinholeCamera.hpp:345
bool isMasked(const Eigen::Vector2d &imagePoint) const
Check if the keypoint is masked.
Definition: CameraBase.hpp:83
void projectHomogeneousBatch(const Eigen::Matrix4Xd &points, Eigen::Matrix2Xd *imagePoints, std::vector< CameraBase::ProjectionStatus > *stati) const
Projects points in homogenous coordinates to 2d image points (projection) in a batch. Uses projection including distortion models.
Definition: PinholeCamera.hpp:406
double one_over_fv_
1.0 / fv_
Definition: PinholeCamera.hpp:324
Base class for all camera models.
Definition: CameraBase.hpp:60
void getIntrinsics(Eigen::VectorXd &intrinsics) const
Get the intrinsics as a concatenated vector.
Definition: PinholeCamera.hpp:94
double cv_
imageCenterV
Definition: PinholeCamera.hpp:322