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

Putting data inside a Mat object in Opencv

本文关键字:Mat 对象 中的 Opencv 数据      更新时间:2023-10-16

我试图从文件中读取数据,将其存储在双数组中,然后使用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)<<" ";
    }
}
Mat samples = Mat(500,2,CV_32FC1,&d); // that's a *float* Mat !

你想要的;

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