从一个2D平面中的另一个平面计算相应的点

问题描述 投票:0回答:1

我有一个平面A(由2D点A1,A2,A3,A4定义)和一个平面B(由2D点B1,B2,B3,B4定义)。这是校准过程。

我要解决的问题是如何从平面B中的平面A计算点X?

我读过有关单应性和变换矩阵的信息,但我发现一点与单点计算无关。

我正在使用C#和EMGU来完成代码部分,但是任何示例都将不胜感激。

谢谢。

c# emgucv
1个回答
0
投票

如果我正确理解了您的问题,则希望选择一些输入点,并希望将该图像扭曲到所需的位置。如果是这样,您可以将以下代码用作模板。

//Get the input image
Mat img = CvInvoke.Imread("img.png", ImreadModes.AnyColor);

//Declare an image that will hold the output
Mat output = new Mat(img.Width, img.Height);

//Get two points on the input image
Point point = new Point(0, 0);
Point point2 = new Point(100, 0);
Point point3 = new Point(0, 100);
Point point4 = new Point(100, 100);

//Store the points in a list
PointF[] srcPoints = new PointF[] { point, point2, point3, point4 };

//Declare where you want the image to end up
Point point5 = new Point(50, 0);
Point point6 = new Point(150, 0);
Point point7 = new Point(50, 100);
Point point8 = new Point(150, 100);

//Store those points in the list
PointF[] dstPoints = new PointF[] { point5, point6, point7, point8 };

//Calculate the homography matrix
Mat matrix = CvInvoke.FindHomography(srcPoints, dstPoints, RobustEstimationAlgorithm.AllPoints);

//Warp the image
CvInvoke.WarpPerspective(img, output, matrix, new Size(output.Width, output.Height), Inter.Area, Warp.Default);

这里您只是读入要使用的图像,声明起点和终点,然后将这些变量传递到两个函数中即可为您进行所有计算。当然,您将不得不更改一些值以适合您的特定情况,但这就是我过去解决此类问题的方式。

我希望这是您想要的,如果有任何疑问,请告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.