简体   繁体   English

为什么Matlab赋予的价值不同于C ++

[英]Why does Matlab gives different value than C++

I am creating a huge program in c++ for computer vision, and for debugging purposes I use Matlab. 我正在用c ++创建一个用于计算机视觉的大型程序,并且出于调试目的,我使用Matlab。 After time fighting with it I realised that some simple arithmetic equation's answer is different when using Matlab and c++ (Visual studio 9 compiler BTW). 经过一段时间的努力,我意识到使用Matlab和c ++(Visual Studio 9编译器BTW)时一些简单的算术方程的答案是不同的。 why is that? 这是为什么?

Here is the arithmetic operation: 这是算术运算:

Matlab function: 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++ function 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;

}

Data: 数据:

Note: Matlab values are copy-pasted from debbuger c++ values, they are EXACTLY the same. 注意: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
];

results: 结果:

Matlab : Matlab的

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

C++: C ++:

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

Note: I am not tagging the question as OpenCV on purpose. 注意:我不是故意将问题标记为OpenCV While evidently I am using OpenCV in C++, cv::Point2d is just a struct with two double variables, x and y, and I don't think this question is about OpenCV at all. 虽然显然我在C ++中使用OpenCV ,但cv::Point2d只是具有两个double变量x和y的结构,我根本不认为这个问题与OpenCV有关。

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;

should be (presumably) 应该(大概)

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;

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

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