首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用cv2.fisheye.undistortPoints将失真空间中的点转换为未失真空间中的点?

如何使用cv2.fisheye.undistortPoints将失真空间中的点转换为未失真空间中的点?
EN

Stack Overflow用户
提问于 2021-08-18 17:35:01
回答 1查看 146关注 0票数 0

我正在尝试使用opencv鱼眼函数将未失真空间中的特征映射回失真空间。我可以通过以下代码成功地将我的图像从相机扭曲的鱼眼图像转换到常规空间:

代码语言:javascript
运行
复制
DIM = (953, 720)
K = np.array(
    [
        [407.0259762535615, 0.0, 488.89663712932474],
        [0.0, 409.25366832487896, 388.1998354574297],
        [0.0, 0.0, 1.0],
    ]
)
D = np.array(
    [
        [-0.04485892302426824],
        [0.0787884305594057],
        [-0.08374236678783106],
        [0.027626067632899026],
    ]
)
img = np.zeros((720, 953, 3), dtype=np.uint8)
img = cv2.rectangle(img, (200, 150), (300, 200), (255, 255, 255), -1)
map1, map2 = cv2.fisheye.initUndistortRectifyMap(K, D, np.eye(3), K, DIM, cv2.CV_16SC2)
undistorted_img = cv2.remap(
    img, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT
)
# The rectangle is now found at 60, 43 in undistorted_img.  This code works.

但是,当我想要映射一个点(任何一个方向)时,我无法使用cv2.fisheye.undistortPoints或distortPoints将一个点从一个空间移动到另一个空间。通过使用尺寸为720 x 953的图像,我在x,y 200,150处放置了一个点。在未失真的图像中,该点现在位于60,43。但是,我不能使用这两个函数中的任何一个映射这两个点。下面是我的代码和输出:

代码语言:javascript
运行
复制
cv2.fisheye.undistortPoints(np.array([[[200, 150]]], dtype=np.float32), K, D)
# returns array([[[-1.0488918, -0.8601203]]], dtype=float32)
cv2.fisheye.distortPoints(np.array([[[200, 150]]], dtype=np.float32), K, D)
# returns array([[[1064.9419,  822.5983]]], dtype=float32)
cv2.fisheye.undistortPoints(np.array([[[60, 34]]], dtype=np.float32), K, D)
# Returns array([[[-4.061374 , -3.3357866]]], dtype=float32)
cv2.fisheye.distortPoints(np.array([[[60, 34]]], dtype=np.float32), K, D)
# array([[[1103.0706 ,  738.13654]]], dtype=float32)

所有这些都不符合我在图像转换本身中看到的内容。关于distortPoints和undistortPoints,我有什么不理解的地方?谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-19 16:35:19

我认为你需要使用estimate new camera matrix来保证不失真。

代码语言:javascript
运行
复制
points = np.array([[[200, 150]]]).astype(np.float32)
newcameramtx = cv2.fisheye.estimateNewCameraMatrixForUndistortRectify(
    K, D, DIM, None, balance=1)
dst = cv2.fisheye.undistortPoints(points, K, D, None, newcameramtx)
# [[[323.35104 242.06458]]]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68836988

复制
相关文章

相似问题

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