title: Find 4 specific corner pixels and use them with warp perspective
body: <p>I'm playing around with OpenCV and I want to know how you would build a simple version of a perspective transform program. I have a image of a parallelogram and each corner of it consists of a pixel with a specific color, which is nowhere else in the image. I want to iterate through all pixels and find these 4 pixels. Then I want to use them as corner points in a new image in order to warp the perspective of the original image. In the end I should have a zoomed on square.</p>
  
  <pre><code>Point2f src[4]; //Is this the right datatype to use here?
  int lineNumber=0;
  //iterating through the pixels
  for(int y = 0; y &lt; image.rows; y++)
  {
      for(int x = 0; x &lt; image.cols; x++)
      {
          Vec3b colour = image.at&lt;Vec3b&gt;(Point(x, y));
      if(color.val[1]==245 &amp;&amp; color.val[2]==111 &amp;&amp; color.val[0]==10) { 
          src[lineNumber]=this pixel // something like Point2f(x,y) I guess
          lineNumber++;
      }
      }
  }
  /* I also need to get the dst points for getPerspectiveTransform 
  and afterwards warpPerspective, how do I get those? Take the other 
  points, check the biggest distance somehow and use it as the maxlength to calculate 
  the rest? */
  </code></pre>
  
  <p>How should you use OpenCV in order to solve the problem? (I just guess I'm not doing it the "normal and clever way") Also how do I do the next step, which would be using more than one pixel as a "marker" and calculate the average point in the middle of multiple points. Is there something more efficient than running through each pixel?  </p>
  
  <p>Something like this basically: </p>
  
  <p><a href="https://i.stack.imgur.com/5QT1x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5QT1x.png" alt="enter image description here"></a></p>