(ocr_integration)= # OCR integration ```{versionadded} 2.3 ``` To deal with images containing text, just [install Tesseract](https://tesseract-ocr.github.io/tessdoc/). Tesseract will be auto-detected by Tika or you can explicitly [set the path to tesseract binary](#ocr-path). Then add an image (png, jpg, …) into your FSCrawler {ref}`root-directory`. After the next index update, the text will be indexed and placed in `_source.content`. ## OCR settings Here is a list of OCR settings (under `fs.ocr` prefix): | Name | Environment Variable | Default value | Documentation | |-------------------------------------|-----------------------------------------------|-----------------|-------------------------------------------------------------------| | `fs.ocr.enabled` | `FSCRAWLER_FS_OCR_ENABLED` | `true` | [Disable/Enable OCR](#disableenable-ocr) | | `fs.ocr.language` | `FSCRAWLER_FS_OCR_LANGUAGE` | `"eng"` | [OCR Language](#ocr-language) | | `fs.ocr.path` | `FSCRAWLER_FS_OCR_PATH` | `null` | [OCR Path](#ocr-path) | | `fs.ocr.data_path` | `FSCRAWLER_FS_OCR_DATA_PATH` | `null` | [OCR Data Path](#ocr-data-path) | | `fs.ocr.output_type` | `FSCRAWLER_FS_OCR_OUTPUT_TYPE` | `txt` | [OCR Output Type](#ocr-output-type) | | `fs.ocr.pdf_strategy` | `FSCRAWLER_FS_OCR_PDF_STRATEGY` | `ocr_and_text` | [OCR PDF Strategy](#ocr-pdf-strategy) | | `fs.ocr.page_seg_mode` | `FSCRAWLER_FS_OCR_PAGE_SEG_MODE` | `01` | [OCR Page Seg Mode](#ocr-page-seg-mode) | | `fs.ocr.preserve_interword_spacing` | `FSCRAWLER_FS_OCR_PRESERVE_INTERWORD_SPACING` | `false` | [OCR Preserve Interword Spacing](#ocr-preserve-interword-spacing) | ## Disable/Enable OCR ```{versionadded} 2.7 ``` You can completely disable using OCR by setting `fs.ocr.enabled` property in your `~/.fscrawler/test/_settings.yaml` file: ```yaml name: "test" fs: url: "/path/to/data/dir" ocr: enabled: false ``` By default, OCR is activated if tesseract can be found on your system. ## OCR Language If you are using the default Docker image (see {ref}`docker`) or if you have installed any of the [Tesseract Languages](https://tesseract-ocr.github.io/tessdoc/Data-Files.html), you can use them when parsing your documents by setting `fs.ocr.language` property in your `~/.fscrawler/test/_settings.yaml` file: ```yaml name: "test" fs: url: "/path/to/data/dir" ocr: language: "eng" ``` ````{note} You can define multiple languages by using `+` sign as a separator: ```yaml name: "test" fs: url: "/path/to/data/dir" ocr: language: "eng+fas+fra" ``` ```` ## OCR Path If your Tesseract application is not available in default system PATH, you can define the path to use by setting `fs.ocr.path` property in your `~/.fscrawler/test/_settings.yaml` file: ```yaml name: "test" fs: url: "/path/to/data/dir" ocr: path: "/path/to/tesseract/bin/" ``` You can point `fs.ocr.path` either at the `tesseract` executable itself or at the directory that contains it: FSCrawler accepts both forms. When you set it, it’s highly recommended to set the [OCR Data Path](#ocr-data-path). ## OCR Data Path Set the path to the ‘tessdata’ folder, which contains language files and config files if Tesseract can not be automatically detected. You can define the path to use by setting `fs.ocr.data_path` property in your `~/.fscrawler/test/_settings.yaml` file: ```yaml name: "test" fs: url: "/path/to/data/dir" ocr: path: "/path/to/tesseract/bin/" data_path: "/path/to/tesseract/share/tessdata/" ``` ## OCR Output Type ```{versionadded} 2.5 ``` Set the output type from ocr process. `fs.ocr.output_type` property can be defined to `txt` or `hocr` in your `~/.fscrawler/test/_settings.yaml` file: ```yaml name: "test" fs: url: "/path/to/data/dir" ocr: output_type: "hocr" ``` ```{note} When omitted, `txt` value is used. ``` ## OCR PDF Strategy By default, FSCrawler will also try to extract also images from your PDF documents and run OCR on them. This can be a CPU intensive operation. If you don’t mean to run OCR on PDF but only on images, you can set `fs.ocr.pdf_strategy` to `"no_ocr"` or to `"auto"`: ```yaml name: "test" fs: ocr: pdf_strategy: "auto" ``` Supported strategies are: * `auto`: No OCR is performed on PDF documents if there is more than 10 characters extracted. See [PDFParser OCR Options](https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=109454066). * `no_ocr`: No OCR is performed on PDF documents. OCR might be performed on images though if OCR is not disabled. See [Disable/Enable OCR](#disableenable-ocr). * `ocr_only`: Only OCR is performed. * `ocr_and_text`: OCR and text extraction is performed. ```{note} When omitted, `ocr_and_text` value is used. If you have performance issues, it's worth using the `auto` option instead as only documents with barely no text will go through the OCR process. ``` ## OCR Page Seg Mode Set Tesseract to only run a subset of layout analysis and assume a certain form of image. The options for N are: * `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. * `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 Preserve Interword Spacing Spaces between the words will be deleted.