Demo (YouTube): Text Finder in Images with Python
The initial reason for writing this program was that I was the network administrator of my department, and I had to conduct an asset inventory due to a change in department leadership.
Consequently, there were as many as 166 items to inventory. Therefore, each time I found an item and needed to attach a new sticker, I had to search for that item's sticker from all the asset stickers.
However, these stickers were not sorted according to any specific rule, so it took a long time to find the stickers each time. Thus, this program was designed to search for the location of an asset sticker in which image and at what position.
OCR Image Keyword Search is an efficient and user-friendly Python application that utilizes Optical Character Recognition (OCR) to search for user-specified keywords in a set of images. The application uses the Tesseract OCR engine and OpenCV for image processing, and stores OCR results for faster subsequent searches.
Before you begin, ensure you have met the following requirements:
-
Python 3.6 or later.
-
Tesseract OCR installed on your machine.
For Windows users, you can download the installer from the UB Mannheim Github page and follow the installation instructions.
For Mac users, you can install Tesseract using Homebrew:
brew install tesseract
For Linux users, you can install Tesseract using apt:
sudo apt install tesseract-ocr
-
Clone this repository to your local machine.
git clone https://github.com/xxrjun/text-finder-in-images.git
-
Set up a virtual environment (optional, but recommended):
python3 -m venv venv
-
Activate the virtual environment:
source venv/bin/activate
-
Install the required Python packages:
pip install -r requirements.txt
-
Place the images you want to search in the
./images
directory..jpg
file format is recommended. -
Modify the
main.py
file to set the path to the Tesseract OCR executable(in line 8):# TODO: Set the path to the Tesseract OCR executable pytesseract.pytesseract.tesseract_cmd = r'/opt/homebrew/bin/tesseract'
How to find the path to the Tesseract OCR executable: Tesseract documentation: Installation
-
Run the main script:
python main.py
-
When prompted, enter the keyword you want to search for. The program will search for the keyword in the images and display any images where the keyword is found. Press 'q' to close the image window and continue with the next image.
-
To exit the program, enter 'exit' when prompted for a keyword.