简体   繁体   English

如何通过投影矩阵从 KITTI 获得鸟瞰图?

[英]How to get Bird's Eye View from KITTI by Projection Matrix?

The goal is to get the Bird's Eye View from KITTI images (dataset), and I have the Projection Matrix (3x4).目标是从 KITTI 图像(数据集)中获得鸟瞰图,并且我有投影矩阵(3x4)。

There are many ways to generate transformation matrices.有很多方法可以生成变换矩阵。 For Bird's Eye View I have read some kind math expressions, like:对于鸟瞰图,我已经阅读了一些数学表达式,例如:

H12 = H2*H1-1=A R A-1=P*A-1 in OpenCV - Projection, homography matrix and bird's eye view H12 = H2*H1-1=A R A-1=P*A-1 in OpenCV - 投影、单应矩阵和鸟瞰图

and x = Pi * Tr * X in kitti dataset camera projection matrix和 x = Pi * Tr * X 在kitti 数据集相机投影矩阵

but none of these options worked for my purpose.但这些选项都不适用于我的目的。

PYTHON CODE PYTHON 代码

import numpy as np import cv2导入 numpy 作为 np 导入 cv2

image = cv2.imread('Data/RGB/000007.png') image = cv2.imread('数据/RGB/000007.png')

maxHeight, maxWidth = image.shape[:2]最大高度,最大宽度 = image.shape[:2]

M has 3x4 dimensions M 有 3x4 尺寸

M = np.array(([721.5377, 0.0, 609.5593, 44.85728], [0.0, 721.5377, 72.854, 0.2163791], [0.0, 0.0, 1.0, .002745884])) M = np.array(([721.5377, 0.0, 609.5593, 44.85728], [0.0, 721.5377, 72.854, 0.2163791], [0.0, 0.0, 1.0, .002745884]))

Here It's necessary a M matrix with 3x3 dimensions这里需要一个 3x3 维度的 M 矩阵

warped = cv2.warpPerspective(image, M, (maxWidth, maxHeight)) warped = cv2.warpPerspective(图像, M, (maxWidth, maxHeight))

show the original and warped images显示原始图像和变形图像

cv2.imshow("Original", image) cv2.imshow("原始", 图片)

cv2.imshow("Warped", warped) cv2.imshow("扭曲", 扭曲)

cv2.waitKey(0) cv2.waitKey(0)

I need to know how to manage the Projection Matrix for getting Bird's Eye View.我需要知道如何管理投影矩阵以获得鸟瞰图。

So far, everything I've tried throws warped images at me, without information even close to what I need.到目前为止,我尝试过的所有事情都会向我抛出扭曲的图像,甚至没有接近我需要的信息。

This is a example of image from the KITTI database.这是来自 KITTI 数据库的图像示例。

This is other example of image from the KITTI database.这是来自 KITTI 数据库的另一个图像示例。

On the left, images are shown detecting cars in 3D (above) and 2D (below).在左侧,图像显示在 3D(上)和 2D(下)中检测汽车。 On the right is the Bird's Eye View that I want to obtain.右边是我想要获得的鸟瞰图。 Therefore, I need to obtain the transformation matrix to transform the coordinates of the boxes that delimit the cars.因此,我需要获取变换矩阵来变换分隔汽车的框的坐标。

Here is my code to manually build a bird's eye view transform:这是我手动构建鸟瞰图变换的代码:

cv::Mat1d CameraModel::getInversePerspectiveMapping(double pixelPerMeter, cv::Point const & origin) const {
    double f = pixelPerMeter * cameraPosition()[2];
    cv::Mat1d R(3,3);
    R <<  0, 1, 0,
          1, 0, 0,
          0, 0, 1;

    cv::Mat1d K(3,3);
    K << f, 0, origin.x, 
         0, f, origin.y, 
         0, 0, 1;
    cv::Mat1d transformtoGround = K * R * mCameraToCarMatrix(cv::Range(0,3), cv::Range(0,3));
    return transformtoGround * mIntrinsicMatrix.inv();
}

The member variables/functions used inside the functions are函数内部使用的成员变量/函数是

  • mCameraToCarMatrix : a 4x4 matrix holding the homogeneous rigid transformation from the camera's coordinate system to the car's coordinate system. mCameraToCarMatrix :一个 4x4 矩阵,包含从相机坐标系到汽车坐标系的齐次刚性变换。 The camera's axes are x-right, y-down, z-forward.相机的轴是 x-right、y-down、z-forward。 The car's axes are x-forward, y-left, z-up.汽车的轴是 x-forward、y-left、z-up。 Within this function only the rotation part of mCameraToCarMatrix is used.在此 function 中,仅使用mCameraToCarMatrix的旋转部分。
  • mIntrinsicMatrix : the 3x3 matrix holding the camera's intrinsic parameters mIntrinsicMatrix : 保存相机内在参数的 3x3 矩阵
  • cameraPosition()[2] : the Z-coordinate (height) of the camera in the car's coordinate frame. cameraPosition()[2] : 汽车坐标系中相机的 Z 坐标(高度)。 It's the same as mCameraToCarMatrix(2,3) .它与mCameraToCarMatrix(2,3)相同。

The function parameters: function参数:

  • pixelPerMeter : the resolution of the bird's eye view image. pixelPerMeter :鸟瞰图的分辨率。 A distance of 1 meter on the XY plane will translate to pixelPerMeter pixels in the bird's eye view image. XY 平面上 1 米的距离将转换为鸟瞰图像中的pixelPerMeter像素。
  • origin : the camera's position in the bird's eye view image origin :鸟瞰图中相机的position

You can pass the transform matrix to cv::initUndistortRectifyMaps() as newCameraMatrix and then use cv::remap to create the bird's eye view image.您可以将变换矩阵作为newCameraMatrix传递给cv::initUndistortRectifyMaps() ,然后使用cv::remap创建鸟瞰图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM