22
33## Prerequisites
44
5- > #### Install Tesseract first {: .warning}
5+ > #### Install Tesseract first
66>
77> ` image_ocr ` is a NIF binding — it cannot start without ** Tesseract ≥ 5.0**
88> and Leptonica installed on the host running this Livebook. The first
99> ` Mix.install/2 ` cell below will fail to compile the NIF if these are
1010> missing.
1111>
12- > | Platform | One-liner |
13- > | --- | --- |
14- > | macOS | ` brew install tesseract leptonica pkg-config ` |
12+ > | Platform | One-liner |
13+ > | ---------------------- | ------------------------------------------------------------------------------------------------- --- |
14+ > | macOS | ` brew install tesseract leptonica pkg-config ` |
1515> | Debian / Ubuntu 24.04+ | ` sudo apt-get install -y build-essential pkg-config libtesseract-dev libleptonica-dev tesseract-ocr ` |
16- > | Fedora / RHEL | ` sudo dnf install -y gcc-c++ pkgconf-pkg-config tesseract-devel leptonica-devel ` |
17- > | Arch | ` sudo pacman -S base-devel pkgconf tesseract leptonica ` |
18- > | Alpine | ` apk add build-base pkgconf tesseract-ocr-dev leptonica-dev ` |
19- > | Windows | Use WSL2 with Ubuntu 24.04 and follow the Debian/Ubuntu row. |
16+ > | Fedora / RHEL | ` sudo dnf install -y gcc-c++ pkgconf-pkg-config tesseract-devel leptonica-devel ` |
17+ > | Arch | ` sudo pacman -S base-devel pkgconf tesseract leptonica ` |
18+ > | Alpine | ` apk add build-base pkgconf tesseract-ocr-dev leptonica-dev ` |
19+ > | Windows | Use WSL2 with Ubuntu 24.04 and follow the Debian/Ubuntu row. |
2020>
2121> Verify with ` tesseract --version ` and ` pkg-config --modversion tesseract `
2222> in your shell before continuing.
2323
2424``` elixir
2525Mix .install (
2626 [
27- {:image_ocr , path: Path . expand ( " .. " , __DIR__ ) },
27+ {:image_ocr , " ~> 0.1 " },
2828 {:image , " ~> 0.66" },
29- {:kino , " ~> 0.14" }
29+ {:kino , " ~> 0.14" },
30+ {:nx , " ~> 0.10" },
31+ {:exla , " ~> 0.10" }
3032 ]
3133)
3234```
@@ -49,7 +51,7 @@ easy to render text on a white background that Tesseract can read.
4951
5052``` elixir
5153render_text = fn string ->
52- Image .text! (string,
54+ Image .Text . text! (string,
5355 font_size: 48 ,
5456 text_fill_color: :black ,
5557 background_fill_color: :white ,
@@ -187,14 +189,13 @@ in-memory binaries, and live `Vix.Vips.Image` values transparently.
187189upload = Kino .Input .image (" Image to OCR" )
188190```
189191
190- ``` elixir
192+ ```` elixir
191193case Kino .Input .read (upload) do
192194 nil ->
193195 Kino .Markdown .new (" _Upload an image above and re-run this cell._" )
194196
195- %{file_ref: ref} ->
196- path = Kino .Input .file_path (ref)
197- {:ok , image} = Image .open (path)
197+ kino ->
198+ {:ok , image} = Image .from_kino (kino)
198199 {:ok , recognised} = Image .OCR .read_text (ocr, image)
199200
200201 Kino .Layout .grid (
@@ -206,7 +207,7 @@ case Kino.Input.read(upload) do
206207 columns: 1
207208 )
208209end
209- ```
210+ ````
210211
211212## 8. Tweaking accuracy with PSM and SetVariable
212213
0 commit comments