title: How to exit from a function
body: <p>Sometimes when I use this function, it does not detect the edges of an image, that is because I would like to know how to exit the function, in case it does not find any contour, with an if loop for example.</p>
  
  <pre><code>def sort_contours(cnts,reverse = False):
      i = 0
      boundingBoxes = [cv2.boundingRect(c) for c in cnts]
      #if cnts==0:
        #quit()
      (cnts, boundingBoxes) = zip(*sorted(zip(cnts, boundingBoxes),
                                          key=lambda b: b[1][i], reverse=reverse))
      return cnts
  </code></pre>
  
  <p>With this output in failure case:</p>
  
  <pre><code>      7     (cnts, boundingBoxes) = zip(*sorted(zip(cnts, boundingBoxes),
  ----&gt; 8                                         key=lambda b: b[1][i], reverse=reverse))
        9     return cnts
       10 
  
  ValueError: not enough values to unpack (expected 2, got 0)
  </code></pre>
  
  <p>Before I made this </p>
  
  <pre><code>#if cnts==0:
    #quit()
  </code></pre>
  
  <p>Which does not work, any ideas?</p>