This is a python implementation to recognize images with text in them. It uses OpenCV to detect text within natural scene images using the EAST text detector.
- Clone this repository and move to the main directory
git clone https://github.com/mmayank74567/detecting_images_with_text.git
cd detecting_images_with_text/
- Create a virtual environment. Install dependencies from the
requirements.txt
file using the followng command:
pip3 install -r requirements.txt
- EAST text detector requires to have OpenCV 3.4.2 or higher. To install OpenCV, run:
pip install opencv-python
The structure of the directory is represented below:
├── detecting_text
│ ├── __init__.py
│ └── detecting_text_in_images.py
├── model
│ └── frozen_east_text_detection.pb
├── output
├── sample
| ├── test1.jpg
| ├── test2.jpg
| ├── test3.jpg
| ├── test4.jpg
| ├── test5.jpg
| ├── test6.jpg
| └── test7.jpg
└── run.py
- The
detecting_text
package contains thedetecting_text_in_images.py
module. TheDetectingText
class of this module holds two methods, namely,non_max_suppression
andeast_detection
.
The east_detection
method implements the EAST text detector which is based on the paper EAST: An Efficient and Accurate Scene Text Detector. Since it is an end-to-end deep learning model, the EAST pipeline is highly efficiently as it sidesteps computationally draining sub-algorithms used by other text detectors. The method utilizes the EAST scene text detector model file that is stored in the model
folder to detect texts in images.
The non_max_suppression
method ignores the redundant and overlapping bounding boxes by utilizing non-maximum suppression.
- The
sample
folder contains a mix of natural scene images to demonstrate the implementation. Theoutput
folder stores the copy of images from thesample
folder that have text in them.
To run the run.py
script, execute the following command:
python run.py --model model/frozen_east_text_detection.pb --imagepath sample --output output
It parses three command line arguments
--model
: path to the model file--imagepath
: path to the folder of images--output
: path to the folder storing a copy of images with text in them--operation
:copy
to make copies of images with text in them in the output folder ormove
to move the images with text in them to the output folder (default =copy
)
As shown in image below, images with text in them are successfully detected and copied to the output folder.