title: Save/Read Matrix from OpenCV FileNodeIterator
body: <p>I am having trouble saving and reading a <code>cv::Mat</code> saved into a <code>cv::FileNode</code> through which I am iterating. I can write the matrix to a file using</p>
  
  <pre><code>// Data to save
  std::vector&lt;cv::Mat&gt; masks;
  masks.push_back(cv::Mat::ones(3,3,CV_8UC1));
  masks.push_back(cv::Mat::zeros(2,2,CV_8UC1));
  
  // Open file for writing
  cv::FileStorage fs(file, cv::FileStorage::WRITE);
  
  // Create node
  fs &lt;&lt; "data" &lt;&lt; "[";
  for (size_t i=0; i&lt;masks.size(); ++i)
  {
      // Fill each node with data
      fs &lt;&lt; "{:";
      // Write other data...
      fs &lt;&lt; "mask" &lt;&lt; masks.at(i);
      fs &lt;&lt; "}";
  }
  fs &lt;&lt; "]";
  </code></pre>
  
  <p>Writing a file in this way causes no problems. However, subsequently opening this file causes an unhandled exception which prints:</p>
  
  <blockquote>
    <p>Reading OpenCV Error: Parsing error (testPR.yml(7): Missing , between
    the elemen ts) in unknown function, file
    ......\modules\core\src\persistence.cpp, line 12 63</p>
  </blockquote>
  
  <p>To read the matrix I attempt to do this:</p>
  
  <pre><code>// Open file for reading
  cv::FileStorage fs(file, cv::FileStorage::READ);   ///&lt; This causes an exception
  
  // Open node
  cv::FileNode d = fs["data"];
  cv::FileNodeIterator it = d.begin(), it_end = d.end();
  
  for( ; it!= it_end; ++it)
  {
      // Read other data...
      cv::Mat mask;
      (*it)["mask"] &gt;&gt; mask;
  }
  </code></pre>
  
  <p>Surely it's possible to save/read a matrix to a node in this manner, isn't it?</p>