C# 单应矩阵变换

C# 单应矩阵变换,c#,image,2d,transformation,homography,C#,Image,2d,Transformation,Homography,我正在研究单应方法,将相关点从深度数组的矩形区域复制并扩展到新数组,但右下角的点不会改变单应数组。任何想法,建议,谢谢。谢谢,节日快乐 public short[] depthImg; public int topleftx = 10; public int toplefty = 20; public int toprightx = 300; public int toprighty = 20; public int bottomleftx = 30; public int bottomleft

我正在研究单应方法,将相关点从深度数组的矩形区域复制并扩展到新数组,但右下角的点不会改变单应数组。任何想法,建议,谢谢。谢谢,节日快乐

public short[] depthImg;
public int topleftx = 10;
public int toplefty = 20;
public int toprightx = 300;
public int toprighty = 20;
public int bottomleftx = 30;
public int bottomlefty = 200;
public int bottomrightx = 310;
public int bottomrighty = 220;

short[] homographyImg = new short[320 * 240];
for(int ii = 0; ii < 320 * 240; ii++)
{
    int xx = ii % 320;
    int yy = ii / 320;
    int lx =(topleftx + (bottomleftx - topleftx)*(yy/240));
    int rx =(toprightx + (bottomrightx - toprightx)*(yy/240));
    if (xx < rx & xx > lx)
    {
        int px = 320*(xx-lx)/(rx-lx);
        int ty =(toplefty + (toprighty - toplefty)*(px/320));
        int by =(bottomlefty + (bottomrighty - bottomlefty)*(px/320));
        if (yy > ty & yy < by)
        {
            int pxy = 240*(yy-ty)/(by-ty)*320 + px;
            homographyImg[pxy] = depthImg[ii];
        }
    }
}
//我无法在对话中粘贴代码,所以我上传到这里。这是一个类似的数组变换,它们修改角坐标以获得正确的图片

    for(int yy = 0; yy < newHeight; yy++)
    {
        for(int xx = 0; xx < newWidth; xx++)
        {
            int TLidx = (xx * 2) + yy * 2 * width;
            int TRidx = (xx * 2 + 1) + yy * width * 2;
            int BLidx = (xx * 2) + (yy * 2 + 1) * width;
            int BRidx = (xx * 2 + 1) + (yy * 2 + 1) * width;
            dst[newWidth- xx - 1 + yy * newWidth] = Color32.Lerp(Color32.Lerp(src[BLidx],src[BRidx],.5F),
                                                   Color32.Lerp(src[TLidx],src[TRidx],.5F),.5F);
        }
    }

您确定要在if语句中使用&而不是&?我相信&是好的,因为这两个条件都应该是真的,在左-右或更高的上-下范围内,无论第一个表达式的真实性如何,都将对这两个表达式求值将计算每个表达式,并在第一个表达式错误时停止。一个问题是整数除法,尽管我不确定这是否是问题所在。几乎总是在b大于a的地方除以a/b。这将返回0。将常数设为双精度,例如320.0或将括号保留在一旁。&&的问题在于,即使第一个常数为真,它也是真的。省略括号确实有帮助,但我发现的主要问题是,表示这些点的图片以抛物线方式而不是线性方式弯曲。