Ask Your Question
0

Save a vector<Mat> to a file and read it back in c++

asked 2013-05-28 14:33:25 -0500

elfis gravatar image

updated 2013-05-28 16:12:21 -0500

berak gravatar image

Hello, i am developing a face recognition application and i want to store a vector<mat> with faces to a file. Then, when the application starts, i want to read it back and fill the vector with the faces. I am doing this way because the FaceRecognizer model, does not support update (only the FaceRecognizer.LBPH supports it) and i am working with Eigenfaces and Fisherfaces. I tried to store it in a txt

std::ofstream output_file("./ppFaces.txt");
std::ostream_iterator<Mat> output_iterator(output_file, "\n");
std::copy(preprocessedFaces.begin(), preprocessedFaces.end(), output_iterator);

but when i read it back, the vector does not filled correct. Any ideas?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-05-29 02:53:21 -0500

berak gravatar image

unfortunately, there's no appropriate operator >> for cv::Mat, that's why reading back your txt-file fails.

you could use the FileStorage for this ( like the eigen reco saves/reads it's mats, look at the top of contrib/src/facerec.cpp ),

but i'd recommend, you store your images as images (imwrite/imread), and keep a txt-file with the filenames and label-id's

this will be much faster and take less space

edit flag offensive delete link more

Comments

Finally i prefered to store images as images (imwrite/imread). But which is the best format(pgm, png, etc) and compression to store the images so later the recognition works accurate?

elfis gravatar imageelfis ( 2013-07-02 05:53:11 -0500 )edit
1

i'd use png for this. imwrite("name.png",img) with default args does a (lossless) compression with level 3 already

berak gravatar imageberak ( 2013-07-02 06:28:38 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-05-28 14:33:25 -0500

Seen: 2,481 times

Last updated: May 29 '13