title: Bounding box using OpenCV
body: <p>I want to get the bounding box of a filled black circle on a white background using opencv BoundingRect. I used the sample code from <a href="http://cgi.cse.unsw.edu.au/~cs4411/wiki/index.php?title=OpenCV_Guide#Finding_bounding_boxes_around_regions_of_a_binary_image" rel="nofollow noreferrer">http://cgi.cse.unsw.edu.au/~cs4411/wiki/index.php?title=OpenCV_Guide#Finding_bounding_boxes_around_regions_of_a_binary_image</a> but failed to get the properties of the bounding box and draw it into the image. Should be a simple problem, I think, but still I fail doing it...</p>
  
  <p>Would be nice, if you could write down some sample code.</p>
  
  <p>Thanks.</p>
  
  <hr>
  
  <p>The picture I'm using at the moment is an image of 1392x1040 pixels with a big black circle in the middle (diameter around 1000 pixels) and the rest of the image is white.</p>
  
  <p>My source code is:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;cv.h&gt;
  #include &lt;highgui.h&gt;
  
  using namespace std;
  
  int main(int argc, char** argv){
  
  
  IplImage* img_in = cvLoadImage("Schwarzer_Kreis.png",1);
  
  
  IplImage* img_working = cvCreateImage(cvGetSize(img_in), 8, 1);
  cvCvtColor(img_in, img_working, CV_BGR2GRAY);
  
  CvSeq* seq;
  
  vector&lt;CvRect&gt; boxes;
  
  CvMemStorage* storage = cvCreateMemStorage(0);
  cvClearMemStorage(storage);
  
  cvFindContours(img_working, storage, &amp;seq, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE, cvPoint(600,200));
  
  CvRect boundbox ;
  
  for(; seq; seq = seq-&gt;h_next) {
   boundbox = cvBoundingRect(seq);
   boxes.push_back(boundbox);
  }
  
  for (int ii=0; ii&lt;boxes.size(); ii++) {
  cout &lt;&lt; boxes[ii].x &lt;&lt; endl;
  cout &lt;&lt; boxes[ii].y &lt;&lt; endl;
  cout &lt;&lt; boxes[ii].width &lt;&lt; endl;
  cout &lt;&lt; boxes[ii].height &lt;&lt; endl;
  }
  
  
  cvWaitKey(0);
  
  return 0;
  
  }
  </code></pre>
  
  <hr>
  
  <p>The output that I geht from the program is:</p>
  
  <p>601</p>
  
  <p>201</p>
  
  <p>1390</p>
  
  <p>1038</p>