简体   繁体   English

在opencv2中使用3D感知

[英]Using 3D perception in opencv2

Can anyone please explain if it is possible, and if so how, to work with cv2.getPerspectiveTransform(). 任何人都可以解释一下是否可以使用cv2.getPerspectiveTransform()。

I have 3d information about my image: I know the length of a,b and also the Different heights of c,d,e,f and g. 我有3d关于我的图像的信息:我知道a,b的长度以及c,d,e,f和g的不同高度。 I made the height different to get more 3d information but if it isn't needed that will be preferable. 我设置了不同的高度以获取更多3d信息,但是如果不需要,则更好。

Ultimately I need to know where the pink dot really is in the rectangle after implementing the transform on my [x,y] position I get from the camera feed. 最终,我需要在从摄像机源获取的[x,y]位置上执行转换后,才知道粉红色的点真正在矩形中的哪个位置。

在此处输入图片说明

If you denote by C,D,E,F the positions of the four corners of the black polygon in the original image (each of them is a 2D point), and C',D',E',F' the positions of the corresponding points in your target image (probably (0,0), (a, 0), (a, b), (0, b)), M = cv2.getPerspectiveTransform({C,D,E,F}, {C',D',E',F'}) is the perspective transformation from one polygon to the other. 如果用C,D,E,F表示原始图像中黑色多边形的四个角的位置(每个角都是2D点),而C',D',E',F'的位置表示目标图像中的对应点(可能是(0,0),(a,0),(a,b),(0,b)),M = cv2.getPerspectiveTransform({C,D,E,F}, {C',D',E',F'})是从一个多边形到另一个多边形的透视图转换。

Given the position G of the vertical projection of g onto the black polygon in the original image, you can compute its position in the target image as cv2.transform(G, M). 给定g在原始图像中黑色多边形上的垂直投影的位置G,您可以将其在目标图像中的位置计算为cv2.transform(G,M)。 This will return a point (x,y,z), where the last coordinate z is a normalizing term. 这将返回一个点(x,y,z),其中最后一个坐标z是归一化项。 This z is zero when your point would be "at infinity" in the target image. 当您的点在目标图像中“无穷大”时,z为零。 If z is not zero, the point you are looking for is (x/z, y/z). 如果z不为零,则您要寻找的点是(x / z,y / z)。

If z is zero, your point is at infinity, in the direction of the support of vector (x, y) (think of the case where G would be at the intersection of the supporting lines of two opposite sides of the black polygon in the source image). 如果z为零,则您的点在向量(x,y)的支撑方向上是无穷大(例如G处于黑色多边形两个相对边的支撑线相交处的情况)源图像)。

If you know that the heights of c,d,e,f,g are equal, these points are also coplanar, and the exact same method applies to c,d,e,f,g instead of C,D,E,F,G. 如果您知道c,d,e,f,g的高度相等,那么这些点也是共面的,并且完全相同的方法适用于c,d,e,f,g而不是C,D,E,F ,G。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM