MCPcopy
hub / github.com/lining0806/PythonSpiderNotes / image_file_to_string

Function image_file_to_string

Captcha1/pytesser_pro/pytesser_pro.py:40–57  ·  view source on GitHub ↗

Applies tesseract to filename; or, if image is incompatible and graceful_errors=True, converts to compatible format and then applies tesseract. Fetches resulting text. If cleanup=True, delete scratch files after operation.

(filename, cleanup = cleanup_scratch_flag, graceful_errors=True, bool_digits=False)

Source from the content-addressed store, hash-verified

38 return text
39
40def image_file_to_string(filename, cleanup = cleanup_scratch_flag, graceful_errors=True, bool_digits=False):
41 """Applies tesseract to filename; or, if image is incompatible and graceful_errors=True,
42 converts to compatible format and then applies tesseract. Fetches resulting text.
43 If cleanup=True, delete scratch files after operation."""
44 try:
45 try:
46 call_tesseract(filename, scratch_text_name_root, bool_digits)
47 text = util.retrieve_text(scratch_text_name_root)
48 except errors.Tesser_General_Exception:
49 if graceful_errors:
50 im = Image.open(filename)
51 text = image_to_string(im, cleanup, bool_digits)
52 else:
53 raise
54 finally:
55 if cleanup:
56 util.perform_cleanup(scratch_image_name, scratch_text_name_root)
57 return text

Callers 1

tess_test.pyFile · 0.85

Calls 2

call_tesseractFunction · 0.85
image_to_stringFunction · 0.85

Tested by

no test coverage detected