Ask Your Question
0

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

asked May 28 '13

elfis gravatar image

updated May 28 '13

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?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
3

answered May 29 '13

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

Preview: (hide)

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 (Jul 2 '13)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 (Jul 2 '13)edit

Question Tools

Stats

Asked: May 28 '13

Seen: 4,652 times

Last updated: May 29 '13