首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >哪一个openCv函数可以用来计算给定点坐标和摄像机extrinsics/本质的BEV透视变换?

哪一个openCv函数可以用来计算给定点坐标和摄像机extrinsics/本质的BEV透视变换?
EN

Stack Overflow用户
提问于 2020-12-11 12:47:47
回答 3查看 913关注 0票数 3

我的相机有3x3 intrinsics4x3 extrinsics矩阵,通过cv2.calibrateCamera()获得。

现在,我想使用这些参数来计算从摄像机获得的帧中任意给定坐标的BEV (Bird Eye View)变换。

哪个openCv函数可用于计算给定点坐标和摄像机extrinsics和/或intrinsics 3x3 matricesBEV透视图转换

我在下面的文章中发现了一些非常相关的东西:基于https://deepnote.com/article/social-distancing-detector/https://www.pyimagesearch.com/2014/08/25/4-point-opencv-getperspective-transform-example/

他们使用cv2.getPerspectiveTransform()来获取3X3 matrix,但是我不知道这个矩阵是代表intrinsicsextrinsecs还是其他什么东西。然后,他们使用这样的矩阵来转换点列表,方式如下:

代码语言:javascript
复制
#Assuming list_downoids is the list of points to be transformed and matrix is the one obtained above
list_points_to_detect = np.float32(list_downoids).reshape(-1, 1, 2)
transformed_points = cv2.perspectiveTransform(list_points_to_detect, matrix)

我真的需要知道是否可以使用这个cv2.perspectiveTransform函数来计算转换,或者是否有更好的方法使用extrinsicsintrinsics或两者,而不必重用框架,因为我已经将检测到的/选定的坐标保存在数组中。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2020-12-27 23:30:17

经过深入的调查,我找到了一个很好的解决办法:

projection matrixextrinsicintrinsic摄像机矩阵之间的乘法器。

当我们没有摄像头时,cv2.getPerspectiveTransform()会给我们Projection Matrix

cv2.warpPerspective()转换图像itsef。

对于上面的问题,我们不需要这两个函数,因为我们已经有了extrinsicsintrinsecs和图像中点的坐标。

考虑到以上所述,我编写了一个函数,将给定的BEVextrinsics中的点列表转换为extrinsics

代码语言:javascript
复制
    def compute_point_perspective_transformation(intrinsics, extrinsics, point_x_y):
    """Auxiliary function to project a specific point to BEV
        
        Parameters
        ----------
        intrinsics (array)     : The camera intrinsics matrix
        extrinsics (array)     : The camera extrinsics matrix
        point_x_y (tuple[x,y]) : The coordinates of the point to be projected to BEV
        
        Returns
        ----------
        tuple[x,y] : the projection of the point
    """
        # Using the camera calibration for Bird Eye View
        intrinsics_matrix = np.array(intrinsics, dtype='float32')
        #In the intrinsics we have parameters such as focal length and the principal point

        extrinsics_matrix = np.array(extrinsics, dtype='float32')
        #The extrinsic matrix stores the position of the camera in global space
        #The 1st 3 columns represents the rotation matrix and the last is a translation vector
        extrinsics = extrinsics[:, [0, 1, 3]]

        #We removed the 3rd column of the extrinsics because it represents the z coordinate (0)
        projection_matrix = np.matmul(intrinsics_matrix, extrinsics_matrix)

        # Compute the new coordinates of our points - cv2.perspectiveTransform expects shape 3
        list_points_to_detect = np.array([[point_x_y]], dtype=np.float32)
        transformed_points = cv2.perspectiveTransform(list_points_to_detect, projection_matrix)
        return transformed_points[0][0][0], transformed_points[0][0][1]
票数 1
EN

Stack Overflow用户

发布于 2020-12-11 14:48:01

答案是:如果没有与图像像素相关的距离信息,就不可能计算场景的BEV。

想想看:想象一下,你有一张垂直屏幕的图片:然后鸟瞰就成了一条线。现在假设这个屏幕显示的是一个景观的图像,并且这个屏幕的图片与风景本身的图片是无法区分的。BEV仍然是一条线(虽然是彩色的)。

现在,假设你有一张完全相同的图片,但这一次它不是一张屏幕的图片,而是一幅风景的图片。然后,鸟眼视图是而不是一条线,更接近我们通常想象的BEV。

最后,让我声明,OpenCV无法知道您的图片是否描述了其他东西的平面(即使给定了摄像机参数),因此,无法计算场景的BEV。函数cv2.perspectiveTransform需要您传递给它一个同形矩阵(您可以使用cv2.findHomography()获得一个矩阵,但是您也需要一些关于图像的距离信息)。

很抱歉,这个否定的答案,但没有办法解决你的问题,只考虑到相机的内在和外部校准矩阵。

票数 2
EN

Stack Overflow用户

发布于 2022-03-27 11:53:35

既然你有相机模型,一个现成的(但不是完整的)解决方案就是使用getTopViewOfImage 从摄像机转换库中获取

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65251663

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档