libfovis
rectification.hpp
1 #ifndef __fovis_rectification_hpp__
2 #define __fovis_rectification_hpp__
3 
4 #include <inttypes.h>
5 
6 #include <Eigen/Core>
7 
8 #include "camera_intrinsics.hpp"
9 
10 namespace fovis
11 {
12 
42 {
43  public:
44 
51  Rectification(const CameraIntrinsicsParameters& input_camera_params);
52 
57  Rectification(const CameraIntrinsicsParameters& input_camera_params,
58  const Eigen::Matrix3d& rotation,
59  const CameraIntrinsicsParameters& rectified_camera_params);
60 
61  ~Rectification();
62 
67  return _input_camera;
68  }
69 
74  const Eigen::Matrix3d& getRectificationRotation() const {
75  return *_rotation;
76  }
77 
85  return _rectified_camera;
86  }
87 
96  void rectifyLookup(int dist_u, int dist_v,
97  Eigen::Vector2d* rect_uv) const
98  {
99  assert(dist_u >= 0 && dist_v >= 0 && dist_u < _input_camera.width && dist_v < _input_camera.height);
100  int pixel_index = dist_v * _input_camera.width + dist_u;
101  rect_uv->x() = _map_x[pixel_index];
102  rect_uv->y() = _map_y[pixel_index];
103  }
104 
114  void rectifyLookupByIndex(int pixel_index,
115  Eigen::Vector2d* rect_uv) const
116  {
117  rect_uv->x() = _map_x[pixel_index];
118  rect_uv->y() = _map_y[pixel_index];
119  }
120 
128  void rectifyBilinearLookup(const Eigen::Vector2d& dist_uv,
129  Eigen::Vector2d* rect_uv) const {
130  int u = (int)dist_uv.x();
131  int v = (int)dist_uv.y();
132 
133  assert(u >= 0 && v >= 0 && u < _input_camera.width && v < _input_camera.height);
134 
135  // weights
136  float wright = (dist_uv.x() - u);
137  float wbottom = (dist_uv.y() - v);
138  float w[4] = {
139  (1 - wright) * (1 - wbottom),
140  wright * (1 - wbottom),
141  (1 - wright) * wbottom,
142  wright * wbottom
143  };
144 
145  int ra_index = v * _input_camera.width + u;
146  int neighbor_indices[4] = {
147  ra_index,
148  ra_index + 1,
149  ra_index + _input_camera.width,
150  ra_index + _input_camera.width + 1
151  };
152 
153  rect_uv->x() = 0;
154  rect_uv->y() = 0;
155  for(int i = 0; i < 4; ++i) {
156  rect_uv->x() += w[i] * _map_x[neighbor_indices[i]];
157  rect_uv->y() += w[i] * _map_y[neighbor_indices[i]];
158  }
159  }
160 
164  Rectification* makeCopy() const;
165 
166  private:
167  Rectification() {}
168 
169  void populateMap();
170 
171  CameraIntrinsicsParameters _input_camera;
172 
173  Eigen::Matrix3d* _rotation;
174  // use a pointer above to avoid EIGEN_MAKE_ALIGNED_OPERATOR_NEW
175 
176  CameraIntrinsicsParameters _rectified_camera;
177 
178  float* _map_x;
179  float* _map_y;
180 };
181 
182 } /* */
183 
184 #endif
int height
Definition: camera_intrinsics.hpp:49
const CameraIntrinsicsParameters & getInputCameraParameters() const
Definition: rectification.hpp:66
const Eigen::Matrix3d & getRectificationRotation() const
Definition: rectification.hpp:74
void rectifyLookup(int dist_u, int dist_v, Eigen::Vector2d *rect_uv) const
Definition: rectification.hpp:96
Maps image coordinates from an input image to image coordinates on a rectified camera.
Definition: rectification.hpp:41
quick and dirty profiling tool.inspired by the matlab tic/toc command
Definition: camera_intrinsics.hpp:6
int width
Definition: camera_intrinsics.hpp:44
Intrinsic parameters for a pinhole camera with plumb-bob distortion model.
Definition: camera_intrinsics.hpp:14
void rectifyLookupByIndex(int pixel_index, Eigen::Vector2d *rect_uv) const
Definition: rectification.hpp:114
Rectification * makeCopy() const
void rectifyBilinearLookup(const Eigen::Vector2d &dist_uv, Eigen::Vector2d *rect_uv) const
Definition: rectification.hpp:128
const CameraIntrinsicsParameters & getRectifiedCameraParameters() const
Definition: rectification.hpp:84