vishwakayireddi1234 commited on
Commit
259b9b0
·
verified ·
1 Parent(s): cd3d0b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -39,12 +39,16 @@ Always format your response exactly like this:
39
  def ocr_image(pil_image):
40
  try:
41
  w, h = pil_image.size
42
- scale = max(1, 2000 // max(w, h))
43
  img = pil_image.resize((w * scale, h * scale), Image.LANCZOS)
44
  img = img.convert("L")
45
- img = ImageEnhance.Contrast(img).enhance(2.0)
 
46
  img = img.filter(ImageFilter.SHARPEN)
47
- text = pytesseract.image_to_string(img, config="--psm 6 --oem 3").strip()
 
 
 
48
  return text if len(text) > 10 else None
49
  except Exception:
50
  return None
 
39
  def ocr_image(pil_image):
40
  try:
41
  w, h = pil_image.size
42
+ scale = max(1, 3000 // max(w, h))
43
  img = pil_image.resize((w * scale, h * scale), Image.LANCZOS)
44
  img = img.convert("L")
45
+ img = ImageEnhance.Contrast(img).enhance(3.0)
46
+ img = ImageEnhance.Sharpness(img).enhance(2.0)
47
  img = img.filter(ImageFilter.SHARPEN)
48
+ text = pytesseract.image_to_string(
49
+ img,
50
+ config="--psm 6 --oem 3 -c tessedit_char_whitelist=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.+=-/() "
51
+ ).strip()
52
  return text if len(text) > 10 else None
53
  except Exception:
54
  return None