Go to the documentation of this file.00001
00020 #ifndef NTK_GEOMETRY_POSE3D_H
00021 #define NTK_GEOMETRY_POSE3D_H
00022
00023 # include <ntk/core.h>
00024
00025 namespace ntk
00026 {
00027
00033 class Pose3D
00034 {
00035 private:
00036 class PrivatePose3D;
00037 friend class PrivatePose3D;
00038 PrivatePose3D* impl;
00039
00040 public:
00041 Pose3D();
00042 ~Pose3D();
00043
00044 Pose3D(const Pose3D& rhs);
00045 Pose3D& operator=(const Pose3D& rhs);
00046
00047 public:
00048 virtual void saveToYaml(cv::FileStorage& yaml) const;
00049 virtual void loadFromYaml(cv::FileNode yaml);
00050
00052 void setCameraParametersFromOpencv(const cv::Mat1d& cv_matrix);
00053
00055 void setCameraParameters(double fx, double fy, double cx, double cy, bool orthographic = false);
00056
00057 public:
00065 void toLeftCamera(const cv::Mat1d& intrinsics_matrix,
00066 const cv::Mat1d& R,
00067 const cv::Mat1d& T);
00068
00073 void toRightCamera(const cv::Mat1d& cv_matrix,
00074 const cv::Mat1d& R,
00075 const cv::Mat1d& T);
00076
00078 Pose3D computeDeltaPoseWith(const Pose3D& new_pose) const;
00079
00080 public:
00082 double focalX() const { return m_focal_x; }
00083 double focalY() const { return m_focal_y; }
00084
00086 double imageCenterX() const { return m_image_center_x; }
00087 double imageCenterY() const { return m_image_center_y; }
00088
00090 bool focalAreIdentical() const { return std::abs(m_focal_x - m_focal_y) <= 1e-5; }
00091
00093 double meanFocal() const { return (m_focal_x + m_focal_y)/2.0; }
00094
00096 bool isValid() const { return m_has_camera_params; }
00097
00099 void setOrthographic(bool ortho);
00100 bool isOrthographic() const { return m_orthographic; }
00101
00102 public:
00104 const cv::Vec3f cvTranslation() const;
00105
00110 const cv::Vec3f cvEulerRotation() const;
00111
00113 const cv::Vec3f cvRodriguesRotation() const;
00114
00116 const cv::Mat1f cvCameraTransform() const;
00117
00119 cv::Mat1f cvInvCameraTransform() const;
00120
00122 cv::Mat1f cvProjectionMatrix() const;
00123
00125 cv::Mat1f cvInvProjectionMatrix() const;
00126
00127 public:
00129 void resetCameraTransform();
00130
00132 void invert();
00133
00138 void setCameraTransform(const cv::Mat1d& tvec, const cv::Mat1d& rvec);
00139
00141 void setCameraTransform(const cv::Mat1f& H);
00142
00144 void setCameraTransformFromCvFundamentalMatrix(const cv::Mat1f& F);
00145
00147 void applyTransformBefore(const Pose3D& rhs_pose);
00148 void applyTransformBefore(const cv::Vec3f& cvTranslation, const cv::Vec3f& rotation_euler_angles);
00149 void applyTransformBefore(const cv::Vec3f& cvTranslation, const cv::Mat1d& rotation_matrix);
00150 void applyTransformBeforeRodrigues(const cv::Vec3f& cvTranslation, const cv::Vec3f& rotation_rodrigues);
00151
00153 void applyTransformAfter(const Pose3D& rhs_pose);
00154 void applyTransformAfter(const cv::Vec3f& translation, const cv::Vec3f& rotation_euler_angles);
00155 void applyTransformAfter(const cv::Vec3f& translation, const cv::Mat1d& rotation_matrix);
00156 void applyTransformAfterRodrigues(const cv::Vec3f& translation, const cv::Vec3f& rotation_rodrigues);
00157
00158 public:
00160 cv::Point3f cameraTransform(const cv::Point3f& p) const;
00161
00163 cv::Point3f invCameraTransform(const cv::Point3f& p) const;
00164
00166 cv::Point3f projectToImage(const cv::Point3f& p) const;
00167
00169 void projectToImage(const cv::Mat3f& voxels, const cv::Mat1b& mask, cv::Mat3f& pixels) const;
00170
00172 cv::Point3f unprojectFromImage(const cv::Point2f& p, double depth) const;
00173 cv::Point3f unprojectFromImage(const cv::Point3f& p) const
00174 { return unprojectFromImage(cv::Point2f(p.x,p.y), p.z); }
00175
00177 void unprojectFromImage(const cv::Mat1f& pixels, const cv::Mat1b& mask, cv::Mat3f& voxels) const;
00178
00179 private:
00180 double m_focal_x;
00181 double m_focal_y;
00182 double m_image_center_x;
00183 double m_image_center_y;
00184 bool m_has_camera_params;
00185 bool m_orthographic;
00186 };
00187
00189 cv::Vec3f estimate_normal_from_depth(const cv::Mat1f& depth_yml, const Pose3D& pose, int r, int c);
00190
00192 cv::Vec3f camera_eye_vector(const Pose3D& pose, int r, int c);
00193
00198 cv::Vec3f compute_axis_angle_rotation(const cv::Vec3f& src, const cv::Vec3f& dst);
00199
00200 }
00201
00202 #endif // NTK_GEOMETRY_POSE3D_H