Apollo 10.0
自动驾驶开放平台
apollo::perception::camera::UndistortionHandler类 参考

#include <undistortion_handler.h>

apollo::perception::camera::UndistortionHandler 的协作图:

Public 成员函数

 UndistortionHandler ()
 
 ~UndistortionHandler ()
 
bool set_device (int device)
 
bool Init (const std::string &sensor_name, int device)
 
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 Handle (const base::Image8U &src_img, base::Image8U *dst_img)
 : Processing each image @params: src_img - input image array dst_img - output image array
 
bool Release (void)
 

详细描述

在文件 undistortion_handler.h28 行定义.

构造及析构函数说明

◆ UndistortionHandler()

apollo::perception::camera::UndistortionHandler::UndistortionHandler ( )
inline

在文件 undistortion_handler.h30 行定义.

30{ inited_ = false; }

◆ ~UndistortionHandler()

apollo::perception::camera::UndistortionHandler::~UndistortionHandler ( )
inline

成员函数说明

◆ Handle()

bool apollo::perception::camera::UndistortionHandler::Handle ( const base::Image8U src_img,
base::Image8U dst_img 
)

: Processing each image @params: src_img - input image array dst_img - output image array

在文件 undistortion_handler.cc85 行定义.

86 {
87 if (!inited_) {
88 return false;
89 }
90
91 if (!set_device(device_)) {
92 return false;
93 }
94
95 return imageRemap(src_img, dst_img, width_, height_, d_mapx_, d_mapy_);
96}
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)

◆ Init()

bool apollo::perception::camera::UndistortionHandler::Init ( const std::string &  sensor_name,
int  device 
)

在文件 undistortion_handler.cc45 行定义.

45 {
46 if (inited_) {
47 return true;
48 }
49
50 std::vector<double> D;
51 std::vector<double> K;
52
53 algorithm::SensorManager *sensor_manager =
54 algorithm::SensorManager::Instance();
55 if (!sensor_manager->IsSensorExist(sensor_name)) {
56 AERROR << "Sensor '" << sensor_name << "' not exists!";
57 return false;
58 }
59
60 if (!set_device(device)) {
61 return false;
62 }
63
65 std::dynamic_pointer_cast<base::BrownCameraDistortionModel>(
66 sensor_manager->GetDistortCameraModel(sensor_name));
67
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_});
72
73 Eigen::Matrix3f I;
74 I << 1.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 1.f;
75
76 InitUndistortRectifyMap(distort_model->get_intrinsic_params(),
77 distort_model->get_distort_params(), I,
78 distort_model->get_intrinsic_params(), width_,
79 height_, &d_mapx_, &d_mapy_);
80
81 inited_ = true;
82 return true;
83}
void Reshape(const int num, const int channels, const int height, const int width)
Deprecated; use Reshape(const std::vector<int>& shape).
Definition blob.cc:72
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)
first check imutoantoffset saved in device
Definition readme.txt:2
#define AERROR
Definition log.h:44
std::shared_ptr< BrownCameraDistortionModel > BrownCameraDistortionModelPtr

◆ InitUndistortRectifyMap()

void apollo::perception::camera::UndistortionHandler::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 
)

在文件 undistortion_handler.cc103 行定义.

107 {
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 float k4 = distortion(5, 0); // add k4,k5,k6 for Rational model
122 float k5 = distortion(6, 0);
123 float k6 = distortion(7, 0);
124
125 Eigen::Matrix3f Rinv = R.inverse();
126
127 for (int v = 0; v < height_; ++v) {
128 float *x_ptr = d_mapx->mutable_cpu_data() + d_mapx->offset(v);
129 float *y_ptr = d_mapy->mutable_cpu_data() + d_mapy->offset(v);
130 for (int u = 0; u < width_; ++u) {
131 Eigen::Matrix<float, 3, 1> xy1;
132 xy1 << (static_cast<float>(u) - ncx) / nfx,
133 (static_cast<float>(v) - ncy) / nfy, 1;
134 auto XYW = Rinv * xy1;
135 double nx = XYW(0, 0) / XYW(2, 0);
136 double ny = XYW(1, 0) / XYW(2, 0);
137 double r_square = nx * nx + ny * ny;
138 double r_quad = r_square * r_square;
139 double r_sextic = r_quad * r_square;
140 double scale = (1 + r_square * k1 + r_quad * k2 + r_sextic * k3) /
141 (1 + r_square * k4 + r_quad * k5 + r_sextic * k6);
142 double nnx =
143 nx * scale + 2 * p1 * nx * ny + p2 * (r_square + 2 * nx * nx);
144 double nny =
145 ny * scale + p1 * (r_square + 2 * ny * ny) + 2 * p2 * nx * ny;
146 x_ptr[u] = static_cast<float>(nnx * fx + cx);
147 y_ptr[u] = static_cast<float>(nny * fy + cy);
148 }
149 }
150}

◆ Release()

bool apollo::perception::camera::UndistortionHandler::Release ( void  )

在文件 undistortion_handler.cc98 行定义.

98 {
99 inited_ = false;
100 return true;
101}

◆ set_device()

bool apollo::perception::camera::UndistortionHandler::set_device ( int  device)

在文件 undistortion_handler.cc30 行定义.

30 {
31 device_ = device;
32 auto code = cudaSetDevice(device_);
33 if (code != cudaSuccess) {
34 AERROR << "cudaSetDevice failed: " << cudaGetErrorString(code);
35 return false;
36 }
37 return true;
38}

该类的文档由以下文件生成: