Skip to main content

Fast OCR for Japanese manga (fork of manga-ocr)

Project description

Hayai OCR (速いOCR)

Fast optical character recognition for Japanese text, with the main focus being Japanese manga. A fork of manga-ocr by kha-white, rebuilt with a SigLIP2 + BERT encoder-decoder architecture for improved accuracy and speed.

It uses a custom end-to-end model built with Transformers' Vision Encoder Decoder framework, pairing a SigLIP2 NaFlex vision encoder with a Japanese BERT character-level decoder.

Hayai OCR can be used as a general purpose printed Japanese OCR, but its main goal is to provide high quality text recognition, robust against various scenarios specific to manga:

  • both vertical and horizontal text
  • text with furigana
  • text overlaid on images
  • wide variety of fonts and font styles
  • low quality images

Unlike many OCR models, Hayai OCR supports recognizing multi-line text in a single forward pass, so that text bubbles found in manga can be processed at once, without splitting them into lines.

See also:

  • Poricom, a GUI reader
  • mokuro, a tool for generating HTML overlays for manga

Installation

You need Python 3.9 or newer. Please note that the newest Python release might not be supported due to a PyTorch dependency, which often breaks with new Python releases and needs some time to catch up. Refer to PyTorch website for a list of supported Python versions.

If you want to run with GPU, install PyTorch as described here, otherwise this step can be skipped.

pip install hayai-ocr

Usage

Python API

from hayai_ocr import HayaiOcr

mocr = HayaiOcr()
text = mocr('/path/to/img')

or

import PIL.Image
from hayai_ocr import HayaiOcr

mocr = HayaiOcr()
img = PIL.Image.open('/path/to/img')
text = mocr(img)

Note: The backwards-compatible MangaOcr alias is still available:

from hayai_ocr import MangaOcr
mocr = MangaOcr()

Running in the background

Hayai OCR can run in the background and process new images as they appear.

You might use a tool like ShareX or Flameshot to manually capture a region of the screen and let the OCR read it either from the system clipboard, or a specified directory. By default, Hayai OCR will write recognized text to clipboard, from which it can be read by a dictionary like Yomitan.

Clipboard mode on Linux requires wl-copy for Wayland sessions or xclip for X11 sessions. You can find out which one your system needs by running echo $XDG_SESSION_TYPE in the terminal.

Your full setup for reading manga in Japanese with a dictionary might look like this:

capture region with ShareX -> write image to clipboard -> Hayai OCR -> write text to clipboard -> Yomitan

  • To read images from clipboard and write recognized texts to clipboard, run in command line:
    hayai_ocr
    
  • To read images from ShareX's screenshot folder, run in command line:
    hayai_ocr "/path/to/sharex/screenshot/folder"
    

Note that when running in the clipboard scanning mode, any image that you copy to clipboard will be processed by OCR and replaced by recognized text. If you want to be able to copy and paste images as usual, you should use the folder scanning mode instead and define a separate task in ShareX just for OCR, which saves screenshots to some folder without copying them to clipboard.

When running for the first time, downloading the model might take a few minutes. The OCR is ready to use after OCR ready message appears in the logs.

  • To see other options, run in command line:
    hayai_ocr --help
    

If hayai_ocr doesn't work, you might also try replacing it with python -m hayai_ocr.

Usage tips

  • OCR supports multi-line text, but the longer the text, the more likely some errors are to occur. If the recognition failed for some part of a longer text, you might try to run it on a smaller portion of the image.
  • The model was trained specifically to handle manga, visual novel, general anime and handwritten Japanese texts. It should perform well everywhere.
  • The model always attempts to recognize some text on the image, even if there is none. Because it uses a transformer decoder (and therefore has some understanding of the Japanese language), it might even "dream up" some realistically looking sentences! This shouldn't be a problem for most use cases.

Examples

Here are some cherry-picked examples showing the capability of the model.

image Result
素直にあやまるしか
立川で見た〝穴〟の下の巨大な眼は:
実戦剣術も一流です
第30話重苦しい闇の奥で静かに呼吸づきながら
よかったじゃないわよ!何逃げてるのよ!!早くあいつを退治してよ!
ぎゃっ
ピンポーーン
LINK!私達7人の力でガノンの塔の結界をやぶります
ファイアパンチ
少し黙っている
わかるかな〜?
警察にも先生にも町中の人達に!!

Acknowledgments

This project is a fork of manga-ocr by kha-white.

Training data included:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hayai_ocr-0.1.0.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hayai_ocr-0.1.0-py3-none-any.whl (69.7 kB view details)

Uploaded Python 3

File details

Details for the file hayai_ocr-0.1.0.tar.gz.

File metadata

  • Download URL: hayai_ocr-0.1.0.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hayai_ocr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dbdc191e0a96c45c0590f41c5678848d027f00c04d40c1132f6c0bf0cecfc0f3
MD5 f4dbe9e193cb2bbdb5959cb7f7960073
BLAKE2b-256 46f43bf055304459d6e8faab2d0cdae71217549914826aee436cae5219cdf91f

See more details on using hashes here.

Provenance

The following attestation bundles were made for hayai_ocr-0.1.0.tar.gz:

Publisher: publish-to-pypi.yml on NopeNopeGuy/hayai-ocr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hayai_ocr-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hayai_ocr-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 69.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hayai_ocr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a6ac0cc864c43d68f8c9de7798a5570ecf32efd65ede78590771bd0f5fa12052
MD5 c703a70ce331c7fe41dbad51e57b0f35
BLAKE2b-256 0d4b94b1ce1bf00e953e180023c75ee12d77ae55b6ed2ec392c417371dbdf258

See more details on using hashes here.

Provenance

The following attestation bundles were made for hayai_ocr-0.1.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on NopeNopeGuy/hayai-ocr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page