title: OpenCV: Approx. Segmentation from Contour-Image
body: <p>I'm trying to find a way to do an approximated segmentation on graveyard images (in context of CBIR in cultural scienes - but that's not the topic). So far I'm using this strategy:</p>
  
  <ul>
  <li>Blurr image twice (experimental findings)</li>
  <li>Apply Canny-Edge-Detector</li>
  <li><p>Finding the contours</p>
  
  <pre><code>int main(int argc, const char* argv[]) {
  
  cout &lt;&lt; "Starting " &lt;&lt; endl;
  Mat sourceImage;
  sourceImage = imread("singlesegmentation/DSCN5204.JPG",
          CV_LOAD_IMAGE_COLOR);
  
  if (!sourceImage.data) {
      cout &lt;&lt; "No Image found." &lt;&lt; endl;
      return -1;
  }
  
  cv::Mat blurred = imagePro::blurrNtimes(2, sourceImage);
  cv::Mat target = edged::applyCanny(blurred);
  cout &lt;&lt; "Canny applied " &lt;&lt; endl;
  
  vector&lt;vector&lt;Point&gt; &gt; contours;
  vector&lt;Vec4i&gt; hierarchy;
  cv::Point offset;
  offset.x = sourceImage.rows / 2;
  offset.y = sourceImage.cols / 2;
  cv::findContours(target, contours, hierarchy, CV_RETR_TREE ,
          CV_CHAIN_APPROX_SIMPLE, offset);
  cout &lt;&lt; "Contours applied " &lt;&lt; endl;
  
  int idx = 0;
  for (; idx &gt;= 0; idx = hierarchy[idx][0]) {
      Scalar color(rand() &amp; 255, rand() &amp; 255, rand() &amp; 255);
      drawContours(target, contours, idx, color, CV_FILLED, 8, hierarchy);
  }
  cout &lt;&lt; "Lines applied " &lt;&lt; endl;
  
  cv::namedWindow("Contour", CV_WINDOW_NORMAL);
  cv::imshow("Contour", target);
  cv::waitKey(0);
  
  return 0;
  </code></pre>
  
  <p>}</p></li>
  </ul>
  
  <p>The namespaces "imagePro" and "edged" contain simple code of opencv to blur a image and further process it. The code works. Here is an example-picture:
  <img src="https://i.stack.imgur.com/bQ4KU.png" alt="Contour-Image of Gravestone">
  But now I have no idea to segment the image. I want to go from the inside to the outside of the rectangle-stone and when I find a line I want to remember the coordinates and then cut the content. Thank you if you have an idea or hint!</p>