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

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

Data Science用户
提问于 2020-12-11 12:57:15
回答 1查看 362关注 0票数 0

我的相机有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或两者,而不必重用该框架,因为我已经将帧中检测到的人的坐标保存到了数组中。

有人刚刚告诉我,如果我有至少3个3D点使用cv2.findHomography函数,我可以达到这个目标。我正在尝试这种方法。还有其他人有其他的输入吗?

EN

回答 1

Data Science用户

回答已采纳

发布于 2020-12-27 23:31:10

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

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

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

cv2.warpPerspective()转换图像itsef。

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

考虑到上面介绍的内容,我编写了一个函数,将给定BEVextrinsicslist_x_y点列表转换为D31

代码语言: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]
票数 0
EN
页面原文内容由Data Science提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://datascience.stackexchange.com/questions/86554

复制
相关文章

相似问题

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