title: How to detect edge and crop an image in Python
body: <p>I'm new to Image Processing in Python and I'm trying to solve a common problem. I have an image having a signature of a person. I want to find the edges and crop it to fit the signature in the image.</p>
  
  <h2>Input Image</h2>
  
  <p><a href="https://i.stack.imgur.com/Ltbxx.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/Ltbxx.jpg" alt="enter image description here"></a></p>
  
  <h2>Expected Output</h2>
  
  <p><a href="https://i.stack.imgur.com/shfHX.png" rel="noreferrer"><img src="https://i.stack.imgur.com/shfHX.png" alt="enter image description here"></a></p>
  
  <p>I tried Canny Edge Detection and cropping the image using a list of existing solutions (articles &amp; answers) using PIL, CV2, but none seem to work. I'm looking for a working solution.</p>
  
  <p>Some solutions I tried:</p>
  
  <ol>
  <li><p><a href="https://www.quora.com/How-can-I-detect-an-object-from-static-image-and-crop-it-from-the-image-using-openCV" rel="noreferrer">https://www.quora.com/How-can-I-detect-an-object-from-static-image-and-crop-it-from-the-image-using-openCV</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/33998364/crop-image-from-all-sides-after-edge-detection">Crop Image from all sides after edge detection</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/36982736/how-to-crop-biggest-rectangle-out-of-an-image">How to crop biggest rectangle out of an image</a></p></li>
  </ol>
  
  <p>and many more... None worked although seems very simple. I encountered either errors or not expected output using any of the existing solutions.</p>