Leptonica: the C image processing library behind Tesseract OCR
Leptonica is an open source library containing software that is broadly useful for image processing and image analysis applications. The official github repository for Leptonica is: danbloomberg/leptonica. See leptonica.org for more documentation.
At a glance
- What is it?
- Leptonica is a C library for document and natural image analysis, covering rasterop, affine transforms, morphology, adaptive binarization, and I/O for ten standard formats. Tesseract OCR and OpenCV both depend on it, and the vcpkg port is the documented install path.
- Who is it for?
- Leptonica suits projects that need low-level image analysis in C, particularly document tasks such as skew correction, adaptive binarization, page segmentation, and PDF or Postscript generation. Any project that already links against tesseract has it as a transitive dependency.
- Can I use it commercially?
- Check first. The repository uses a licence we do not classify automatically, so read its LICENSE file before any commercial use.
- Is it still maintained?
- Yes. The repository last received commits 9 days ago.
- What is it written in?
- Mainly C, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on October 11, 2026, and from our analysis. They are not legal advice.
Editorial analysis
Tesseract OCR, OpenCV, and jbig2enc all depend on Leptonica
Leptonica is an open source C library for image processing and image analysis, covering both document images, such as scanned text pages, and natural images such as photographs. The distinction between those two categories is meaningful: document processing tasks like skew detection, binarization, and layout segmentation have different requirements from real-time computer vision, and Leptonica's feature set reflects a document-analysis origin.
Three projects in the open source ecosystem list it as a dependency. Tesseract, the OCR engine, uses Leptonica for image preparation before character recognition. OpenCV includes it alongside its own image processing stack. jbig2enc, which encodes multipage binary image documents with jbig2 compression, relies on it for binary image handling.
Several co-maintainers have worked on specific aspects of the library. Stefan Weil helped remove internal struct data from the public interface and implemented the atomic reference counting that makes the library thread-safe. Adam Korczynski contributed most of the open source fuzz testing infrastructure, covering significant code paths in the oss-fuzz project. The README credits these contributors alongside their specific contributions.
Rasterop plus three geometric transform families, and where they differ
Rasterop, also called bitblt, handles the core pixel copy and combine operations that most other functions build on. Above that base layer, geometric transforms come in three families with different properties. Affine operations include scaling, translation, rotation, and shear, and they work on images at any pixel depth from binary through deep color. Projective and bilinear transforms are separate families that handle perspective correction and smooth quadrilateral mappings respectively.
Morphology works in both binary and grayscale modes, with rank order filters and convolution available for operations that require neighborhood statistics. Seedfill and connected component analysis work on binary images to identify and label regions. Pixelwise masking, blending, enhancement, and arithmetic operations are listed as a separate group covering operations that work pixel-by-pixel rather than on neighborhoods.
Image data packs into 32-bit words, and operations use 32-bit arithmetic wherever the algorithm permits. This packing decision affects the memory layout and speeds up bitwise morphology operations, but it means Leptonica's internal Pix representation is not byte-aligned in the way that many imaging libraries assume, and interoperating with those libraries requires conversion.
Install via vcpkg in five commands on Linux, macOS, or Windows
The README documents vcpkg as the install path. The sequence works on Linux and macOS using the shell bootstrap script, and on Windows with PowerShell using bootstrap-vcpkg.bat in place of the .sh variant:
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install leptonicavcpkg's Leptonica port is jointly maintained by Microsoft and community contributors, and the README asks for issues or pull requests against the vcpkg repository if the port version falls behind the tagged release.
For source builds, the repository includes both CMake and autotools. CMakeLists.txt and cmake/ handle the CMake path. The autotools path uses autogen.sh, configure.ac, Makefile.am, and the m4/ directory. GitHub Actions runs three CI workflows: cmake on Linux, cmake-win64 on Windows, and autotools-macos on macOS. The repository also includes a prog/ directory described as many programs provided to test and show usage of the library's functions.
Document image pipeline: skew detection, adaptive binarization, segmentation, and PDF output
The document image capabilities form a pipeline from raw scan to structured output. Determination of skew and orientation of text images identifies how much a page deviates from horizontal. Location of baselines and local skew determination refines that picture at a line-by-line level rather than for the whole page at once.
Adaptive background normalization and binarization converts a grayscale scan to binary while compensating for uneven illumination across the page, which is the step tesseract relies on before running character recognition. Segmentation of page images with mixed text and images splits a page into text and non-text regions. Image dewarping based on content (textlines) corrects page curl or binding distortion by finding the textlines and using them as reference curves.
Output formats for documents include Postscript at levels 1, 2, and 3, and PDF with G4, DCT, and FLATE compression modes, described as device-independent output. A jbig2 unsupervised classifier is included for compressing multipage binary image documents. Border representations of 1 bpp images and raster conversion for SVG are also listed. These output capabilities make the library useful as a backend for document conversion, not only as an analysis tool.
pixa, boxa, and pta: the return types that most analysis functions use
Three array types appear throughout the Leptonica API. pixa is an array of pix image objects, boxa is an array of bounding boxes, and pta is an array of points. Most analysis operations return one of these types rather than a single scalar or image. A connected component analysis returns a boxa of bounding rectangles and a pixa of component images. Understanding these types is a prerequisite for reading any Leptonica code.
The library also includes general-purpose data structures beyond these image types: stacks, generic arrays, queues, heaps, doubly-linked lists, sets, ordered maps, hashmaps, number arrays, and string arrays. These are bundled as part of the library rather than separated into a utility package, so a project adopting Leptonica gets all of them as part of its dependency surface.
I/O is provided for jpg, png, tiff, webp, jp2, bmp, pnm, gif, ps, and pdf. That is ten format families in one library, which avoids adding separate format-specific dependencies for common image types. There is no video I/O, no camera capture, and no GPU-accelerated format decoding; Leptonica operates on images already in memory or on disk.
Over 2700 functions in ANSI C with exit() prohibited and oss-fuzz coverage
The public API has more than 2700 functions. Naming is consistent: each function name begins with the primary data structure it operates on, so pix_ functions work on Pix image objects, boxa_ functions work on box arrays, and so on throughout the API. Pointer checking is applied to all arguments, and exit() is absent from the library's error paths entirely, which means a failed image operation returns an error code to the caller rather than terminating the process. That design is what makes Leptonica safe to embed in a long-running application.
Over 140 regression tests cover basic functions and applications, and the library is tested with valgrind for memory errors. The oss-fuzz integration provides ongoing fuzz testing for the public API.
Portability is listed as an explicit design characteristic. Builds are confirmed on Linux, macOS, MinGW, Cygwin, and Windows. The library is endian-independent. Thread safety uses atomic operations for reference counting rather than global locks, so concurrent reads of the same image data are safe. API documentation comes from doxygen-generated output and additional background pages at www.leptonica.org.
The barcode reader is a very early version, the licence is not a standard identifier, and v1.87.0 is from December 2025
The barcode reader covers 1D barcodes and the README describes it as a very early version as of release 1.55. The current tagged release is 1.87.0, published on December 24, 2025, with the last push to the repository on October 2, 2026. That note about the barcode reader has not been revised as version numbers advanced. The library does not document 2D barcode support (QR codes, DataMatrix, or similar), and there is no machine learning-based recognition in the listed capabilities.
The licence is a custom text in leptonica-license.txt at the repository root. GitHub cannot classify it against a standard identifier, which means automated licence scanning tools may flag or leave it unresolved. Reading the file directly is necessary before using the library commercially.
OpenCV is the most commonly cited alternative for general computer vision. The difference in approach is scope and language surface: OpenCV provides Python, Java, and JavaScript bindings and is oriented toward real-time vision, while Leptonica is a C library with a document analysis focus and no higher-level language bindings in this repository. A project using tesseract already has Leptonica as a transitive dependency, so adding direct calls does not increase the dependency count.
Editorial conclusion
Leptonica suits projects that need low-level image analysis in C, particularly document tasks such as skew correction, adaptive binarization, page segmentation, and PDF or Postscript generation. Any project that already links against tesseract has it as a transitive dependency. Skip it if you need first-class Python or Java bindings without writing a C wrapper, or if you need GPU acceleration for real-time vision tasks; neither is provided. Before adopting, read leptonica-license.txt in the repository root, because GitHub cannot classify the licence and the terms matter for commercial use.
Frequently asked questions
What is Leptonica?
Leptonica is an open source C library for image processing and image analysis of document and natural images. It provides over 2700 functions covering morphology, geometric transforms, adaptive binarization, page segmentation, and I/O for ten standard image formats. Tesseract OCR depends on it.
How do I install Leptonica?
The README documents vcpkg as the install path: clone vcpkg, run bootstrap-vcpkg.sh, then run ./vcpkg integrate install and ./vcpkg install leptonica. For source builds, the repository includes both CMake and autotools build systems.
What licence does Leptonica use?
Leptonica uses a custom licence stored in leptonica-license.txt at the repository root. GitHub cannot classify it as a standard open source licence, so read that file before using the library in a commercial product.
What image formats does Leptonica support?
Leptonica provides I/O for jpg, png, tiff, webp, jp2, bmp, pnm, gif, ps, and pdf. There is no video I/O or camera capture.
What is the difference between Leptonica and OpenCV?
OpenCV targets real-time computer vision and provides Python, Java, and JavaScript bindings, while Leptonica is a C library oriented toward document image analysis. OpenCV is broader in scope; Leptonica goes deeper on document-specific tasks such as skew correction, adaptive binarization, and page segmentation.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/danbloomberg-leptonica)