Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
/ndlocr-lite-gui/userconf.yaml
/ndlocr-lite-gui/debug.log
/ndlocr-lite-gui/4ab7ecc3-53fb-b3e7-64e8-a809b5a483d2/
/4ab7ecc3-53fb-b3e7-64e8-a809b5a483d2/
/4ab7ecc3-53fb-b3e7-64e8-a809b5a483d2/
2 changes: 1 addition & 1 deletion LICENCE
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,4 @@ understandings, or agreements concerning use of licensed material. For
the avoidance of doubt, this paragraph does not form part of the
public licenses.

Creative Commons may be contacted at creativecommons.org.
Creative Commons may be contacted at creativecommons.org.
51 changes: 28 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@ Windows(Windows 11)、Mac(Apple M4, macOS Sequoia)及びLinux(Ubuntu 22.04)環

本プログラムは、国立国会図書館がCC BY 4.0ライセンスで公開するものです。詳細については[LICENCE](./LICENCE)をご覧ください。なお、本アプリケーションの実行時に利用するライブラリ等のライセンスについては[LICENCE_DEPENDENCIES](./LICENCE_DEPENDENCEIES)をご覧ください。


## デスクトップアプリケーションによる利用

**デスクトップアプリケーションを利用する際には、日本語(全角文字)を含まないパスにアプリケーションを配置してください。全角文字を含む場合に起動しないことがあります。**

[releases](https://github.com/ndl-lab/ndlocr-lite/releases)からお使いのOS環境(Windows/Mac/Linux)に合ったファイルをダウンロードしてください。


デスクトップアプリケーションの操作方法については[NDLOCR-Liteの使い方](https://lab.ndl.go.jp/data_set/ndlocrlite-usage/)、ビルド方法については[デスクトップアプリケーションの利用方法](./ndlocr-lite-gui/README.md)を参照してください。


次のgifアニメーションは、

[国立国会図書館総務部総務課 編『国立国会図書館年報』昭和27年度,国立国会図書館,1954. 国立国会図書館デジタルコレクション https://dl.ndl.go.jp/pid/3048008"](https://dl.ndl.go.jp/pid/3048008/1/24)
Expand All @@ -32,80 +29,88 @@ Windows(Windows 11)、Mac(Apple M4, macOS Sequoia)及びLinux(Ubuntu 22.04)環
<img src="resource/demo_lite.gif" width="600">

## コマンドラインからの利用

※コマンドラインから操作を行うにはPython 3.10以上が必要です。

事前準備
```

```sh
git clone https://github.com/ndl-lab/ndlocr-lite
cd ndlocr-lite
pip install -r requirements.txt
cd src
```

実行例1.(同階層にある「9892834_0001」という名称のディレクトリ内の画像を一括処理し、tmpdirという名称のディレクトリに結果を出力する。)
```
python3 ocr.py --sourcedir 9892834_0001 --output tmpdir

```sh
python3 ocr.py --sourcedir 9892834_0001 --output tmpdir
```

実行例2.(同階層にある「digidepo_1287221_00000002.jpg」という名称の画像を処理し、tmpdirという名称のディレクトリに結果を出力する。)
```

```sh
python3 ocr.py --sourceimg digidepo_1287221_00000002.jpg --output tmpdir
```

uv(https://github.com/astral-sh/uv
)をお使いの環境であれば、以下のようにしても導入・実行可能です。この場合、「ndlocr-lite」というコマンドから実行できます。
[uv](https://github.com/astral-sh/uv)をお使いの環境であれば、以下のようにしても導入・実行可能です。この場合、「ndlocr-lite」というコマンドから実行できます。

導入方法
```

```sh
git clone https://github.com/ndl-lab/ndlocr-lite
cd ndlocr-lite
uv tool install .
```

実行例
```
ndlocr-lite --sourceimg digidepo_1287221_00000002.jpg --output tmpdir

```sh
ndlocr-lite --sourceimg digidepo_1287221_00000002.jpg --output tmpdir
```

### パラメータの説明

#### `--sourcedir`オプション

処理したい画像の含まれるディレクトリを絶対パスまたは相対パスで指定する。ディレクトリ内の"jpg(jpegも可)"、"png"、"tiff(tifも可)"、"jp2"及び"bmp"の拡張子のファイルを順次処理する。

#### `--sourceimg`オプション

処理したい画像を絶対パスまたは相対パスで直接指定する。"jpg(jpegも可)"、"png"、"tiff(tifも可)"、"jp2"及び"bmp"の拡張子のファイルを処理することが可能。

#### `--output`オプション

OCR結果を保存する出力先ディレクトリを相対パスまたは絶対パスで指定する。

#### `--viz`オプション

`--viz True`を指定することで、文字認識箇所を青枠で表示した画像を出力先ディレクトリに出力する。

#### `--device`オプション(ベータ)
対応GPUを搭載したサーバかつonnxruntime-gpuがインストールされている環境に限り、`--device cuda`を指定することでGPUを利用した処理に切り替える。

対応GPUを搭載したサーバかつonnxruntime-gpuがインストールされている環境に限り、`--device cuda`を指定することでGPUを利用した処理に切り替える。

## OCR結果の例

|資料画像|OCR結果の冒頭(誤認識を含む)|OCR結果のxml|
|---|---|---|
|<img src="./resource/viz_digidepo_2531162_0024.jpg" width="400"><br>国立国会図書館総務部 編『国立国会図書館スタッフ・マニュアル』E-2,国立国会図書館,1963.8. 国立国会図書館デジタルコレクション https://dl.ndl.go.jp/pid/2531162/1/23|(ヱ)気送子送付管気送子送付には、上記気送響にて送付するものと、空気の圧縮を使用せず,直接落下させる装置の二通りがある。後者の送付管は山納台左側に設置されており.5|[OCR結果(xmlファイル)](./resource/digidepo_2531162_0024.xml)|
|<img src="./resource/viz_digidepo_11048278_po_geppo1803_00021.jpg" width="400"><br> 館内スコープ 次世代室の謎に迫れ!. 国立国会図書館月報. 2018, (683),  p.20. http://dl.ndl.go.jp/info:ndljp/pid/11048278|はじめまして!私は2017年4月に就職後、次世代システム開発研究室(次世代室)という場所で仕事をしています。でも、「次世代室」って何をするところか想像しにくいですよね。次世代室は、図書館の役割がインターネット等の情報技術で変化する中、より先進的なサービスを検討していくために作られた比較的新しい部署です。|[OCR結果(xmlファイル)](./resource/digidepo_11048278_po_geppo1803_00021.xml)|
|<img src="./resource/viz_digidepo_3048008_0025.jpg" width="400"><br>国立国会図書館総務部総務課 編『国立国会図書館年報』昭和27年度,国立国会図書館,1954. 国立国会図書館デジタルコレクション https://dl.ndl.go.jp/pid/3048008/1/25|第8章職員、庁舍、財政、記念行事等1.職員A.司書職員の研修昭和26年度(第4回)研修に引続き、昭和27年度(第5回)司書職員研修を27年6月2日から28年4月10日まで320時間、研修生50名に実施した。本年度は、東京学芸大学の協力を得て、講師は、本館職員が専門分野の科目を担当した外、東京学芸大学の教授が担当した。本年度も單位科目ごとに試験を実施し、必修科目(11單位)選択科目(4單位)合わせて15單位以上の試験に合格した43名が修了した。|[OCR結果(xmlファイル)](./resource/digidepo_3048008_0025.xml)|

|<img src="./resource/viz_digidepo_2531162_0024.jpg" width="400"><br>国立国会図書館総務部 編『国立国会図書館スタッフ・マニュアル』E-2,国立国会図書館,1963.8. 国立国会図書館デジタルコレクション <https://dl.ndl.go.jp/pid/2531162/1/23>|(ヱ)気送子送付管気送子送付には、上記気送響にて送付するものと、空気の圧縮を使用せず,直接落下させる装置の二通りがある。後者の送付管は山納台左側に設置されており.5|[OCR結果(xmlファイル)](./resource/digidepo_2531162_0024.xml)|
|<img src="./resource/viz_digidepo_11048278_po_geppo1803_00021.jpg" width="400"><br> 館内スコープ 次世代室の謎に迫れ!. 国立国会図書館月報. 2018, (683),  p.20. <http://dl.ndl.go.jp/info:ndljp/pid/11048278>|はじめまして!私は2017年4月に就職後、次世代システム開発研究室(次世代室)という場所で仕事をしています。でも、「次世代室」って何をするところか想像しにくいですよね。次世代室は、図書館の役割がインターネット等の情報技術で変化する中、より先進的なサービスを検討していくために作られた比較的新しい部署です。|[OCR結果(xmlファイル)](./resource/digidepo_11048278_po_geppo1803_00021.xml)|
|<img src="./resource/viz_digidepo_3048008_0025.jpg" width="400"><br>国立国会図書館総務部総務課 編『国立国会図書館年報』昭和27年度,国立国会図書館,1954. 国立国会図書館デジタルコレクション <https://dl.ndl.go.jp/pid/3048008/1/25>|第8章職員、庁舍、財政、記念行事等1.職員A.司書職員の研修昭和26年度(第4回)研修に引続き、昭和27年度(第5回)司書職員研修を27年6月2日から28年4月10日まで320時間、研修生50名に実施した。本年度は、東京学芸大学の協力を得て、講師は、本館職員が専門分野の科目を担当した外、東京学芸大学の教授が担当した。本年度も單位科目ごとに試験を実施し、必修科目(11單位)選択科目(4單位)合わせて15單位以上の試験に合格した43名が修了した。|[OCR結果(xmlファイル)](./resource/digidepo_3048008_0025.xml)|

## モデルの再学習及びカスタマイズについて(開発者向け情報)
[学習及びモデル変換手順](/train/README.md)をご覧ください。

[学習及びモデル変換手順](/train/README.md)をご覧ください。

## 技術情報について(開発者向け情報)

NDLOCR-Liteは「レイアウト認識」、「文字列認識」、「読み順整序」の3つの機能(モジュール)を組み合わせて実現しています。

レイアウト認識にはDEIMv2[1]、文字列認識にはPARSeq[2]をそれぞれ用いており、読み順整序については当館が公開している[NDLOCR](https://github.com/ndl-lab/ndlocr_cli)と同様のモジュールを用いています。
レイアウト認識にはDEIMv2[1]、文字列認識にはPARSeq[2]をそれぞれ用いており、読み順整序については当館が公開している[NDLOCR](<https://github.com/ndl-lab/ndlocr_cli>)と同様のモジュールを用いています。

[1]Shihua Huang and Yongjie Hou and Longfei Liu and Xuanlong Yu and Xi Shen. Real-Time Object Detection Meets DINOv3. arXiv preprint arXiv:2509.20787, 2025.(https://arxiv.org/abs/2509.20787)
[1]Shihua Huang and Yongjie Hou and Longfei Liu and Xuanlong Yu and Xi Shen. Real-Time Object Detection Meets DINOv3. arXiv preprint arXiv:2509.20787, 2025.(<https://arxiv.org/abs/2509.20787>)

[2]Darwin Bautista, Rowel Atienza. Scene text recognition with permuted autoregressive sequence models. arXiv:2212.06966, 2022. (https://arxiv.org/abs/2207.06966)
[2]Darwin Bautista, Rowel Atienza. Scene text recognition with permuted autoregressive sequence models. arXiv:2212.06966, 2022. (<https://arxiv.org/abs/2207.06966>)

レイアウト認識及び文字列認識の機械学習モデルは、いずれもpytorchをフレームワークとした学習を行った後にONNX形式に変換して利用しています。詳しくは[学習及びモデル変換手順](/train/README.md)をご覧ください。


16 changes: 11 additions & 5 deletions ndlocr-lite-gui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
NDLOCR-Liteの使い方を説明します。

## 起動方法

お使いのOSに対応する圧縮ファイルを展開し、ndlocr_liteをダブルクリック等で実行してください。

なお、セキュリティに関する警告が出ることがあります。
Expand All @@ -11,13 +12,14 @@ Windows 11の場合は、「WindowsによってPCが保護されました」→

macOSの場合は、

https://zenn.dev/nakamura196/articles/c62a465537ff20
<https://zenn.dev/nakamura196/articles/c62a465537ff20>

の手順に従ってください。

なお、初回の起動には1分程度時間を要することがあります。お待ちください。

## 操作方法

①OCR処理をかけたいファイルまたはディレクトリを指定します。画像(jpg,png,tiff,bmp,jp2)に加えてPDFファイルに対する処理が可能です。

②出力先となるディレクトリを指定します。
Expand All @@ -27,14 +29,17 @@ https://zenn.dev/nakamura196/articles/c62a465537ff20
④ ディレクトリを指定した場合、OCR処理が完了した画像から処理結果のプレビューを表示できます。ファイルを指定した場合には当該ファイルの処理結果が表示されます。

## 自分でアプリケーションをビルドする場合の方法(開発者向け情報)

本アプリケーションは[Flet(外部サイト)](https://flet.dev/)を利用します。

いずれのOSの場合にも事前にFlutter-SDKの導入が必要です。依存関係のインストールに関する説明は省略します。

### Windowsの場合
https://flet.dev/docs/publish/windows/

<https://flet.dev/docs/publish/windows/>
も参照してください。
```

```sh
#(コマンドプロンプトを利用、ndlocr-lite-guiと同階層で実行する)
python3 -m venv ocrenv
.\ocrenv\Scripts\activate
Expand All @@ -45,7 +50,7 @@ flet build windows

### Macの場合

```
```sh
#(ndlocr-lite-guiと同階層で実行する)
python3 -m venv ocrenv
source ./ocrenv/bin/activate
Expand All @@ -55,7 +60,8 @@ flet build macos
```

### Linuxの場合
```

```sh
#(ndlkotenocr-lite-guiと同階層で実行する)
python3 -m venv ocrenv
source ./ocrenv/bin/activate
Expand Down
21 changes: 5 additions & 16 deletions ndlocr-lite-gui/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,11 @@ requires-python = ">=3.10"
authors = [
{ name = "National_Diet_Library", email = "lab@ndl.go.jp" }
]
dependencies = [
"flet==0.27.6",
"dill==0.3.8",
"lxml==5.4.0",
"networkx==3.3",
"onnxruntime==1.23.2",
"pillow==12.1.1",
"ordered-set==4.1.0",
"protobuf==6.31.1",
"pyparsing==3.1.2",
"PyYAML==6.0.1",
"tqdm==4.66.4",
"reportlab==4.2.5",
"pypdfium2==4.30.0",
"numpy==2.2.2"
]

dynamic = ["dependencies"]

[tool.setuptools.dynamic]
dependencies = { file = ["requirements.txt"] }

[tool.flet]
# org name in reverse domain name notation, e.g. "com.mycompany".
Expand Down
14 changes: 14 additions & 0 deletions ndlocr-lite-gui/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
flet==0.27.6
dill==0.3.8
lxml==5.4.0
networkx==3.3
onnxruntime==1.23.2
pillow==12.1.1
ordered-set==4.1.0
protobuf==6.31.1
pyparsing==3.1.2
PyYAML==6.0.1
tqdm==4.66.4
reportlab==4.2.5
pypdfium2==4.30.0
numpy==2.2.2
22 changes: 5 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,10 @@ version = "1.0.0"
description = "NDLOCR-Lite CLI Application"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
"flet==0.27.6",
"dill==0.3.8",
"lxml==5.4.0",
"networkx==3.3",
"onnxruntime==1.23.2",
"pillow==12.1.1",
"ordered-set==4.1.0",
"protobuf==6.31.1",
"pyparsing==3.1.2",
"PyYAML==6.0.1",
"tqdm==4.66.4",
"reportlab==4.2.5",
"pypdfium2==4.30.0",
"numpy==2.2.2"
]
dynamic = ["dependencies"]

[tool.setuptools.dynamic]
dependencies = { file = ["requirements.txt"] }

[project.scripts]
ndlocr-lite = "ocr:main"
Expand All @@ -37,4 +25,4 @@ where = ["src"]

[tool.setuptools.package-data]
"model" = ["*.onnx"]
"config" = ["*.yaml"]
"config" = ["*.yaml"]
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ PyYAML==6.0.1
tqdm==4.66.4
reportlab==4.2.5
pypdfium2==4.30.0
numpy==2.2.2
numpy==2.2.2
Loading