A C++ tool designed to detect and extract text regions from images using Deep Learning models (DBNet). The tool handles text detection, perspective warping, and binarization to prepare images for OCR.
- Text Detection: Uses ONNX Runtime with DBNet models.
- Geometry Processing: Merges fragmented detections using Stable Component Analysis.
- Image Warping: Unwarps perspective-distorted text regions.
- Binarization: Converts regions to black and white for better OCR accuracy.
- Auto-Cleaning: Automatically clears output directory before saving new results.
- CMake: Version 3.17 or higher.
- Compiler: C++17 compliant compiler (GCC, Clang, or MSVC).
- Internet: Required during the first build to download ONNX Runtime dependencies automatically.
- Clone the repository (if applicable).
- Create a build directory:
mkdir build cd build - Configure the project with CMake:
Note: This step will download the appropriate ONNX Runtime binaries for your platform (Linux/Windows).
cmake ..
- Build the executable:
make
./build/ocr_preprocessor <image_path> [model_path]<image_path>: Path to the input image file.[model_path]: (Optional) Path to the ONNX model file. Defaults todet_v5.onnx.
The default model det_v5.onnx uses a newer ONNX IR version (v10). The ONNX Runtime version used in this project supports up to IR version 9.
Please use the provided det_v5_ir9.onnx model.
./build/ocr_preprocessor test1.png det_v5_ir9.onnxThe tool is configured to always store output in the project root's output folder (ocp/output/), regardless of where you run the command from.
Directory Cleaning: The output/ directory is automatically cleaned (all files deleted) every time you run the tool to ensure you only see results from the latest run.