Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Store mat data in txt

I am trying to write a mat file to txt file. I am using the above function to do so:

void writeMatToFile(cv::Mat& m, const char* filename){

ofstream fout(filename);
for(int i=0; i<m.rows; i++){
    for(int j=0; j<m.cols; j++){
        fout<<m.at<float>(i,j)<<"\t";
    }
    fout<<endl;
}
fout.close();

}

And the main code:

 string file = "output.txt";
 writeMatToFile(image,file.c_str());

However I am receiving unhandled exceptions. Any idea how can i store mat data in txt?

click to hide/show revision 2
retagged

updated 2014-02-24 03:45:29 -0600

berak gravatar image

Store mat data in txt

I am trying to write a mat file to txt file. I am using the above function to do so:

void writeMatToFile(cv::Mat& m, const char* filename){

ofstream fout(filename);
for(int i=0; i<m.rows; i++){
    for(int j=0; j<m.cols; j++){
        fout<<m.at<float>(i,j)<<"\t";
    }
    fout<<endl;
}
fout.close();

}

And the main code:

 string file = "output.txt";
 writeMatToFile(image,file.c_str());

However I am receiving unhandled exceptions. Any idea how can i store mat data in txt?