【问题标题】:Putting data inside a Mat object in Opencv在 Opencv 中将数据放入 Mat 对象中
【发布时间】:2014-03-20 14:17:00
【问题描述】:

我正在尝试从文件中读取数据,将其存储在双精度数组中,然后使用 Mat 构造函数创建包含数据的对象。但是输出并不像预期的那样。

ifstream in;
in.open("data");
double d[500][2];
for(int i=0;i<500;i++)
{
    for(int j=0;j<2;j++)
    {
        in>>d[i][j];

    }
}

Mat samples = Mat(500,2,CV_32FC1,&d);

for(int i=0;i<5;i++)
{
    cout<<"\n";
    for(int j=0;j<2;j++)
    {
        cout<<d[i][j]<<" ";
    }
}
cout<<"\nSamples";

for(int i=0;i<5;i++)
{
    cout<<"\n";
    for(int j=0;j<2;j++)
    {
        cout<<samples.at<double>(i,j)<<" ";
    }
}

【问题讨论】:

    标签: c++ opencv mat


    【解决方案1】:
    Mat samples = Mat(500,2,CV_32FC1,&d); // that's a *float* Mat !
    

    你想要的;

    Mat samples = Mat(500,2,CV_64FC1,&d);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-28
      • 2015-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多