docling-project / docling-project/docling

TesseractOcrModel code not checking the languages in the correct place

Open
#2,050 3 comments 1 reaction 0 assignees View on GitHub
bug triage/close-stale
Dominant language
Python
Stars
66.4k
Forks
4.8k
Avg merge
2d 21h
Merged PRs (30d)
84

Description

### Bug

Trying to use tesseract with TesseractOcrOptions(path="path_to_tessdata") leads to:

```log
ImportError: tesserocr is not correctly configured. No language models have been detected. Please ensure that the TESSDATA_PREFIX envvar points to tesseract languages dir.
```

Despite having all needed files in `path_to_tessdata`

From the tesserocr doc: _point to the tessdata path if it cannot be detected automatically. This can be done by setting the TESSDATA_PREFIX environment variable or by passing the path to PyTessBaseAPI_

With TesseractOcrOptions(path="path_to_tessdata"), we should be able to have TESSDATA_PREFIX unset

`[Here](https://github.com/docling-project/docling/blob/main/docling/models/tesseract_ocr_model.py#L75)` there is:

` _, self._tesserocr_languages = tesserocr.get_languages()`

that will load the languages from TESSDATA_PREFIX instead of the provided path

We need

```python
if self.options.path is not None:
_, self._tesserocr_languages = tesserocr.get_languages(path=self.options.path)
else:
_, self._tesserocr_languages = tesserocr.get_languages()`
```

(I can submit a PR)

### Steps to reproduce

```python
pipeline_options = PdfPipelineOptions()
pipeline_options.do_ocr = True
tesseract_options = TesseractOcrOptions(path="path_to_tessdata")

pipeline_options.ocr_options = tesseract_options
doc_converter = DocumentConverter(format_options={
InputFormat.PDF: PdfFormatOption(
pipeline_options=pipeline_options,
pipeline_cls=StandardPdfPipeline, backend=DoclingParseV4DocumentBackend)
})
doc_converter.convert(source)

# ImportError: tesserocr is not correctly configured. No language models have been detected. Please ensure that the TESSDATA_PREFIX envvar points to tesseract languages dir. But having all needed files in path_to_tessdata

```

### Docling version

2.43.0

### Python version

3.9.18

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.