title: HOW TO Find rhombus corners in OpenCV and crop a smaller rectangle out of it?
body: <p>I am willing to get a plain rectangle out of a warped Image.</p>
  
  <p>For example, once I have this sort of Image:
  <img src="https://i.stack.imgur.com/ZXmbg.png" alt="enter image description here"></p>
  
  <p>... I would like to crop the area correspondent to the following rectangle: 
  <img src="https://i.stack.imgur.com/Zh1eI.png" alt="enter image description here"></p>
  
  <p>... BUT my code is extracting this bigger frame:
  <img src="https://i.stack.imgur.com/SXQF4.png" alt="enter image description here"></p>
  
  <p>MY CODE IS SHOWN bellow:</p>
  
  <pre><code>int main(int argc, char** argv) {
      cv::Mat img = cv::imread(argv[1]);
  
      // Convert RGB Mat to GRAY
      cv::Mat gray;
      cv::cvtColor(img, gray, CV_BGR2GRAY);
  
      // Store the set of points in the image before assembling the bounding box
      std::vector&lt;cv::Point&gt; points;
      cv::Mat_&lt;uchar&gt;::iterator it = gray.begin&lt;uchar&gt;();
      cv::Mat_&lt;uchar&gt;::iterator end = gray.end&lt;uchar&gt;();
      for (; it != end; ++it) {
          if (*it)
              points.push_back(it.pos());
      }
  
      // Compute minimal bounding box
      Rect box = cv::boundingRect(cv::Mat(points));
  
      // Draw bounding box in the original image (debug purposes)
      cv::Point2f vertices[4];
      vertices[0] = Point2f(box.x, box.y  +box.height);
      vertices[1] = Point2f(box.x, box.y);
      vertices[2] = Point2f(box.x+ box.width, box.y);
      vertices[3] = Point2f(box.x+ box.width, box.y   +box.height);
  
      for (int i = 0; i &lt; 4; ++i) {
          cv::line(img, vertices[i], vertices[(i + 1) % 4], cv::Scalar(0, 255, 0), 1, CV_AA);
          cout &lt;&lt; "==== vertices (x, y) = " &lt;&lt; vertices[i].x &lt;&lt; ", " &lt;&lt; vertices[i].y &lt;&lt; endl;
      }
  
      cv::imshow("box", img);
      cv::imwrite("box.png", img);
  
      waitKey(0);
  
      return 0;
  }
  </code></pre>
  
  <p>Any ideas on how to find the rhombus corners and try to reduce them to a smaller rectangle?</p>