50 std::vector<double> D;
51 std::vector<double> K;
54 algorithm::SensorManager::Instance();
56 AERROR <<
"Sensor '" << sensor_name <<
"' not exists!";
65 std::dynamic_pointer_cast<base::BrownCameraDistortionModel>(
68 height_ =
static_cast<int>(distort_model->get_height());
69 width_ =
static_cast<int>(distort_model->get_width());
70 d_mapx_.
Reshape({height_, width_});
71 d_mapy_.
Reshape({height_, width_});
74 I << 1.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 1.f;
77 distort_model->get_distort_params(), I,
78 distort_model->get_intrinsic_params(), width_,
79 height_, &d_mapx_, &d_mapy_);
104 const Eigen::Matrix3f &camera_model,
105 const Eigen::Matrix<float, 8, 1> &distortion,
const Eigen::Matrix3f &R,
106 const Eigen::Matrix3f &new_camera_model,
int width,
int height,
108 float fx = camera_model(0, 0);
109 float fy = camera_model(1, 1);
110 float cx = camera_model(0, 2);
111 float cy = camera_model(1, 2);
112 float nfx = new_camera_model(0, 0);
113 float nfy = new_camera_model(1, 1);
114 float ncx = new_camera_model(0, 2);
115 float ncy = new_camera_model(1, 2);
116 float k1 = distortion(0, 0);
117 float k2 = distortion(1, 0);
118 float p1 = distortion(2, 0);
119 float p2 = distortion(3, 0);
120 float k3 = distortion(4, 0);
121 Eigen::Matrix3f Rinv = R.inverse();
123 for (
int v = 0; v < height_; ++v) {
126 for (
int u = 0; u < width_; ++u) {
127 Eigen::Matrix<float, 3, 1> xy1;
128 xy1 << (static_cast<float>(u) - ncx) / nfx,
129 (
static_cast<float>(v) - ncy) / nfy, 1;
130 auto XYW = Rinv * xy1;
131 double nx = XYW(0, 0) / XYW(2, 0);
132 double ny = XYW(1, 0) / XYW(2, 0);
133 double r_square = nx * nx + ny * ny;
134 double scale = (1 + r_square * (k1 + r_square * (k2 + r_square * k3)));
136 nx * scale + 2 * p1 * nx * ny + p2 * (r_square + 2 * nx * nx);
138 ny * scale + p1 * (r_square + 2 * ny * ny) + 2 * p2 * nx * ny;
139 x_ptr[u] =
static_cast<float>(nnx * fx + cx);
140 y_ptr[u] =
static_cast<float>(nny * fy + cy);
void Reshape(const int num, const int channels, const int height, const int width)
Deprecated; use Reshape(const std::vector<int>& shape).
void InitUndistortRectifyMap(const Eigen::Matrix3f &camera_model, const Eigen::Matrix< float, 8, 1 > &distortion, const Eigen::Matrix3f &R, const Eigen::Matrix3f &new_camera_model, int width, int height, base::Blob< float > *d_mapx, base::Blob< float > *d_mapy)
bool imageRemap(const base::Image8U &src_img, base::Image8U *dst_img, const int src_width, const int src_height, const base::Blob< float > &map_x, const base::Blob< float > &map_y)