title: How to Improve OCR on image with text in different colors and fonts?
body: <p>I'm using the <a href="https://cloud.google.com/vision/" rel="noreferrer">Google Vision API</a> to extract the text from some pictures, however, I have been trying to improve the accuracy (confidence) of the results with no luck.</p>
  
  <p>every time I change the image from the original I lose accuracy in detecting some characters.</p>
  
  <p>I have isolated the issue to have multiple colors for different words with can be seen that words in red for example have incorrect results more often than the other words.</p>
  
  <p>Example:</p>
  
  <p>some variations on the image from gray scale or b&amp;w</p>
  
  <p><a href="https://i.stack.imgur.com/QiSKN.png" rel="noreferrer"><img src="https://i.stack.imgur.com/QiSKN.png" alt="Original Image"></a></p>
  
  <p><a href="https://i.stack.imgur.com/1CdMH.png" rel="noreferrer"><img src="https://i.stack.imgur.com/1CdMH.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/yhXbS.png" rel="noreferrer"><img src="https://i.stack.imgur.com/yhXbS.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/2pi7p.png" rel="noreferrer"><img src="https://i.stack.imgur.com/2pi7p.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/ANjd0.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ANjd0.png" alt="enter image description here"></a></p>
  
  <p>What ideas can I try to make this work better, specifically changing the colors of text to a uniform color or just black on a white background since most algorithms expect that?</p>
  
  <p>some ideas I already tried, also some thresholding. </p>
  
  <pre><code>dimg = ImageOps.grayscale(im)
  cimg = ImageOps.invert(dimg)
  
  contrast = ImageEnhance.Contrast(dimg)
  eimg = contrast.enhance(1)
  
  sharp = ImageEnhance.Sharpness(dimg)
  eimg = sharp.enhance(1)
  </code></pre>