# OpenCV恢复平面图像时透视变换为何无效？

> 原文链接：https://robotics.hellobike.com/pitfalls/2017-10-19-robotics-se-14417
> 频道：pitfalls | 更新日期：2017-10-19 | 标签：auto, stackexchange, computer-vision, cameras, calibration, opencv
> 核心摘要：用warpPerspective恢复顶视图时需加WARP_INVERSE_MAP，并可用新相机矩阵或remap保留信息、提高效率。

# OpenCV恢复平面图像时透视变换为何无效？

::: v-pre
> 本文由 AI 根据公开内容整理，可能有误，请以原文为准：[OpenCV get topdown view of planar pattern by using intrinsic and extrinsic from cameraCalibrate](https://robotics.stackexchange.com/questions/14417/opencv-get-topdown-view-of-planar-pattern-by-using-intrinsic-and-extrinsic-from)（Robotics Stack Exchange #14417）

**状态**：已解决

## 问题

提问者用`calibrateCamera`得到内外参后，对畸变透视图B执行`undistort`和`warpPerspective`生成C，但结果几乎没有处理透视变换；后续还发现中间图`tempImgC`可能丢失外侧信息。

## 环境

Linux / ROS 机器人软件与控制通用开发环境

## 解决办法

1. 恢复图像时调用`warpPerspective(tempImgC, imgC, matPerspective, Size(2500, 2000), WARP_INVERSE_MAP)`。
2. 为避免`undistort`中间图丢失外侧信息，先用`getOptimalNewCameraMatrix(intrinsic, distCoeffs, Size(2500, 2000), 1)`生成`newIntrinsic`，再传给`undistort`并用`newIntrinsic*transRot3x3`计算透视矩阵。
3. 若逐帧处理需提升效率，可用`projectPoints`直接生成目标到源图的映射，再对每帧调用`remap`，避免中间图。

原问题作者：ricecakebear；采纳答案作者：ricecakebear。原内容依 CC BY-SA 4.0 授权，本页摘要同样依 CC BY-SA 4.0 授权。
:::

## 原始参考来源 (Sources)

- [Robotics Stack Exchange #14417：OpenCV get topdown view of planar pattern by using intrinsic and extrinsic from cameraCalibrate](https://robotics.stackexchange.com/questions/14417/opencv-get-topdown-view-of-planar-pattern-by-using-intrinsic-and-extrinsic-from)