Is it possible to search through text in images in emacs?

I have searched for a tool, but i could not find anything. I want to scan all my documents and then search the images with emacs to find my document.

For example: i scan a documnent, which shows "hello world", then i want to find this image, when searching in a folder full of images with that image in the folder.

1 Answer 1


You need to wire up an optical character recognition program (e.g. https://github.com/tesseract-ocr/tesseract) to read the text from images, and then couple that with a search tool.

See https://kitchingroup.cheme.cmu.edu/blog/2015/07/24/Indexing-text-in-screenshots-so-they-are-searchable/ for an example of how it might work.

If you have a lot of images, I guess you would want to cache the results somehow, so you don't have to find all the images, then do OCR, then search each time.

Here is a proof of concept that is lightly tested. This finds images (png and jpg) in the current directory (and below), runs each one through tesseract and captures the string, and then uses completion to search (I use ivy, which makes it pretty easy), then opens the image you select.

(require 'f)

(let* ((candidates (cl-loop for f in  (f-files "." (lambda (f)
                             (member (file-name-extension f)
                                 '("png" "jpg")))
                (cons (shell-command-to-string
                   (format "tesseract %s -" f))
       (choice (completing-read "Query: " candidates)))
  (find-file (cdr (assoc choice candidates))))

I would not use this on your file system, it would probably take a long time to do that. Instead, you would want to save the strings to some intermediate database, and then search the database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.