title: Using Python and Tesseract OCR to solve Captcha
body: <p>I am not planning to spam, and besides Google has made captcha obsolete with reCaptcha. I am doing this as a project to learn more about OCR and eventually maybe neural networks. </p>
  
  <p>SO I have an image from a Captcha, I have been able to make modest progress, but the documentation on tesseract isn't exactly well documented. Here is the code I have so far and the results are bellow it.</p>
  
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common import keys
  import time
  import random
  import pytesseract
  from pytesseract import image_to_string 
  from PIL import Image, ImageEnhance, ImageFilter 
  
  
  def ParsePic():
      pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'
      im = Image.open("path\\screenshot.png") 
      im = im.filter(ImageFilter.CONTOUR)
      im = im.filter(ImageFilter.DETAIL)
      enhancer = ImageEnhance.Contrast(im)
      im = enhancer.enhance(4)
      im = im.convert('L')
      im.save('temp10.png')   
      text = image_to_string(Image.open('temp10.png'))
      print(text)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ih8km.jpg" rel="nofollow noreferrer">Original Image</a></p>
  
  <p><a href="https://i.stack.imgur.com/JfTSw.png" rel="nofollow noreferrer">Output</a></p>
  
  <p>I understand that Captcha was made specifically to defeat OCR, but I read that it is no longer the case, and Im interested in learning how it was done. </p>
  
  <p>My question is, how do I make the background the same color, so the text becomes easily readable?</p>