title: Get coordinates of contours in OpenCV
body: <p>Let's say that I have the following output image:</p>
  
  <p><img src="https://i.stack.imgur.com/ZhSt6.png" alt="enter image description here"></p>
  
  <p>Basically, I have video stream and I want to get coordinates of rectangle only in the output image. Here's my C++ code:</p>
  
  <pre><code>while(1)
      {
          capture &gt;&gt; frame;
  
          if(frame.empty())
              break;
  
          cv::cvtColor( frame, gray, CV_BGR2GRAY ); // Grayscale image
  
          Canny( gray, canny_output, thresh, thresh * 2, 3 );
  
          // Find contours
          findContours( canny_output, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
  
          // Draw contours
          Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
  
          for( int i = 0; i&lt; contours.size(); i++ )
          {
              Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
              drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() );
          }
  
          cv::imshow( "w", drawing );
  
          waitKey(20); // waits to display frame
  
      }
  </code></pre>
  
  <p>Thanks.</p>