Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opencv 移位像素代码片段的说明_Opencv_Shift_Distortion_Radial_Coefficients - Fatal编程技术网

Opencv 移位像素代码片段的说明

Opencv 移位像素代码片段的说明,opencv,shift,distortion,radial,coefficients,Opencv,Shift,Distortion,Radial,Coefficients,我已经移植到新的C++ API中,从答案中得到代码。然而,虽然我理解了大部分代码,但我无法理解calc_shift()函数背后的概念以及像素偏移是如何提取的。如果有人能给我一个解释,我将非常感激。该功能具有以下功能: float calc_shift(float x1,float x2,float cx,float k) { float thresh = 1; float x3 = x1+(x2-x1)*0.5; float res1 = x1+((x1-cx)*k*((

我已经移植到新的C++ API中,从答案中得到代码。然而,虽然我理解了大部分代码,但我无法理解calc_shift()函数背后的概念以及像素偏移是如何提取的。如果有人能给我一个解释,我将非常感激。该功能具有以下功能:

float calc_shift(float x1,float x2,float cx,float k)
{
    float thresh = 1;
    float x3 = x1+(x2-x1)*0.5;
    float res1 = x1+((x1-cx)*k*((x1-cx)*(x1-cx)));
    float res3 = x3+((x3-cx)*k*((x3-cx)*(x3-cx)));

    std::cerr<<"x1: "<<x1<<" - "<<res1<<" x3: "<<x3<<" - "<<res3<<std::endl;

    if(res1>-thresh and res1 < thresh)
        return x1;
    if(res3<0){
        return calc_shift(x3,x2,cx,k);
    }else{
        return calc_shift(x1,x3,cx,k);
    }

}
我想理解上面的代码,因为我还想将其用于k<0的枕形失真情况。如果我现在这样使用它,代码就会陷入一个带有k的无限循环中
int w = src.cols;
int h = src.rows;

xShift = calc_shift(0, Cx - 1, Cx, k);
float newCenterX = w - Cx;
float xShift2 = calc_shift(0, newCenterX - 1, newCenterX, k);

yShift = calc_shift(0, Cy - 1, Cy, k);
float newCenterY = w - Cy;
float yShift2 = calc_shift(0, newCenterY - 1, newCenterY, k);

xScale = (w - xShift - xShift2) / w;
yScale = (h - yShift - yShift2) / h;