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

Homography Transformation逆变换无法还原原图的问题咨询

单应性变换逆变换无法还原原图的问题

我对单应性变换(Homography Transformation)存在概念误解,测试发现正向变换效果正常,但使用逆单应矩阵对变换后的图像进行逆变换,完全无法还原出原图。

测试代码

import numpy as np
#import matplotlib.pyplot as plt
import cv2


img  = cv2.imread("colour.jpg")
height= img.shape[0] 
width = img.shape[1]
#################   参数设置 ###################################

f=200
rotX= 0.2
rotZ= 0.02
rotY= 0.002
distX = 0.5
distY =0.7
distZ= 0.1



K = np.array([[f, 0, width/2, 0],
            [0, f, height/2, 0],
            [0, 0,   1, 0]])

# K 逆矩阵
Kinv = np.zeros((4,3))
Kinv[:3,:3] = np.linalg.inv(K[:3,:3])*f
Kinv[-1,:] = [0, 0, 1]


RX = np.array([[1,           0,            0, 0],
                        [0,np.cos(rotX),-np.sin(rotX), 0],
                        [0,np.sin(rotX),np.cos(rotX) , 0],
                        [0,           0,            0, 1]])

RY = np.array([[ np.cos(rotY), 0, np.sin(rotY), 0],
                        [            0, 1,            0, 0],
                        [ -np.sin(rotY), 0, np.cos(rotY), 0],
                        [            0, 0,            0, 1]])

RZ = np.array([[ np.cos(rotZ), -np.sin(rotZ), 0, 0],
                            [ np.sin(rotZ), np.cos(rotZ), 0, 0],
                            [            0,            0, 1, 0],
                            [            0,            0, 0, 1]])

# 组合旋转矩阵 (RX,RY,RZ)
R = np.linalg.multi_dot([ RX , RY , RZ ])

# 平移矩阵
T = np.array([[1,0,0,distX],
                            [0,1,0,distY],
                            [0,0,1,distZ],
                            [0,0,0,1]])

# 整体单应矩阵
H = np.linalg.multi_dot([K, R, T, Kinv])
Hinv = np.linalg.inv(H)


transformed = cv2.warpPerspective(img, H, img.shape[:2][::-1])
back = cv2.warpPerspective(transformed, Hinv, transformed.shape[:2][::-1])




cv2.imshow("test", img)
cv2.waitKey(2000)

cv2.imshow("test", transformed)
cv2.waitKey(2000)

cv2.imshow("test", back)
cv2.waitKey(2000)

示例图

  • 原图:原图
  • 变换后图:变换后图
  • 逆变换后图:逆变换后图

内容的提问来源于stack exchange,提问作者Philipp Enöckl

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 15:35:13