libfovis
primesense_depth.hpp
1 #ifndef __fovis_primesense_depth_hpp__
2 #define __fovis_primesense_depth_hpp__
3 
4 #include <inttypes.h>
5 #include <assert.h>
6 #include "feature_match.hpp"
7 #include "camera_intrinsics.hpp"
8 #include "rectification.hpp"
9 #include "depth_source.hpp"
10 
11 namespace fovis
12 {
13 
50 {
54  int width;
58  int height;
59 
63  double shift_offset;
68 
77 
86 };
87 
94 {
95  public:
102 
108  Eigen::Matrix4d getDepthUvdToDepthXyz() const {
109  double fx_inv = 1 / params.depth_params.fx;
110  double pdb_inv = 1 / params.projector_depth_baseline;
111  double a = -0.125 * fx_inv * pdb_inv;
112  double b = 0.125 * params.shift_offset * fx_inv * pdb_inv;
113  double cx = params.depth_params.cx;
114  double cy = params.depth_params.cy;
115  Eigen::Matrix4d result;
116  result <<
117  fx_inv, 0, 0, -cx * fx_inv,
118  0, fx_inv, 0, -cy * fx_inv,
119  0, 0, 0, 1,
120  0, 0, a, b;
121  return result;
122  }
123 
128  Eigen::Isometry3d getDepthXyzToRgbXyz() const {
129  Eigen::Isometry3d result = Eigen::Isometry3d::Identity();
130  result.translate(Eigen::Vector3d(params.depth_to_rgb_translation));
131  const double *q = params.depth_to_rgb_quaternion;
132  result.rotate(Eigen::Quaterniond(q[0], q[1], q[2], q[3]));
133  return result;
134  }
135 
140  Eigen::Matrix<double, 3, 4> getRgbXyzToRgbUvw() const {
141  return rgb_rectification->getInputCameraParameters().toProjectionMatrix();
142  }
143 
144  // ============= convenience functions =================
145 
153  Eigen::Matrix<double, 3, 4> getDepthUvdToRgbUvw() const {
155  }
156 
162  Eigen::Matrix4d getDepthUvdToRgbXyz() const {
163  return getDepthXyzToRgbXyz().matrix() * getDepthUvdToDepthXyz();
164  }
165 
170  return params;
171  }
172 
177  return rgb_rectification;
178  }
179 
180  private:
182 
183  Rectification* rgb_rectification;
184 };
185 
193 {
194  public:
196  ~PrimeSenseDepth();
197 
198  void setDisparityData(const uint16_t* disparity);
199 
200  bool getXyz(int u, int v, Eigen::Vector3d & xyz);
201  void getXyz(OdometryFrame * frame);
202  void refineXyz(FeatureMatch * matches,
203  int num_matches,
204  OdometryFrame * frame);
205 
218  inline uint16_t getDisparity(int rgb_u, int rgb_v) const;
219 
223  inline uint16_t getDisparityAtIRPixel(int ir_u, int ir_v) const;
224 
225  inline double getBaseline() const;
226 
227  inline bool haveXyz(int u, int v);
228 
229  private:
230  bool haveXyz(float u_f, float v_f);
231 
232  bool getXyzFast(KeypointData* kpdata);
233  bool getXyzInterp(KeypointData* kpdata);
234 
235  int _ir_width;
236  int _ir_height;
237 
238  const PrimeSenseCalibration* _calib;
239 
240  uint16_t* _disparity;
241 
242  // for each RGB camera pixel, stores the index of the corresponding
243  // disparity image pixel (v*width + u)
244  uint32_t* _rgb_to_disparity_map;
245 
246  uint32_t _disparity_map_max_index;
247 
248  Eigen::Matrix4d* _uvd1_d_to_xyz_c;
249 };
250 
251 uint16_t
252 PrimeSenseDepth::getDisparity(int u, int v) const
253 {
254  int rgb_index = v * _ir_width + u;
255  uint32_t disparity_index = _rgb_to_disparity_map[rgb_index];
256  if(disparity_index < _disparity_map_max_index) {
257  return _disparity[disparity_index];
258  } else {
259  return 0;
260  }
261 }
262 
263 uint16_t
264 PrimeSenseDepth::getDisparityAtIRPixel(int ir_u, int ir_v) const
265 {
266  assert(ir_u >= 0 && ir_v >= 0 && ir_u < _ir_width && ir_v < _ir_height);
267  return _disparity[ir_v * _ir_width + ir_u];
268 }
269 
270 double
272 {
273  return _calib->getParameters().projector_depth_baseline;
274 }
275 
276 bool
278 {
279  int rgb_index = v * _ir_width + u;
280  uint32_t disparity_index = _rgb_to_disparity_map[rgb_index];
281  return disparity_index < _disparity_map_max_index;
282 }
283 
284 }
285 #endif
Calibration data structure for Kinect / PrimeSense sensors.
Definition: primesense_depth.hpp:49
bool haveXyz(int u, int v)
Definition: primesense_depth.hpp:277
Eigen::Matrix4d getDepthUvdToRgbXyz() const
Definition: primesense_depth.hpp:162
double projector_depth_baseline
Definition: primesense_depth.hpp:67
double depth_to_rgb_quaternion[4]
Definition: primesense_depth.hpp:76
Stores data specific to an input frame.
Definition: frame.hpp:33
Provides depth estimates for input image pixels.
Definition: depth_source.hpp:29
Eigen::Isometry3d getDepthXyzToRgbXyz() const
Definition: primesense_depth.hpp:128
int width
Definition: primesense_depth.hpp:54
Represents a single image feature matched between two camera images taken at different times...
Definition: feature_match.hpp:41
Image feature used for motion estimation.
Definition: keypoint.hpp:49
int height
Definition: primesense_depth.hpp:58
uint16_t getDisparityAtIRPixel(int ir_u, int ir_v) const
Definition: primesense_depth.hpp:264
Eigen::Matrix< double, 3, 4 > getDepthUvdToRgbUvw() const
Definition: primesense_depth.hpp:153
const CameraIntrinsicsParameters & getInputCameraParameters() const
Definition: rectification.hpp:66
Eigen::Matrix< double, 3, 4 > getRgbXyzToRgbUvw() const
Definition: primesense_depth.hpp:140
Computes useful information from a PrimeSenseCalibrationParameters object.
Definition: primesense_depth.hpp:93
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
double cx
Definition: camera_intrinsics.hpp:64
double cy
Definition: camera_intrinsics.hpp:69
Eigen::Matrix< double, 3, 4 > toProjectionMatrix() const
Definition: camera_intrinsics.hpp:31
const Rectification * getRgbRectification() const
Definition: primesense_depth.hpp:176
Intrinsic parameters for a pinhole camera with plumb-bob distortion model.
Definition: camera_intrinsics.hpp:14
uint16_t getDisparity(int rgb_u, int rgb_v) const
Definition: primesense_depth.hpp:252
double getBaseline() const
Definition: primesense_depth.hpp:271
CameraIntrinsicsParameters rgb_params
Definition: primesense_depth.hpp:85
void refineXyz(FeatureMatch *matches, int num_matches, OdometryFrame *frame)
double depth_to_rgb_translation[3]
Definition: primesense_depth.hpp:72
Eigen::Matrix4d getDepthUvdToDepthXyz() const
Definition: primesense_depth.hpp:108
double fx
Definition: camera_intrinsics.hpp:54
PrimeSenseCalibration(const PrimeSenseCalibrationParameters &params)
const PrimeSenseCalibrationParameters & getParameters() const
Definition: primesense_depth.hpp:169
double shift_offset
Definition: primesense_depth.hpp:63
Stores depth data for a Kinect / PrimeSense camera.
Definition: primesense_depth.hpp:192
CameraIntrinsicsParameters depth_params
Definition: primesense_depth.hpp:81