Problem with deactivating dictionary in tesseract using Python

Skip to first unread message

Sandra M.

Oct 11, 2019, 4:32:12 AM10/11/19
to tesseract-ocr
I'm trying to deactivate the tesseract dictionary, but I don't get it. I'm using tesseract 5.0.0 and use the Python code below. I read about the parameters load_system_dawg and load_freq_dawg to change them in the config, but I don't know how to do this exactly. Can someone give me more details how to do this?

import pytesseract
import argparse
import cv2
import os

# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to input image to be OCR'd")
args = vars(ap.parse_args())

# load the example image and convert it to grayscale
image = cv2.imread(args["image"])
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# write the grayscale image to disk as a temporary file so we can
# apply OCR to it
filename = "{}.png".format(os.getpid())
cv2.imwrite(filename, gray)

# load the image as a PIL/Pillow image, apply OCR, and then delete
# the temporary file
text = pytesseract.image_to_string(gray, lang='eng', config='--psm 6')
print("Output: " + text)

alexander sanchez diaz

Jan 8, 2020, 7:12:49 AM1/8/20
to tesseract-ocr
I have the same problem. Any Idea? Creating a new file with these parameters with False values and passing it (and absolute path) to pytesseract functions doesn't work!!!

Vuh doo

Mar 1, 2023, 12:58:45 PMMar 1
to tesseract-ocr
Even though it's 3 years later now, the disabling is possible with the -c flag.

pytesseract.image_to_string(roi, lang='eng', config='--psm 3 --oem 3 -c load_system_dawg=false -c load_freq_dawg=false -c 0tessedit_char_whitelist=0123456789r°:-abcdefghijklmnopqstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')

From the tesseract.exe
  -c VAR=VALUE          Set value for config variables.
                        Multiple -c arguments are allowed.
  --psm NUM             Specify page segmentation mode.
  --oem NUM             Specify OCR Engine mode.
NOTE: These options must occur before any configfile.

Page segmentation modes:
  0    Orientation and script detection (OSD) only.
  1    Automatic page segmentation with OSD.
  2    Automatic page segmentation, but no OSD, or OCR. (not implemented)
  3    Fully automatic page segmentation, but no OSD. (Default)
  4    Assume a single column of text of variable sizes.
  5    Assume a single uniform block of vertically aligned text.
  6    Assume a single uniform block of text.
  7    Treat the image as a single text line.
  8    Treat the image as a single word.
  9    Treat the image as a single word in a circle.
 10    Treat the image as a single character.
 11    Sparse text. Find as much text as possible in no particular order.
 12    Sparse text with OSD.
 13    Raw line. Treat the image as a single text line,
       bypassing hacks that are Tesseract-specific.

OCR Engine modes:
  0    Legacy engine only.
  1    Neural nets LSTM engine only.
  2    Legacy + LSTM engines.
  3    Default, based on what is available.
Reply all
Reply to author
0 new messages