18 #ifndef PIC_COMPUTER_VISION_RECTIFICATION_HPP 19 #define PIC_COMPUTER_VISION_RECTIFICATION_HPP 25 #include "../base.hpp" 27 #include "../image.hpp" 29 #include "../image_vec.hpp" 31 #include "../filtering/filter_warp_2d.hpp" 32 #include "../filtering/filter_rotation.hpp" 34 #include "../computer_vision/camera_matrix.hpp" 36 #include "../util/eigen_util.hpp" 38 #ifndef PIC_DISABLE_EIGEN 40 #ifndef PIC_EIGEN_NOT_BUNDLED 41 #include "../externals/Eigen/Dense" 42 #include "../externals/Eigen/SVD" 43 #include "../externals/Eigen/Geometry" 45 #include <Eigen/Dense> 47 #include <Eigen/Geometry> 54 #ifndef PIC_DISABLE_EIGEN 72 if(img0 == NULL || img1 == NULL) {
85 int bmin0[2], bmin1[2], bmax0[2], bmax1[2];
91 bmin0[1] =
MIN(bmin0[1], bmin1[1]);
92 bmax0[1] =
MAX(bmax0[1], bmax1[1]);
97 for(
int i = 0; i < 2; i++) {
98 bmin0[i] =
MIN(bmin0[i], bmin1[i]);
101 bmax0[i] =
MAX(bmax0[i], bmax1[i]);
109 Image *img0_r = NULL;
110 Image *img1_r = NULL;
112 bool bTest = out->
size() == 2;
122 out->push_back(img0_r);
123 out->push_back(img1_r);
141 Eigen::Matrix34d &M0,
142 Eigen::Matrix34d &M1,
144 bool bPartial =
true)
147 if(img0 == NULL || img1 == NULL) {
155 Eigen::Matrix34d M0_r, M1_r;
156 Eigen::Matrix3d T0, T1;
161 Eigen::Vector3d corners[4], corners_T0[4];
162 corners[0] = Eigen::Vector3d(0.0, 0.0, 1.0);
163 corners[1] = Eigen::Vector3d(img0->
widthf, 0.0, 1.0);
164 corners[2] = Eigen::Vector3d(img0->
widthf, img0->
heightf, 1.0);
165 corners[3] = Eigen::Vector3d(img0->
heightf, 0.0, 1.0);
167 for(
int i = 0; i < 4; i ++) {
168 corners_T0[i] = T0 * corners[i];
169 corners_T0[i] /= corners_T0[i][2];
172 auto d_c = corners[2] - corners[0];
173 auto d_c_T0 = corners_T0[2] - corners_T0[0];
175 bool b_x = std::signbit(d_c[0]) == std::signbit(d_c_T0[0]);
176 bool b_y = std::signbit(d_c[1]) == std::signbit(d_c_T0[1]);
178 double f_x = b_x ? 1.0 : -1.0;
179 double f_y = b_y ? 1.0 : -1.0;
213 bool bPartial =
true)
216 if(img0 == NULL || img1 == NULL) {
224 Eigen::Matrix34d M0_r, M1_r;
225 Eigen::Matrix3d T0, T1;
244 Eigen::Matrix3d &R1, Eigen::Vector3d &t1,
245 Eigen::Matrix3d &R01, Eigen::Vector3d &t01)
248 Eigen::Matrix3d R0_t = Eigen::Transpose< Eigen::Matrix3d >(R0);
269 Eigen::Matrix3d &R01,
270 Eigen::Vector3d &t01,
274 if(img0 == NULL || img1 == NULL) {
283 Eigen::Matrix3d R01_t = Eigen::Transpose< Eigen::Matrix3d >(R01);
286 Eigen::Vector3d X(0.0, 1.0, 0.0);
291 double alpha = std::acos(t01.dot(X));
292 Eigen::Matrix3d rot, rotation1;
294 rot = Eigen::AngleAxisd(alpha, n);
295 rotation1 = rot * R01_t;
297 Eigen::Matrix3f rotation0f, rotation1f;
298 rotation0f = rot.cast<
float>();
299 rotation1f = rotation1.cast<
float>();
306 #endif // PIC_DISABLE_EIGEN 310 #endif // PIC_COMPUTER_VISION_RECTIFICATION_HPP int size() const
size computes the number of values.
Definition: image.hpp:481
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
bool getBCentroid()
getBCentroid
Definition: filter_warp_2d.hpp:108
PIC_INLINE ImageVec * computeImageRectification(Image *img0, Image *img1, Eigen::Matrix34d &M0, Eigen::Matrix34d &M1, ImageVec *out=NULL, bool bPartial=true)
computeImageRectification this function rectifies two images
Definition: rectification.hpp:139
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
PIC_INLINE ImageVec * computeImageRectificationWarp(Image *img0, Image *img1, Eigen::Matrix3d &T0, Eigen::Matrix3d &T1, ImageVec *out, bool bPartial=true)
computeImageRectificationWarp
Definition: rectification.hpp:65
float heightf
Definition: image.hpp:84
PIC_INLINE Matrix3x3 MatrixConvert(Eigen::Matrix3f &mat)
MatrixConvert converts a matrix from a Eigen::Matrix3f representation into a Matrix3x3 representation...
Definition: eigen_util.hpp:356
#define PIC_INLINE
Definition: base.hpp:33
float widthf
Definition: image.hpp:84
#define MIN(a, b)
Definition: math.hpp:69
The Image class stores an image as buffer of float.
Definition: image.hpp:60
void setBoundingBox(int *bmin, int *bmax)
setBoundingBox
Definition: filter_warp_2d.hpp:186
PIC_INLINE Eigen::Matrix3d DiagonalMatrix(Eigen::Vector3d D)
DiagonalMatrix creates a diagonal matrix.
Definition: eigen_util.hpp:113
PIC_INLINE void cameraRectify(Eigen::Matrix3d &K0, Eigen::Matrix3d &R0, Eigen::Vector3d &t0, Eigen::Matrix3d &K1, Eigen::Matrix3d &R1, Eigen::Vector3d &t1, Eigen::Matrix34d &P0_out, Eigen::Matrix34d &P1_out, Eigen::Matrix3d &T0, Eigen::Matrix3d &T1)
cameraRectify
Definition: camera_matrix.hpp:294
PIC_INLINE ImageVec * computeImageRectificationPanoramicLL(Image *img0, Image *img1, Eigen::Matrix3d &R01, Eigen::Vector3d &t01, ImageVec *out=NULL)
computeImageRectificationPanoramicLL
Definition: rectification.hpp:266
PIC_INLINE ImageVec Single(Image *img)
Single creates an std::vector which contains img; this is for filters input.
Definition: image_vec.hpp:36
Definition: bilateral_separation.hpp:25
#define MAX(a, b)
Definition: math.hpp:73
static void computeBoundingBox(Matrix3x3 &h, bool bCentroid, float width, float height, int *bmin, int *bmax)
computeBoundingBox
Definition: filter_warp_2d.hpp:122
PIC_INLINE void alignPanoramicLL(Eigen::Matrix3d &R0, Eigen::Vector3d &t0, Eigen::Matrix3d &R1, Eigen::Vector3d &t1, Eigen::Matrix3d &R01, Eigen::Vector3d &t01)
alignPanoramicLL
Definition: rectification.hpp:243
static Image * execute(Image *imgIn, Image *imgOut, float angleX, float angleY, float angleZ)
execute
Definition: filter_rotation.hpp:194
The FilterWarp2D class.
Definition: filter_warp_2d.hpp:31