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)
| 38 | return text |
| 39 | |
| 40 | def 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 |
no test coverage detected