You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python中基于对应点的图像去畸变问题及异常排查

图像去畸变匹配异常问题

我有一张带有特定矩形的图像,需要对这些矩形做去畸变处理,以便通过像素距离估算真实世界距离。用网上的代码处理后,去畸变结果和原图完全无法匹配:
原图:pre
去畸变后图像:post
注:蓝色矩形为原图中的矩形,绿色为去畸变后的矩形。

尝试使用initUndistortRectifyMap和initInverseRectificationMap函数对图像和点进行重映射后,效果有所改善,但仍存在一个矩形映射异常:
处理前:pre-rectify
处理后:post-rectify

代码

通用部分

img = cv2.imread(str(image))
IMG_SIZE = img.shape[:-1]  # h, w
optimal_camera_matrix, roi = cv2.getOptimalNewCameraMatrix(camera_matrix, dist_coeffs, IMG_SIZE[::-1], 1, IMG_SIZE[::-1])
maps = cv2.initUndistortRectifyMap(
        camera_matrix,
        dist_coeffs,
        None,
        optimal_camera_matrix,
        IMG_SIZE[::-1],
        cv2.CV_32FC1,
    )
inv_maps = cv2.initInverseRectificationMap(
        camera_matrix,
        dist_coeffs,
        None,
        optimal_camera_matrix,
        IMG_SIZE[::-1],
        cv2.CV_32FC1,
    )

第一版代码

undistorted_image = cv2.undistort(img, camera_matrix, dist_coeffs)
undistorted_begin = cv2.undistortPoints(begin, camera_matrix, dist_coeffs, None, optimal_camera_matrix).squeeze()
undistorted_end = cv2.undistortPoints(end, camera_matrix, dist_coeffs, None, optimal_camera_matrix).squeeze()

第二版代码

undistorted_image = cv2.undistort(img, camera_matrix, dist_coeffs, None, optimal_camera_matrix)
undistorted_image = cv2.remap(img, maps[0], maps[1], cv2.INTER_LINEAR)
undistorted_begin = cv2.undistortPoints(begin, camera_matrix, dist_coeffs, None, optimal_camera_matrix).squeeze()
undistorted_end = cv2.undistortPoints(end, camera_matrix, dist_coeffs, None, optimal_camera_matrix).squeeze()

内容的提问来源于stack exchange,提问作者Caske2000

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 18:21:28