在 Opencv 中将数据放入 Mat 对象中

Posted

技术标签:

【中文标题】在 Opencv 中将数据放入 Mat 对象中【英文标题】:Putting data inside a Mat object in Opencv 【发布时间】: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)<<" ";
    

【问题讨论】:

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

你想要的;

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

【讨论】:

以上是关于在 Opencv 中将数据放入 Mat 对象中的主要内容,如果未能解决你的问题,请参考以下文章