How to compare (x,y) points in array to extract rectangular shape in python
<p>I have a numpy array that was extracted from an image running the harris corner detection algorithm from opencv and I am trying to sort out four points that resembles a rectangle.</p>

<p>The following is the set of points:</p>

<pre><code>numpy.array([[194, 438],
   [495, 431],
   [512, 519],
   [490, 311],
   [548,  28],
   [407, 194],
   [181, 698],
   [169,  93],
   [408,  99],
   [221, 251],
   [395, 692],
   [574, 424],
   [431, 785],
   [538, 249],
   [397, 615],
   [306, 237]])
</code></pre>

<p>What would be the best method to compare the points for angles in quadrants within a slight deviation of 90 along with comparing how parallel lines between top and bottom points and left and right points are to return the four best possible candidates?</p>

<p><strong>Edit</strong></p>

<p>The image is roughly aligned with the rectangle so there is no significant rotation or distortion. The deviation allowance for perspective transformation and rough capturing I think can be +/- 10 degrees</p>

<p>Below is an image of the plotted lines with x and y locations. The desired corners are top-left (169,93), top-right (408,99), bottom-right (395,692), and bottom-left (181,698)
<a href="https://i.stack.imgur.com/iKhCV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iKhCV.png" alt="enter image description here"></a></p>