Reputation: 155
I am trying to read data from a file, store it in a double array and then use the Mat constructor to create an object containing the data. However the output is not as expected.
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)<<" ";
}
}
Upvotes: 1
Views: 2247
Reputation: 39796
Mat samples = Mat(500,2,CV_32FC1,&d); // that's a *float* Mat !
you want;
Mat samples = Mat(500,2,CV_64FC1,&d);
Upvotes: 1