# `AxeraNPU.OCR`
[🔗](https://github.com/cocoa-xu/axera_npu/blob/v0.2.0/lib/axera_npu/ocr.ex#L1)

Finds and reads the lines of text in an image with PP-OCR models on the
NPU: a DB detector (`ch_PP_OCRv3_det` at 640 × 480) and a CTC recognizer
(`ch_PP_OCRv4_rec` at 320 × 48), with the recognizer's dictionary.

    {:ok, ocr} =
      AxeraNPU.OCR.load("ch_PP_OCRv3_det_npu.axmodel", "ch_PP_OCRv4_rec_npu.axmodel",
        "ppocr_keys_v1.txt")

    {:ok, lines} = AxeraNPU.OCR.read(ocr, rgb, 960, 540)
    Enum.map(lines, & &1.text)
    #=> ["NanoKVM-Go offline OCR on the NPU", "离线文字识别：神经网络处理器", ...]

Lines are axis-aligned boxes, which suits screens. A line wider than the
recognizer's input is read in pieces, cut between letters.

# `t`

```elixir
@type t() :: %AxeraNPU.OCR{ref: reference()}
```

# `load`

```elixir
@spec load(Path.t(), Path.t(), Path.t()) ::
  {:ok, t()} | {:error, File.posix() | String.t()}
```

Loads the detector and the recognizer onto the NPU, with the recognizer's
dictionary (one character per line).

# `load_binary`

```elixir
@spec load_binary(binary(), binary(), binary()) :: {:ok, t()} | {:error, String.t()}
```

Like `load/3`, from the files' contents.

# `read`

```elixir
@spec read(t(), struct()) :: {:ok, [AxeraNPU.OCR.Line.t()]} | {:error, atom()}
```

The lines of text in an RGB image as an Nx tensor of type `{:u, 8}` and
shape `{height, width, 3}`.

# `read`

```elixir
@spec read(t(), binary(), pos_integer(), pos_integer()) ::
  {:ok, [AxeraNPU.OCR.Line.t()]} | {:error, atom()}
```

The lines of text in an RGB image (`width × height × 3` bytes), top to
bottom and left to right.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
