在偏斜的平方中找到偏移的坐标 [英] find shifted coordinate in skewed square

查看:90
本文介绍了在偏斜的平方中找到偏移的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正方形,我知道(A,B,C,D)的X,Y坐标,(E,F,G,H)的坐标,以及第一个框内的圆的位置(I, J)。

I have square, I know the X,Y coordinate for the (A,B,C,D) each, coordinate for (E,F,G,H) and the position for the circle inside first box (I,J).

所以..

我想在第二个框内找到同一圆的坐标..基于所有数据。

I want to find the coordinates for the same circle inside the second box .. base on all the data have.

推荐答案

您需要找到从第一个框到第二个框的转换

You need to find the transform from the first box to the second

B = T * A

B=T*A

因此,如果在平面上,则需要找到T,它是一个3x3矩阵

so you need to find T which is a 3x3 matrix if this is on the plane

求解此页面上所示的方程< a href = http://andrew.gibiansky.com/blog/image-processing/image-morphing/ rel = nofollow> http://andrew.gibiansky.com/blog/image-processing/image-morphing /

solve the equations as shown on this page http://andrew.gibiansky.com/blog/image-processing/image-morphing/

他也有程序-从第一个四边形仅需要三个点以及第二个四角形中相应的三个点

and he has the program too - you only need three points from the first quadrangle and the corresponding three points in the second quadrangle

private static float[] calculateTransform(Polygon pOriginal, Polygon pFinal){
    float a = pFinal.xpoints[0];
    float b = pFinal.ypoints[0];
    float c = pFinal.xpoints[1];
    float d = pFinal.ypoints[1];
    float e = pFinal.xpoints[2];
    float f = pFinal.ypoints[2];

    float A = pOriginal.xpoints[0];
    float B = pOriginal.ypoints[0];
    float C = pOriginal.xpoints[1];
    float D = pOriginal.ypoints[1];
    float E = pOriginal.xpoints[2];
    float F = pOriginal.ypoints[2];

    float x = ((B-D)*(e-c) - (a-c)*(F-D)) / ((B-D)*(E-C) - (A-C)*(F-D));
    float y = (a*(E-C) + A*(c-e) - c*E + e*C)/(A*(D-F) + B*(E-C) + C*F - D*E);
    float t = c - x*C - y*D;

    float z = ((B-D)*(f-d) - (b-d)*(F-D)) / ((B-D)*(E-C) - (A-C)*(F-D));
    float w = (b*(E-C) + A*(d-f) - d*E + f*C)/(A*(D-F) + B*(E-C) + C*F - D*E);
    float s = d - z*C - w*D;

    float[] transform = {x, y, z, w, t, s};
    return transform;
}

然后将T应用于A上的任何点以获得B上的对应点

then apply T to any point on A to get the corresponding point on B

private static float[] applyTransform(float x, float y, float[] transform){
    float a = transform[0];
    float b = transform[1];
    float c = transform[2];
    float d = transform[3];
    float t = transform[4];
    float s = transform[5];

    float p = a * x + b * y + t;
    float q = c * x + d * y + s;
    float[] result = {p, q};
    return result;
}

这篇关于在偏斜的平方中找到偏移的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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