Best method to save and load data in a file for opencv 3.1 version

asked 2018-07-26 00:32:15 -0600

kishan patel gravatar image

updated 2018-07-27 01:24:28 -0600

I have <vector<mat> > test; I want to save it to file and read it back. I tried to write it to a FileStorage, but after I read it back, it became fails. Does anybody have an idea? Thanks.

edit retag flag offensive close merge delete

Comments

1
Balaji R gravatar imageBalaji R ( 2018-07-26 00:57:14 -0600 )edit
LBerger gravatar imageLBerger ( 2018-07-26 01:42:16 -0600 )edit

I have checked this link. But it make confuse me. Can you tell me that how can i save data to .xml file from "vector<mat> preprocessedFaces" variable and how can load data from file to this variable.

I have tried for .txt file.But did not used filestorage class.

If you can provide steps,it will great for me.

kishan patel gravatar imagekishan patel ( 2018-07-26 02:35:22 -0600 )edit

I have used these Miki's line of codes. But it gives error when try to read data from the file.

 //variable
  vector<Mat> preprocessedFaces;

  //write data in a file, its working fine
  for( int face_index = 0; face_index < preprocessedFaces.size(); face_index++ ) 
  {
    matwrite("train_data.txt",preprocessedFaces[face_index]);
  }

  //got error when tried to read data...here i got 10,because written data for 10 times 
  for(int index=0; index<10; index++)
  {
    preprocessedFaces[index] = matread("train_data.txt");   
  }
kishan patel gravatar imagekishan patel ( 2018-07-26 06:29:51 -0600 )edit

@kishan patel if you've got problem wuth miki code's you should ask to miki.

About xml it's in tutorial :

    fs << "R" << R;                                      // cv::Mat
    fs << "T" << T;
LBerger gravatar imageLBerger ( 2018-07-26 07:34:11 -0600 )edit

Okay LBerger. But i could not contact with him. If you got any correction from above lines of codes.Let me inform.

kishan patel gravatar imagekishan patel ( 2018-07-26 08:13:45 -0600 )edit

you cannot save a vector<mat> in one file using matwrite. To read it is preprocessedFaces.push_back(matread("train_data.txt")); you will get 10 images preprocessedFaces but always same image

LBerger gravatar imageLBerger ( 2018-07-26 08:29:20 -0600 )edit

Okay. So how can i save that type of data and load it after to that type of data-variable.

kishan patel gravatar imagekishan patel ( 2018-07-26 08:40:04 -0600 )edit