如何在OpenCV中撤消对单个点的透视变换 [英] How to undo a perspective transform for a single point in opencv

查看:109
本文介绍了如何在OpenCV中撤消对单个点的透视变换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用反透视图进行一些图像分析.我使用openCV函数getTransform和findHomography生成转换矩阵并将其应用于源图像.这很好用,我可以从想要的图像中得到要点.问题是,我不知道如何获取单个点值并撤消转换以将其重新绘制到原始图片上.我只想撤消此点集的变换以找到其原始位置.如何做到这一点. 这些点的格式来自openCV库的Point(x,y).

I am trying to do some image analysis using an Inverse Perspective Map. I used the openCV functions getTransform and findHomography to generate a transformation matrix and apply it to the source image. This works well and I am able to get the points from the image I want. The problem is, I don't know how I can take individual point values and undo the transform to draw them back on the original picture. I want to only undo the transform for this set of points to find their original location. How does one do this. The points are in the form Point(x,y) from the openCV library.

推荐答案

要反转单应性(例如,透视变换),通常只需反转变换矩阵即可.

To invert a homography (e.g. perspective transformation) you typically just invert the transformation matrix.

因此,要将某些点从目标图像转换回源图像,您需要反转转换矩阵并使用结果转换这些点.要使用转换矩阵对点进行转换,可以将其从右向右乘以矩阵,然后进行去均质化.

So to transform some points back from your destination image to your source image you invert the transformation matrix and transform those points with the result. To transform a point with a transformation matrix you multiply it from right to the matrix, maybe followed by a de-homogenization.

幸运的是,OpenCV不仅提供了warpAffine/warpPerspective方法,该方法将一个图像的每个像素转换为另一图像,而且还提供了转换单个点的方法.

Luckily, OpenCV provides not only the warpAffine/warpPerspective methods, which transform each pixel of one image to the other image, but there is method to transform single points, too.

使用cv::perspectiveTransform(inputVector, emptyOutputVector, yourTransformation)方法来变换一组点,其中

Use cv::perspectiveTransform(inputVector, emptyOutputVector, yourTransformation) method to transform a set of points, where

inputVectorstd::vector<cv::Point2f>(您也可以使用nx2或2xn矩阵,但这有时是错误的).相反,您可以使用cv :: Point3f类型,但是我不确定这些对象是用于3D转换的同质坐标点还是3D点(或者可能是两者?).

inputVector is a std::vector<cv::Point2f> (you can use a nx2 or 2xn matrix, too, but sometimes that's erroneous). Instead you can use cv::Point3f type, but I'm not sure whether those would be homgeneous coordinate points or 3D points for 3D transformation (or maybe both?).

outputVector是一个空的std::vector<cv::Point2f>,将在其中存储结果

outputVector is an empty std::vector<cv::Point2f> where the result will be stored

yourTransformation是双精度3x3 cv :: Mat(如findHomography提供的)转换矩阵(对于3D点,则为4x4).

yourTransformation is a double precision 3x3 cv::Mat (like provided by findHomography ) transformation matrix (or 4x4 for 3D points).

这篇关于如何在OpenCV中撤消对单个点的透视变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆