Copilot instructions
.github/copilot-instructions.mdCopilot instructions
Quality
89/100
Scores the file, not the repository.Length
1,493 words
48 headings · 19 code blocksRepository
76k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# Tesseract OCR - GitHub Copilot Instructions23## Repository Overview45Tesseract is an open-source **OCR (Optical Character Recognition) engine** that recognizes text from images. This repository contains:67- **libtesseract**: C++ OCR library with C API wrapper8- **tesseract**: Command-line OCR program9- **Training tools**: For creating custom language models1011**Key Facts:**12- Primary language: **C++17** (requires C++17-compliant compiler)13- Size: Large (~100MB+ with submodules)14- License: Apache 2.015- Maintained by: Stefan Weil (lead), Zdenko Podobny (maintainer)1617## Build Systems1819Tesseract supports **two build systems**. Both are actively maintained and tested in CI.2021### 1. Autotools (Traditional, POSIX Systems)2223**When to use:** Linux, macOS (command-line), MSYS2 on Windows2425**Build sequence:**26```bash27./autogen.sh # Generate configure script (only needed after git clone)28./configure # Configure build (creates Makefiles)29make # Build library and CLI30sudo make install # Install to system31sudo ldconfig # Update library cache (Linux only)32make training # Build training tools (optional)33sudo make training-install # Install training tools34```3536**Important:**37- ALWAYS run `./autogen.sh` first if building from git clone38- Use `make -j N` for parallel builds (N = number of CPU cores)39- Check `configure --help` for build options40- To clean: `make clean` or `make distclean` (complete cleanup)4142### 2. CMake (Modern, Cross-platform)4344**When to use:** Windows (MSVC, MinGW), cross-platform, modern development4546**Build sequence:**47```bash48mkdir build # MUST use out-of-source build49cd build50cmake .. # Configure (add options here)51make # Or: cmake --build .52sudo make install # Install to system53```5455**Important CMake options:**56- `BUILD_TRAINING_TOOLS=ON` - Enable training tools build57- `CMAKE_BUILD_TYPE=Release` - Release build (default is RelWithDebInfo)58- `GRAPHICS_DISABLED=ON` - Disable ScrollView (GUI debugger)59- `ENABLE_NATIVE=OFF` - Disable CPU-specific optimizations (for portability)6061**CMake enforces out-of-source builds** - you cannot build in the source directory. If you get an error about this, remove `CMakeCache.txt` and build in a separate directory.6263## Dependencies6465### Core Required Dependencies6667- **Leptonica 1.74.2+** (REQUIRED) - Image I/O library68 - Without this, build will fail69 - Usually installed via package manager: `libleptonica-dev` (Ubuntu) or `leptonica` (Homebrew)7071- **C++17 compiler:**72 - GCC 7+, Clang 5+, MSVC 2017+73 - Verified compilers: gcc-11, gcc-12, gcc-14, clang-15, clang++7475### Training Tools Dependencies7677Only needed if building training tools (`make training` or `-DBUILD_TRAINING_TOOLS=ON`):7879- pango-devel / libpango1.0-dev80- cairo-devel81- icu-devel8283### Optional Dependencies8485- **libarchive-dev**, **libcurl4-openssl-dev** - For advanced features86- **OpenMP** - For parallel processing (enabled by default if available)87- **cabextract** - For testing with CAB archives8889### Traineddata Files9091Tesseract requires **traineddata files** to function. Minimum required:92- `eng.traineddata` (English)93- `osd.traineddata` (Orientation and Script Detection)9495**Installation:**96```bash97# Download individual files (to /usr/local/share/tessdata/ or your TESSDATA_PREFIX path)98cd /usr/local/share/tessdata/ # Or wherever you want to install99wget https://github.com/tesseract-ocr/tessdata/raw/main/eng.traineddata100wget https://github.com/tesseract-ocr/tessdata/raw/main/osd.traineddata101102# Or clone all languages (WARNING: 1.2+ GB)103git clone https://github.com/tesseract-ocr/tessdata.git104```105106**Set environment variable:**107```bash108export TESSDATA_PREFIX=/usr/local/share/tessdata/109```110111Verify with: `tesseract --list-langs`112113## Testing114115### Running Unit Tests116117**With autotools:**118```bash119./autogen.sh120./configure121make122make check # Runs all unit tests123```124125**With CMake:**126```bash127mkdir build && cd build128cmake ..129make130ctest # Or: cmake --build . --target test131```132133**Important:**134- Tests require `googletest` submodule: `git submodule update --init --recursive`135- Tests require tessdata files (eng, osd minimum)136- Test results in `test-suite.log` (autotools) or CTest output (CMake)137138### Running Tesseract CLI139140Basic test commands:141```bash142# After installation:143tesseract --version144tesseract --list-langs145tesseract input.png output # OCR image, creates output.txt146tesseract input.png output pdf # Create searchable PDF147```148149Test files available in `test/testing/` (requires test submodule):150- `phototest.tif` - English test image151- `devatest.png` - Hindi/Devanagari test image (different format intentional)152153## Project Structure154155### Source Code Layout156157```158src/159├── api/ # Public C/C++ API (baseapi.h, capi.h)160├── ccmain/ # Main OCR control logic161├── lstm/ # LSTM neural network engine (Tesseract 4+)162├── ccutil/, cutil/ # Core utilities, data structures163├── classify/ # Character classifier164├── dict/ # Dictionary and language model165├── textord/ # Text line and word detection166├── wordrec/ # Word recognition167├── training/ # Training tools (lstmtraining, text2image, etc.)168└── tesseract.cpp # CLI main() entry point169170include/tesseract/ # Public header files171unittest/ # Unit tests (requires googletest)172test/testing/ # Test images and data173tessdata/ # Default location for traineddata files174doc/ # Documentation175```176177### Key Files178179- **src/api/baseapi.h** - Main C++ API class (`TessBaseAPI`)180- **src/api/capi.h** - C wrapper API181- **src/tesseract.cpp** - Command-line tool182- **CMakeLists.txt**, **configure.ac**, **Makefile.am** - Build configuration183- **VERSION** - Current version string184185### Configuration Files186187- **.clang-format** - Code formatting rules (LLVM style)188- **tesseract.pc.in** - pkg-config template189- **.github/workflows/** - CI/CD definitions190191## CI/CD Workflows192193### Active Workflows1941951. **cmake.yml** - CMake builds on Ubuntu/macOS, 6 configurations1962. **autotools.yml** - Autotools builds, comprehensive testing1973. **unittest.yml** - Unit tests with sanitizers (ASAN, UBSAN)1984. **codeql-analysis.yml** - Security static analysis1995. **vcpkg.yml**, **msys2.yml**, **cmake-win64.yml** - Windows builds200201### Validation Requirements202203All PRs trigger:204- **Build tests** on multiple platforms (Ubuntu 22.04, 24.04, macOS 14, 15)205- **Compiler tests** (GCC 11-14, Clang 15)206- **Unit tests** with sanitizers207- **CodeQL** security scan208209**Expect ~10-30 minutes** for full CI validation.210211### Common CI Failures212213- **Missing dependencies:** Check workflow files for required packages214- **Test failures:** Often due to missing tessdata files215- **Sanitizer errors:** Memory leaks, undefined behavior216- **CodeQL alerts:** Security vulnerabilities in code217218## Common Build Issues & Workarounds219220### Issue: "configure: error: Leptonica not found"221**Solution:** Install leptonica development package222```bash223# Ubuntu/Debian:224sudo apt-get install libleptonica-dev225# macOS:226brew install leptonica227```228229### Issue: "CMake Error: cannot build in source directory"230**Solution:** CMake requires out-of-source builds231```bash232rm -f CMakeCache.txt233mkdir build && cd build && cmake ..234```235236### Issue: "make check" fails with "cannot find tessdata"237**Solution:** Set TESSDATA_PREFIX or download files238```bash239export TESSDATA_PREFIX=/usr/local/share/tessdata/240# Or copy files to /usr/local/share/tessdata/241```242243### Issue: Submodule errors (googletest, test)244**Solution:** Initialize submodules245```bash246git submodule update --init --recursive247```248249### Issue: Old Tesseract version conflicts250**Solution:** Remove previous installation before building251```bash252# Find installed files:253which tesseract254pkg-config --modversion tesseract255# Uninstall old version, then rebuild256```257258### Issue: Training tools not building259**Solution:** Install pango, cairo, icu dependencies260```bash261sudo apt-get install libpango1.0-dev libcairo2-dev libicu-dev262```263264## Validation Steps for Code Changes265266When making code changes, follow these steps:2672681. **Build the project** (choose one):269```bash270 # Autotools:271 ./autogen.sh && ./configure && make272 # CMake:273 mkdir build && cd build && cmake .. && make274```2752762. **Run unit tests**:277```bash278 # Autotools:279 make check280 # CMake:281 ctest282```2832843. **Test CLI manually**:285```bash286 tesseract test/testing/phototest.tif output287 cat output.txt # Verify OCR output288```2892904. **Check for memory issues** (if modifying C++ code):291```bash292 # Build with sanitizers:293 CXXFLAGS="-g -O2 -fsanitize=address,undefined" ./configure294 make && make check295```2962975. **Run CodeQL** (security check):298 - Will run automatically in CI299 - Or use GitHub Code Scanning locally3003016. **Verify documentation** (if API changes):302 - Update header comments in `include/tesseract/`303 - Update relevant docs in `doc/`304305## Code Style & Conventions306307- **Formatting:** Use clang-format with `.clang-format` config (LLVM style)308- **Naming:**309 - Classes: `CamelCase` (e.g., `TessBaseAPI`)310 - Functions: `CamelCase` (e.g., `ProcessPage`)311 - Variables: `snake_case` or `lower_case`312- **Headers:** Use include guards, document public APIs313- **Comments:** Focus on "why", not "what"314- **Commits:** Use meaningful messages, reference issue numbers315316## Important Notes for AI Coding Agents3173181. **Always use out-of-source builds with CMake** - in-source builds are blocked3192. **Check for Leptonica** before building - it's a hard requirement3203. **Initialize git submodules** before running tests3214. **Set TESSDATA_PREFIX** or tests will fail3225. **Building takes time** - allow 2-5 minutes for full build3236. **Testing takes time** - `make check` can take 5-10 minutes3247. **Don't remove existing tests** - they're critical for preventing regressions3258. **Check CI workflows** for platform-specific requirements3269. **Sanitizer builds are slower** - 2-3x slower than normal builds32710. **Training tools are optional** - only build if needed for the task328329## Useful Commands Reference330331```bash332# Quick build and test (autotools):333./autogen.sh && ./configure && make -j8 && make check334335# Quick build and test (CMake):336mkdir build && cd build && cmake .. && make -j8 && ctest337338# Format code:339find src -name '*.cpp' -o -name '*.h' | xargs clang-format -i340341# Check test results:342cat test-suite.log # autotools343ctest --output-on-failure # CMake344345# Install only library (no training):346make install # After ./configure && make347348# Clean builds:349make clean # Partial clean350make distclean # Complete clean (autotools)351rm -rf build # Complete clean (CMake)352353# Check installed version:354tesseract --version355pkg-config --modversion tesseract356357# Debug OCR on specific image:358tesseract input.png output -l eng --psm 6 -c debug_file=/dev/null359```360361---362363**Trust these instructions.** Only search for additional information if these instructions are incomplete, outdated, or if you encounter an error not covered here. The workflows and build procedures are tested daily in CI and represent current best practices for this repository.364
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| pytorch/pytorch.github/copilot-instructions.md · 102k | Copilot instructions | setupbuildteststyle+5 | 100/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.github/instructions/global.instructions.md · 63 | Copilot instructions | buildlint-formatstylearch+4 | 100/100 | 3 days ago | |
| louislam/uptime-kuma.github/copilot-instructions.md · 90k | Copilot instructions | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| dotnet/roslyn.github/instructions/Compiler.instructions.md · 21k | Copilot instructions | buildteststylearch+3 | 99/100 | 3 days ago | |
| hiyouga/LlamaFactory.github/copilot-instructions.md · 74k | Copilot instructions | setupbuildtestlint-format+5 | 97/100 | 2 days ago | |
| JCodesMore/ai-website-cloner-template.github/copilot-instructions.md · 31k | Copilot instructions | buildlint-formatstylearch+3 | 97/100 | 2 days ago | |
| rtk-ai/rtk.github/copilot-instructions.md · 74k | Copilot instructions | buildtestlint-formatstyle+2 | 97/100 | 3 days ago | |
| dotnet/roslyn.github/copilot-instructions.md · 21k | Copilot instructions | buildteststylearch+3 | 97/100 | 3 days ago |
