// from ground points to undistorted points via Homography cv::Mat undistorted_points = cv::Mat::ones(3, rows * cols, CV_64FC1); undistorted_points = H.inv() * ground_points; // 由单应性矩阵获取矫正图上的点
时间: 2024-04-06 12:30:45 浏览: 16
这段代码是用于将地面坐标系下的点云矩阵 `ground_points` 转换为畸变校正后的图像坐标系下的点云矩阵 `undistorted_points`。具体来说,该代码首先创建一个与 `ground_points` 矩阵大小相同的矩阵 `undistorted_points`,并将其所有元素初始化为 1,数据类型为 CV_64FC1(即 64 位单通道浮点数)。
然后,通过计算地面坐标系到畸变校正后的图像坐标系的变换矩阵的逆矩阵 `H.inv()`,将地面坐标系下的点云矩阵 `ground_points` 转换为畸变校正后的图像坐标系下的点云矩阵 `undistorted_points`。该转换同样通过矩阵乘法实现,即 `undistorted_points = H.inv() * ground_points`。
需要注意的是,由于 `ground_points` 和 `undistorted_points` 矩阵均为 3x(rows*cols) 的矩阵,因此它们可以在矩阵乘法中相乘。此外,由于 `H.inv()`、`ground_points` 和 `undistorted_points` 矩阵中的数据类型均为双精度浮点数,因此在计算矩阵乘法时不会产生数据类型转换的问题。
相关问题
std::vector<cv::Mat> channels(2); cv::Mat undistorted_points_temp = cv::Mat::ones(3, rows * cols, CV_64FC1); undistorted_points_temp = K.inv() * undistorted_points; cv::Mat undistorted_mat = cv::Mat::zeros(1, rows * cols, CV_64FC2); cv::s
std::vector<cv::Mat> channels(2);
cv::Mat undistorted_points_temp = cv::Mat::ones(3, rows * cols, CV_64FC1);
undistorted_points_temp = K.inv() * undistorted_points;
cv::Mat undistorted_mat = cv::Mat::zeros(1, rows * cols, CV_64FC2);
cv::split(undistorted_points_temp, channels);
cv::merge(channels, undistorted_mat);
以上代码实现了以下功能:
1. 定义了一个名为 channels 的 cv::Mat 类型的 vector,其大小为 2。
2. 创建了一个 3 行 rows*cols 列的 CV_64FC1 类型的矩阵 undistorted_points_temp,并将其所有元素初始化为 1。
3. 通过 K 的逆矩阵与 undistorted_points 相乘,得到一个新的矩阵 undistorted_points_temp。
4. 创建了一行 rows*cols 列的 CV_64FC2 类型的矩阵 undistorted_mat,并将其所有元素初始化为 0。
5. 将 undistorted_points_temp 矩阵拆分成多个通道,存储在名为 channels 的 vector 中。
6. 将 channels 中的通道合并成一个矩阵 undistorted_mat。
// from ground points to undistorted points via R and t // from ground points to camera points
这段注释表示将地面点云信息通过旋转矩阵 `R` 和平移向量 `t` 转换为畸变校正后的相机坐标系下的点云信息。具体来说,这个过程分为两步:
第一步是从地面坐标系下的点云信息转换为相机坐标系下的点云信息。这里可以使用旋转矩阵和平移向量来描述地面坐标系到相机坐标系之间的变换关系,即将地面坐标系下的点云信息转换到相机坐标系下的形式。这一步的结果是得到了相机坐标系下的点云信息,但仍然存在畸变。
第二步是通过畸变校正将相机坐标系下的点云信息转换为畸变校正后的相机坐标系下的点云信息。这里可以使用相机的内参矩阵和畸变系数对相机坐标系下的点云信息进行畸变校正,从而得到畸变校正后的相机坐标系下的点云信息。
经过这两步转换,就可以将地面坐标系下的点云信息转换为畸变校正后的相机坐标系下的点云信息。