title: OpenCV: Contour detection of shadowed image before OCR
body: <p>I am trying to OCR the picture of documents and my current approach is</p>
  <ol>
  <li>Read an image as a grayscale</li>
  <li>Binarize it thresholding</li>
  <li>Wrap perspective along the contours obtained from <code>cv2.findContours()</code></li>
  </ol>
  <p>The above works well if image is not shadowed. Now I want to get contours of shadowed pictures. My first attempt is to use <code>cv2.adaptiveThreshold</code> for step 2. The adaptive threshold successfully weakened the shadow but the resulted image lost the contrast between the paper and the background. That made cv2 impossible to find contours of the paper. So I need to use other method to remove the shadow.</p>
  <p><strong>Is there any way to remove shadow maintaining the background colour?</strong></p>
  <p>For reference here is the sample picture I am processing with various approaches. From left, I did</p>
  <ol>
  <li>grayscale</li>
  <li>thresholding</li>
  <li>adaptive thresholdin</li>
  <li>normalization</li>
  </ol>
  <p>My goal is to obtain the second picture without shadow.</p>
  <p><a href="https://i.stack.imgur.com/vIerC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vIerC.png" alt="enter image description here" /></a></p>
  <p>Please note that I actually have a temporary solution specifically to the picture which is to process the part of the picture with shadow separately. Yet, it is not the general solution to shadowed picture as its performance depends on the size, shape and position of a shadow so please use other methods.</p>
  <p>This is the original picture.</p>
  <p><a href="https://i.stack.imgur.com/TTEkN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TTEkN.jpg" alt="enter image description here" /></a></p>