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:
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
MangaOcralias 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.
- Normalize output for english.
Examples
Here are some examples showing the capability of the model.
Note: All the example images are picked randomly from Youtube videos and raw manga sites. The model has never seen these images before. Some images (especially the youtube ones) weren't even in the scope of this project, but the model is just that good at it.
| image | Result |
|---|---|
| 知らない世界で見つけたメージを | |
| カナデトモスソラ(Kanadetomosusora) | |
| 建設会社社員行方 | |
| だとしてもこのレベルがウロつくなんて...おそらく2級の呪い | |
| パチパチパチパチ | |
| バビュン | |
| 僕の過去とか未来とか | |
| くらべられっ子 | |
| そうだクラス分けがあるんだった!! | |
| 脇役よ、主役を超えよ! | |
| Eh~Idon'treallywantto~ | |
| 「Sorryforthewait!Didyouwaitlong?」 | |
| YamateAreaNewresidentialdistrictforforeigners |
Acknowledgments
This project is a fork of manga-ocr by kha-white.
Training data included:
- Manga109-s dataset
- jawildtext dataset
- AnimeText dataset
- Additional synthetic and cropped manga datasets
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hayai_ocr-0.2.3.tar.gz.
File metadata
- Download URL: hayai_ocr-0.2.3.tar.gz
- Upload date:
- Size: 864.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1265891bd066f4f1ce7137886318da883542353fa7a043eff4c1544a8ad3bb6
|
|
| MD5 |
601ac9104760ec3cb655f3e91620e68f
|
|
| BLAKE2b-256 |
bb024d166ce698ac7efe55e1f4862de8a582fa359dae0babff9ecb948c4f3db4
|
Provenance
The following attestation bundles were made for hayai_ocr-0.2.3.tar.gz:
Publisher:
publish-to-pypi.yml on NopeNopeGuy/hayai-ocr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hayai_ocr-0.2.3.tar.gz -
Subject digest:
d1265891bd066f4f1ce7137886318da883542353fa7a043eff4c1544a8ad3bb6 - Sigstore transparency entry: 1711770096
- Sigstore integration time:
-
Permalink:
NopeNopeGuy/hayai-ocr@51417d85fcffa5ccc624b0d6332dfa0dc214b185 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/NopeNopeGuy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@51417d85fcffa5ccc624b0d6332dfa0dc214b185 -
Trigger Event:
push
-
Statement type:
File details
Details for the file hayai_ocr-0.2.3-py3-none-any.whl.
File metadata
- Download URL: hayai_ocr-0.2.3-py3-none-any.whl
- Upload date:
- Size: 69.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2867e1c28e4e0037b14bd16cd6aa4d87483a2503ac2c715c395b5c6a3df906e0
|
|
| MD5 |
1a5e1d9974a75503fa5371610d0ea964
|
|
| BLAKE2b-256 |
34909189f04c106a621e60d686484f411a79458664a76fb109e6c8e7dbdc2c8b
|
Provenance
The following attestation bundles were made for hayai_ocr-0.2.3-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on NopeNopeGuy/hayai-ocr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hayai_ocr-0.2.3-py3-none-any.whl -
Subject digest:
2867e1c28e4e0037b14bd16cd6aa4d87483a2503ac2c715c395b5c6a3df906e0 - Sigstore transparency entry: 1711770145
- Sigstore integration time:
-
Permalink:
NopeNopeGuy/hayai-ocr@51417d85fcffa5ccc624b0d6332dfa0dc214b185 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/NopeNopeGuy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@51417d85fcffa5ccc624b0d6332dfa0dc214b185 -
Trigger Event:
push
-
Statement type: