简体   繁体   English

如何在矩形坐标上应用变换

[英]How to apply transformation on rectangle coordinates

I am detecting an object in my code and drawing a rectangle around it. 我在代码中检测到一个对象,并在其周围绘制了一个矩形。 I have four variables to draw rectangle: X, Y, Width, and Height. 我有四个变量来绘制矩形:X,Y,宽度和高度。 I have found a transformation matrix that needs to be applied on the rectangle. 我发现需要在矩形上应用的转换矩阵。 The transformation matrix returned is a 3*3 matrix like this: 返回的转换矩阵是一个3 * 3的矩阵,如下所示:

Tinv =

    1.0022    0.0018        0

   -0.0018    1.0022         0

   -0.4353   -0.9079    1.0000

How to apply the transformation on the rectangle using this matrix? 如何使用此矩阵在矩形上应用变换?

What you should do is calculate all four vertices of the rectangle and then apply the transformation on each individual vertex. 您应该做的是计算矩形的所有四个顶点,然后将变换应用于每个单独的顶点。 This should be easy enough; 这应该很容易; if I get what you're trying to do, then you could use something like the following for say: 如果我知道您要执行的操作,则可以使用类似以下内容的方法:

X = 1;
Y = 2.34;
W = 3.21;
H = 2;

The vertices could now be (assuming that (X,Y) denotes the top left vertex of your rectangle with its base at 0 radian: 顶点现在可以是(假设(X,Y)表示矩形的左上顶点,其底数为0弧度:

(x1,y1) = (1,2.34)
(x2,y2) = (4.21,2.34)
(x3,y3) = (4.21,0.34)
(x4,y4) = (1,0.34)

This could now be represented as: 现在可以表示为:

[
1.00    2.34    0.00
4.21    2.34    0.00
4.21    0.34    0.00
1.00    0.34    1.00
]

This could now be transformed as required by simple matrix multiplication. 现在可以根据需要通过简单的矩阵乘法对其进行转换。

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

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