If you need OCR support in your application, I suggest you use the first party option by using the Text Recognition capabilities of Apple's Vision framework. If your language is not supported by Apple, I suggest you fork this project and maintain it yourself. If you need assistance migrating to another solution or in maintaining your own fork, you or your company can reach out to me to arrange a contract agreement.
This repo contains build scripts to compile Tesseract and it's dependencies for Apple platforms to be distributed as a Swift package. It's primary goal is to aid in migrating SwiftyTesseract to be consumable as a Swift Package Manager dependency. If you're looking for looking for a quick way to get started with using Tesseract in your Apple platform application without the rough edges of memory management and dealing with C interop, then you should start with SwiftyTesseract.
Add libtesseract as a Swift Package Dependency
// Package.swift
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "AwesomePackage",
platforms: [
// These are the minimum versions libtesseract supports
.macOS(.v10_13),
.iOS(.v11),
],
products: [
.library(
name: "AwesomePackage",
targets: ["AwesomePackage"]
),
],
dependencies: [
.package(url: "https://github.com/SwiftyTesseract/libtesseract.git", from: "0.2.0")
],
targets: [
.target(
name: "AwesomePackage",
dependencies: ["libtesseract"],
linkerSettings: [.linkedLibrary("z"), .linkedLibrary("c++")]
),
]
)
// AwesomePackage.swift
import libtesseract
You must link against the following libraries:
- libc++
- libz
This can be done in an Xcode-based project by adding these in Build Phases -> Link Binary with Libaries
In a Swift Package Manager project, this can be achieved by adding the following to your target linkerSettings
:
// See Package.swift example above for full context
targets: [
.target(
name: "AwesomePackage",
dependencies: ["libtesseract"],
linkerSettings: [.linkedLibrary("z"), .linkedLibrary("c++")]
),
]
See SwiftyTesseract's Additonal Configuration notes on considerations for including language training data files.
If you want to build libtesseract from source, you need automake
, pkg-config
, and task
installed on your machine. These can be installed via homebrew:
brew install automake pkg-config go-task/tap/go-task
To build a library for distribution run task build-tesseract-xcframework-zip
libtesseract disributes the following dependencies in binary form:
- Tesseract - License under the Apache v2 License
- Leptonica - Licensed under the BSD 2-Clause License
- libpng - Licensed under the Libpng License
- libjpeg - Licensed under the Libjpeg License
- libtiff - Licensed under the Libtiff License