Text recognition (OCR)
What is text recognition?​
Text recognition (OCR, optical character recognition) reads the text it can find on your photos: receipts, letters, signs, screenshots, whiteboards, book pages. LibrePhotos stores that text with the photo, so you can search for it and select and copy it in the photo viewer. It also helps LibrePhotos tell documents apart from ordinary photos.
Text recognition is off on a new install. An administrator turns it on for the whole server, and then each user starts it for their own photos.
Privacy: what turning it on means​
When an administrator picks a model, LibrePhotos asks them to confirm, under the heading Text recognition reads everything:
Text recognition stores all readable text of every photo in the database as plain text. That includes documents, receipts, letters and IDs that happen to be in your library. Larger models are more accurate, but need more time and memory per photo.
Some things to know before you turn it on:
- The text stays on your server. The model runs locally, like every other model in LibrePhotos.
- The text is not encrypted. Anyone who can read your database or a database backup can read it.
- Only the owner of a photo sees its text. People you share a photo or an album with, and visitors of a public link, do not get it, and search only ever looks at your own photos.
- Turning it off again does not delete the text that was already read. See Turning it off again.
Turning it on​
An administrator turns text recognition on in Account menu > Admin area, under Site settings, with Text recognition (OCR) model:
| Model | Download | When to pick it |
|---|---|---|
| None | Text recognition is off. This is the default. | |
| PP-OCRv6 Tiny (fastest) | about 6 MB | Older or low-power machines, or when speed matters more than every word. |
| PP-OCRv6 Small | about 26 MB | A balance between speed and accuracy. |
| PP-OCRv6 Medium (most accurate) | about 100 MB | Small print and difficult photos, when the machine has memory and time to spare. |
Picking a model opens the confirmation described above. Cancel keeps the previous choice. After you click Save:
- A Download models job fetches the model if it is not on the server yet.
- The
ocrservice starts within about a minute, with no restart. You can see it under Services in the Admin area (see Service Management).
Nothing is read yet at this point. Each user starts the reading from their Library page, as described next.
Extracting text from your photos​
Open Account menu > Library. Under the Text Recognition heading is the Extract Text row:
- Extract reads the photos that have not been read yet. The first time, that is all of your photos. After that, it reads the photos still without text: new ones, and ones an earlier run could not read. New in 1.5.0 Up to 1.4.0, it read the photos added since the last run, so a photo that failed or whose thumbnail was not ready yet could be left out for good.
- The arrow next to Extract opens Extract text again for all photos, which reads every photo again, also the ones that already have text.
Both start an Extract text (OCR) job, which you can follow under Account menu > My jobs. It reads photos only, not videos. Each user runs it for their own photos, so on a shared server every user clicks Extract for themselves.
New in 1.5.0 While a model is selected, the job also starts by itself after a scan and a few minutes after an upload, for the photos still without text. Selecting a model therefore reads your whole library after the next scan or upload, a little at a time. Up to 1.4.0, it only ran when you clicked Extract.
A photo the text recognition service failed on three times is no longer read by these automatic runs. New in 1.7.0 Extract tries it again, and so does Extract text again for all photos. Up to 1.6.0, only Extract text again for all photos did. When the service could not be reached at all, that does not count as a failure. New in 1.7.0 A photo the service fails on is a warning in the log, not an error report, and the job's errors say what the service ran into (for example Failed to process image: MemoryError: ...); up to 1.6.0 they said only Failed to process image.
If the administrator changes the model later, Extract also reads again the photos that were read with the previous model.
Not released yet (comes after 1.7.0) Your photos are read with the model the administrator picked. Up to 1.7.0, PP-OCRv6 Small read them whichever model was picked, and when only another model was on the server, every photo failed. After the update, a server set to PP-OCRv6 Tiny or PP-OCRv6 Medium therefore reads its photos again with that model, after the next scan or upload or when you click Extract; photos that had failed three times are tried again, too. A job whose model is not on the server fails with "The text recognition model ... is not downloaded." instead of trying every photo.
Not released yet (comes after 1.7.0) Long lines of text are read in full. Up to 1.7.0, letters went missing in lines longer than about 20 characters, and more of them with the larger models.
Photos that were read before the update keep the text they have, also when its long lines are garbled. If you use text recognition since 1.7.0 or earlier with PP-OCRv6 Small, open the arrow next to Extract and choose Extract text again for all photos once after the update. With Tiny or Medium selected, the photos are read again by themselves, as described above.
How long it takes depends on the machine and on how much text a photo holds. On a desktop processor with four threads, a photo with a few lines took about half a second with Tiny, one second with Small and five seconds with Medium, and a full page of text about one, three and twelve seconds. A page of small print, 32 lines across its whole width, took about 3, 7 and 30 seconds. The ocr service used up to about 400 MB, 550 MB and 950 MB of memory, also for that page.
Not released yet (comes after 1.7.0) A page with more text than the service reads in half a minute is read in several steps, so a dense page does not run into the time limit of a photo (three minutes) on a slow server. If the photo is rotated or its file is changed between two steps, the page is started over, up to three times; after that it counts as a failure of the photo. Cancelling the job also stops it between two steps of a page.
When no model is selected, the buttons are disabled. Administrators then see "Choose a text recognition model in the admin area to enable this.", and other users see "Text recognition is turned off on this server. Ask your administrator to choose a text recognition model."
Searching for text​
Once a photo's text has been read, a normal search also looks at that text. Searching invoice or Main Street finds the receipt or the street sign that shows those words, together with the photos that match by caption, place, person and so on. See Text Search.
On PostgreSQL (the Docker setups) the text is matched word by word. On SQLite (the Windows app and the single container's internal database) any photo whose text contains your search term matches, also in the middle of a word.
Selecting text in the photo viewer​
When LibrePhotos found text on one of your photos, the photo viewer shows an extra toolbar button, Select text in photo (T). Click it, or press t, and the recognised text is laid over the photo, so you can select it with the mouse and copy it like text on a web page. Press t again, or click Stop selecting text (T), to go back to the plain photo.
The button only appears on your own photos, and only when text was found on them.
Documents​
LibrePhotos uses the recognised text, together with the things it sees in the photo (the same labels as the Things albums), to find documents: receipts, letters, forms and book pages. A photo is marked as a Document when it shows a thing such as a receipt, an invoice or a book page, or when two hints come together, for example a lot of text, an amount next to a word like "total", or a thing such as a menu or a whiteboard. The Extract text (OCR) job checks this for every photo it reads. You can then hide documents from the timeline with the Filter button (see Filtering the timeline), browse them on the Documents page, or pick Documents only with the media button of a list such as Favorites or an album.
Without text recognition, LibrePhotos has nothing to go on and no photo is detected as a document. You can still mark photos as documents yourself, see Category.
Turning it off again​
Set Text recognition (OCR) model back to None. The ocr service stops being started within about a minute, and Extract is disabled for everyone.
This only stops reading new text. Not released yet (comes after 1.7.0) Text that a job is reading at that moment is not stored either. The text that was already read stays in the database, and search keeps finding it. If you turned text recognition off for privacy reasons, keep this in mind. LibrePhotos has no button to delete the stored text yet.
For the other switches that live in Site settings rather than in environment variables, see Feature Toggles.