title: OpenCV write each contour in a separate file
body: <p>Is it possible to write each found closed contour into a separate image file?</p>
  
  <p>I have a code like this:</p>
  
  <pre><code>//Finding contours  
  vector&lt;vector&lt;Point&gt; &gt; img_contours;
  vector&lt;Vec4i&gt; hierarchy;
  findContours( img0, img_contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, Point(0,0) );
  
  //Drawing contours  
  Mat contours_closed = Mat::zeros( img0.size(), CV_8UC1 );
  RNG rng(12345);
  int counter_closed_contours = 0;
  for (int i = 0; i &lt; img_contours.size(); i++) {
      double area = contourArea( img_contours[i] );
      if (area &gt; 2610 &amp;&amp; hierarchy[i][2] &lt; 0){
          counter_closed_contours++;
          //HERE I DON'T KNOW HOW TO CODE AND WHERE TO PUT IMWRITE
          imwrite("Contour_" + std::to_string(counter_closed_contours) + ".jpg", img_contours[i] );
          Scalar color = Scalar( rng.uniform(255, 255), rng.uniform(255, 255),rng.uniform(255, 255));
          drawContours( contours_closed, img_contours, i, color, CV_FILLED );
  
          }
  };
  </code></pre>
  
  <p>Code itself works fine, it finds closed contours and draws them. But since I want each contour in a separate file I don't know where to use imwrite and whether it's possible to get contour by contour inside a loop since it looks like drawContours returns an image of contours in one shot</p>