0

私はコンピュータービジョン用にc++で巨大なプログラムを作成しており、デバッグの目的でMatlabを使用しています。それと戦った後、Matlabとc ++(Visual studio 9コンパイラBTW)を使用すると、いくつかの単純な算術方程式の答えが異なることに気付きました。何故ですか?

算術演算は次のとおりです。

Matlab関数:

function [x,y]=shape_fun(p,shape,Ax,Ay)

x=p(1)+Ax+shape(1)+Ax.*shape(3)+Ay.*shape(4)+Ax.*Ax.*shape(5)/2+Ay.*Ay.*shape(6)/2+Ax.*Ay.*shape(7);
y=p(2)+Ay+shape(2)+Ax.*shape(8)+Ay.*shape(9)+Ax.*Ax.*shape(10)/2+Ay.*Ay.*shape(11)/2+Ax.*Ay.*shape(12);

end

C++関数

cv::Point2d deformed(const double shape_fun[12],const cv::Point2d p,const double Ax,const double Ay){
    cv::Point2d result;

    result.x=(p.x+Ax)+shape_fun[0]+shape_fun[2]*Ax+shape_fun[3]*Ay+shape_fun[4]*Ax*Ax/2*shape_fun[5]*Ay*Ay/2+shape_fun[6]*Ax*Ay;
    result.y=(p.y+Ay)+shape_fun[1]+shape_fun[7]*Ax+shape_fun[8]*Ay+shape_fun[9]*Ax*Ax/2*shape_fun[10]*Ay*Ay/2+shape_fun[11]*Ax*Ay;
    return result;

}

データ:

注:Matlabの値は、debbugerのc ++値からコピーして貼り付けられており、まったく同じです。

Ax=-12
Ay=-12
p=[468,683];
shape=[
     63.178114688537441
     36.536135487588474

    -0.038695673779030673
    -0.045313362559036965

     0.016469896824803026
     0.0017122284868442948
    -0.0030285669997117204

    -0.067902655024060773
     0.17995980761526389

     0.012716871878336870
    -0.036890386929202310
    -0.00081243692842574420
];

結果:

Matlab

x =
     3.947029931219995e+02
y =
     7.043339656551383e+02

C ++:

result  {x=393.54007007383439 y=703.64248713855773 }    cv::Point_<double>

注:私はOpenCV意図的に質問にタグを付けていません。明らかに私はOpenCVC++で使用していますが、これはxとyのcv::Point2d2つのdouble変数を持つ構造体であり、この質問はまったく関係ないと思いますOpenCV

4

1 に答える 1

10
result.x=
    (p.x+Ax)+
    shape_fun[0]+
    shape_fun[2]*Ax+
    shape_fun[3]*Ay+
    shape_fun[4]*Ax*Ax/2*
    shape_fun[5]*Ay*Ay/2+
    shape_fun[6]*Ax*Ay;
result.y=
    (p.y+Ay)+
    shape_fun[1]+
    shape_fun[7]*Ax+
    shape_fun[8]*Ay+
    shape_fun[9]*Ax*Ax/2*
    shape_fun[10]*Ay*Ay/2+
    shape_fun[11]*Ax*Ay;

(おそらく)

result.x=
    (p.x+Ax)+
    shape_fun[0]+
    shape_fun[2]*Ax+
    shape_fun[3]*Ay+
    shape_fun[4]*Ax*Ax/2+ /** change here **/
    shape_fun[5]*Ay*Ay/2+
    shape_fun[6]*Ax*Ay;
result.y=
    (p.y+Ay)+
    shape_fun[1]+
    shape_fun[7]*Ax+
    shape_fun[8]*Ay+
    shape_fun[9]*Ax*Ax/2+ /** change here **/
    shape_fun[10]*Ay*Ay/2+
    shape_fun[11]*Ax*Ay;
于 2013-03-26T16:28:47.390 に答える