如何在opencv中撤消单个点的透视变换
How to undo a perspective transform for a single point in opencv
我正在尝试使用反向透视图进行一些图像分析。我使用openCV函数getTransform和findHomography生成一个变换矩阵,并将其应用于源图像。这很有效,我能够从我想要的图像中获得分数。问题是,我不知道如何获取单个点值并撤消变换,将它们绘制回原始图片上。我只想撤消这组点的变换,以找到它们的原始位置。如何做到这一点。这些点的形式为openCV库中的点(x,y)。
要反转单应性(例如透视变换),通常只需反转变换矩阵。
因此,要将一些点从目标图像转换回源图像,需要反转转换矩阵,并将这些点转换为结果。要用变换矩阵变换一个点,可以将其从右乘到矩阵,然后可能进行去均匀化。
幸运的是,OpenCV不仅提供了warpAffine/warpPerspective方法,将一张图像的每个像素转换为另一张图像,而且还提供了转换单个点的方法。
使用cv::perspectiveTransform(inputVector, emptyOutputVector, yourTransformation)
方法变换一组点,其中
inputVector
是std::vector<cv::Point2f>
(您也可以使用nx2或2xn矩阵,但有时这是错误的)。相反,您可以使用cv::Point3f类型,但我不确定这些是同源坐标点还是用于3D变换的3D点(或者两者都有?)。
outputVector
是空的std::vector<cv::Point2f>
,结果将存储在中
yourTransformation
是双精度3x3cv::Mat(类似于findHomography
提供的)变换矩阵(或3D点的4x4)。
下面是一个Python示例:
import cv2
import numpy as np
# Forward transform
point_transformed = cv2.perspectiveTransform(point_original, trans)
# Reverse transform
inv_trans = np.linalg.pinv(trans)
round_tripped = cv2.perspectiveTransform(point_transformed, inv_trans)
# Now, round_tripped should be approximately equal to point_original
您可以使用cv::perspectiveTransform(inputVector, emptyOutputVector, yourTransformation)
对点应用透视变换
Python:cv2.perspectiveTransform(src, m) → dst
src–输入双通道或三通道浮点数组;每个元素是要变换的2D/3D矢量。m–cv2.getPerspectiveTransform(_src, _dst)
先前计算的3x3或4x4浮点变换矩阵
在python中,您必须在numpy数组中传递点,如下所示:
points_to_be_transformed = np.array([[[0, 0]]], dtype=np.float32)
transfromed_points = cv2.perspectiveTransform(points_to_be_transformed, m)
transfromed_points的形状也将与输入数组相同:points_to_be_transformed
- 试试完美的正方形,你能给点小费吗
- 无法将结构注册为增强几何体3D点
- 具有单个函数的两个点的距离和坡度
- 点云库 - 如何将单个 RGB 值分配给整个点云
- 如何找到两个不同坐标系中对应点之间的旋转和平移(变换矩阵)
- 变换从三焦点张量计算的投影矩阵以估计3D点
- opencv:两个 3D 点云之间的刚性变换
- 傅立叶变换浮点问题
- 许多函数的单个DLL入口点
- 质量控制 与图形上的单个点进行交互
- OpenCV RHO 单应性方法不适用于透视变换
- 如何将变换矩阵应用于OpenCV中的点
- 是否可以有效地计数与数字线上的单个点P重叠的线段的数量
- 使用RANSAC估计两组点之间的二维变换
- 扭曲图像的反透视变换
- 变换矩阵——旋转变换后的新点坐标
- 从三个三维点计算变换矩阵
- 如何在opencv中撤消单个点的透视变换
- 两个坐标系之间的点CGAL变换
- 数组和单个数据点使用指针之间的区别