title: Opencv detect quadrilateral in Python
body: <p>I am using Python 2.7 and OpenCV 3.0. I am doing a project to <strong>detecting the car license plate</strong>. </p>
  
  <p>I am now checking the number of vertex of the contours. If there are 4 vertex(number of elements in approx), then it is more likely to be a <strong>rectangle</strong>/ <strong>parallelogram</strong>/ <strong>quadrilateral</strong> .</p>
  
  <pre><code>(cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
  cnts=sorted(cnts, key = cv2.contourArea, reverse = True)[:10]
  
  # loop over our contours
  for c in cnts:
      peri = cv2.arcLength(c, True)
      approx = cv2.approxPolyDP(c, 0.02 * peri, True)
      if len(approx) == 4 and ratio(approx):
          cv2.drawContours(image, [approx], -1, (0,255,0), 3)
  </code></pre>
  
  <p>And I got two quadrilaterals with array.</p>
  
  <p><a href="https://i.stack.imgur.com/rv2nq.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rv2nq.jpg" alt="enter image description here"></a></p>
  
  <p>However, you can see, there is an <strong>irregular polygon</strong>. This is the array:</p>
  
  <pre><code>[[[209 198]]
  
   [[466  94]]
  
   [[259 153]]
  
   [[247   1]]]
  </code></pre>
  
  <p>I am asking for how can I <strong>omitted the irregular quadrilateral.</strong> Thank you</p>