Tesseract OCR 5.3.3 の開発環境とツール等のインストールと動作確認(多言語の文字認識)(Windows 上)
このページでは,Alpaca.cpp のインストールと動作確認を行う. 公式ページの手順に従う. 利用条件は,利用者で確認すること.
【目次】
【関連する外部ページ】
公式ページ: https://github.com/tesseract-ocr/tessdoc
【サイト内の関連ページ】
前準備
Build Tools for Visual Studio 2022 (ビルドツール for Visual Studio 2022)または Visual Studio 2022 のインストール(Windows 上)
【インストールの判断】 Build Tools for Visual Studio は,開発ツールセットである. Visual Studio は統合開発環境であり,いくつかの種類があり,Build Tools for Visual Studioの機能を含むか連携して使用するものである.インストールは以下の基準で判断してください:
- Build Tools for Visual Studio の機能のみが必要な場合
- Visual Studio の機能が必要である,あるいは,よく分からない場合
Visual Studio 2022 をインストールする際に,「C++ によるデスクトップ開発」を選択することで, Build Tools for Visual Studio 2022 の機能も一緒にインストールされる.
不明な点がある場合は,Visual Studio 全体をインストール を行う方が良い.
Build Tools for Visual Studio 2022 のインストール(Windows 上)
- Windows で,コマンドプロンプトを管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
次のコマンドを実行
次のコマンドは,Build Tools for Visual Studio 2022と VC2015 再配布可能パッケージをインストールするものである.
- Build Tools for Visual Studio 2022 での C++ によるデスクトップ開発,CLI,ATL,MFC のインストール(Windows 上)
- Visual Studio Installer の起動
起動方法: スタートメニューの「Visual Studio Installer」を選ぶ.
- Visual Studio Build Tools 2022 で「変更」を選ぶ.
- 「C++ によるデスクトップ開発」をクリック.そして,画面右側の「インストール」の詳細で「v143 ビルドツール用 C++/CLI サポート(最新)」,「ATL」,「MFC」をチェックする.その後,「変更」をクリック.
- Visual Studio Installer の起動
Visual Studio のインストール(Windows 上)
- Windows で,コマンドプロンプトを管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
次のコマンドを実行
- コマンドプロンプトを管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
- インストールコマンドの実行
winget install Microsoft.VisualStudio.2022.Community --scope machine --override "--add Microsoft.VisualStudio.Workload.NativeDesktop Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core Microsoft.VisualStudio.Component.VC.CLI.Support Microsoft.VisualStudio.Component.CoreEditor Microsoft.VisualStudio.Component.NuGet Microsoft.VisualStudio.Component.Roslyn.Compiler Microsoft.VisualStudio.Component.TextTemplating Microsoft.VisualStudio.Component.Windows.SDK.Latest Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.ATL Microsoft.VisualStudio.Component.VC.ATLMFC" winget install Microsoft.VisualStudio.2022.Community --scope machine Microsoft.VCRedist.2015+.x64
インストールされるコンポーネントの説明:
NativeDesktop
:C++によるデスクトップアプリケーション開発のためのワークロード一式NativeDesktop.Core
:C++デスクトップ開発に必要な基本コンポーネント群VC.CLI.Support
:マネージドコードとネイティブコードの統合開発を可能にするC++/CLIサポートCoreEditor
:コード編集,デバッグ,検索などの基本機能を提供するVisual StudioのコアエディタNuGet
:.NETライブラリの依存関係を管理するパッケージ管理システムWindows.SDK.Latest
:Windows 向けアプリケーション開発用SDK(Software Development Kit)VC.Tools.x86.x64
:32ビット及び64ビット向けC++コンパイラとビルドツールVC.ATL
:Windowsコンポーネント開発用のActive Template LibraryVC.ATLMFC
:デスクトップアプリケーション開発用のMicrosoft Foundation Class Library
システム要件と注意事項:
- 管理者権限でのインストールが必須
- 必要ディスク容量:10GB以上
- 推奨メモリ:8GB以上のRAM
- インストール過程でシステムの再起動が要求される可能性がある
- 安定したインターネット接続環境が必要
追加のコンポーネントが必要な場合は,Visual Studio Installerを使用して個別にインストールすることが可能である.
- インストール完了の確認
winget list Microsoft.VisualStudio.2022.Community
トラブルシューティング:
インストール失敗時は,以下のログファイルを確認:
%TEMP%\dd_setup_<timestamp>.log %TEMP%\dd_bootstrapper_<timestamp>.log
- Visual Studio での C++ によるデスクトップ開発,CLI のインストール(Windows 上)
- Visual Studio Installer の起動
起動方法: スタートメニューの「Visual Studio Installer」を選ぶ.
- Visual Studio Community 2022 で「変更」を選ぶ.
- 「C++ によるデスクトップ開発」をチェック.そして,画面右側の「インストール」の詳細で「v143 ビルドツール用 C++/CLI サポート(最新)」をチェックする.その後,「インストール」をクリック.
- Visual Studio Installer の起動
Git,CMake のインストール(Windows 上)
Gitは,分散型のバージョン管理システム. CMakeは,クロスプラットフォームのビルドシステム生成ツール.
【手順】
- Windows で,コマンドプロンプトを管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
次のコマンドを実行
次のコマンドは,GitとCMakeをインストールし,Gitにパスを通すものである.
次のコマンドでインストールされるGitは 「git for Windows」と呼ばれるものであり, Git,MinGW などから構成されている.
winget install --scope machine Git.Git powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\Program Files\Git\cmd\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")" winget install --scope machine Kitware.CMake powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\Program Files\CMake\bin\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
【関連する外部ページ】
- Git の公式ページ: https://git-scm.com/
- CMake の公式ダウンロードページ: https://cmake.org/download/
【関連項目】 Git バージョン管理システム, Git の利用, CMake ビルドシステム生成ツール, CMake の使用方法
Tesseract OCR 5.3.3 の開発環境とツール等のインストール(Windows 上)
公式ページの手順に従う.
Software Network のセットアップ
- Windows で,コマンドプロンプトを管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
- Software Network のセットアップ
次のコマンドを実行.
cd c:\ rmdir /s /q sw mkdir sw cd sw curl -L -O https://software-network.org/client/sw-master-windows_x86_64-client.zip curl -L -O https://software-network.org/client/swgui-master-windows_x86_64-client.zip powershell -command "Expand-Archive -Path sw-master-windows_x86_64-client.zip" powershell -command "Expand-Archive -Path swgui-master-windows_x86_64-client.zip" rmdir /s /q %HOMEPATH%\.sw cd /d c:%HOMEPATH% c:\sw\sw-master-windows_x86_64-client\sw setup
- 終了の確認
エラーメッセージが出ていないこと.
- ファイルが %HOMEPATH%\.sw にダウンロードされていることを確認
dir %HOMEPATH%\.sw
- Windows のシステム環境変数 Path に c:\sw\sw-master-windows_x86_64-client を追加することにより,パスを通す.
次のコマンドを実行
powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\sw\sw-master-windows_x86_64-client\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
Tesseract 関連ライブラリのビルド(Software Network を使用)
- Windows で,コマンドプロンプトを管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
- Tesseract OCR の開発環境のビルド(Windows 上)
次のコマンドを実行. 終了までしばらく待つ.
cd /d c:%HOMEPATH% sw build -platform=x64 org.sw.demo.google.tesseract.tesseract
- 終了の確認
エラーメッセージが出ていないこと.
- ファイルが %HOMEPATH%\.sw にダウンロードされていることを確認
dir %HOMEPATH%\.sw
Tesseract OCR の開発環境とツール等のインストール(Windows 上)
ソースコードをダウンロードしてインストールする.
- Windows で,コマンドプロンプトを管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
- Tesseract OCR の開発環境のビルド(Windows 上)
次のコマンドを実行. 終了までしばらく待つ.
cd c:\ rmdir /s /q tesseract git clone https://github.com/tesseract-ocr/tesseract cd tesseract mkdir build cd build cmake .. -G "Visual Studio 17 2022" -A x64 -T host=x64 -DBUILD_TESTS=ON -DCMAKE_INSTALL_PREFIX=c:/tesseract # いくつかのファイルをUTF8 を UTF8BOM有りに変換 cd /d c:%HOMEPATH% powershell -Command "$content = Get-Content '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gsocks4aproxy.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gsocks4aproxy.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/84/1c/ec76/src/sdir/gmodule/gmodule.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/84/1c/ec76/src/sdir/gmodule/gmodule.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gnetworkaddress.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gnetworkaddress.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/c7/3e/272a/src/sdir/glib/gatomic.h' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/c7/3e/272a/src/sdir/glib/gatomic.h' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/c7/3e/272a/src/sdir/glib/gtestutils.h' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/c7/3e/272a/src/sdir/glib/gtestutils.h' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/c4/6e/a0a7/src/sdir/gobject/gtype.h' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/c4/6e/a0a7/src/sdir/gobject/gtype.h' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gactiongroupexporter.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gactiongroupexporter.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gappinfo.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gappinfo.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gdbusconnection.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gdbusconnection.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gdbusaddress.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gdbusaddress.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/c7/3e/272a/src/sdir/glib/gstdioprivate.h' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/c7/3e/272a/src/sdir/glib/gstdioprivate.h' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gdatagrambased.h' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gdatagrambased.h' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gfile.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gfile.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gdbusmessage.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gdbusmessage.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gdbusauthmechanismsha1.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gdbusauthmechanismsha1.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gmount.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gmount.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gapplicationimpl-dbus.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gapplicationimpl-dbus.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gdbusserver.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gdbusserver.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/giomodule.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/giomodule.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gproxyresolver.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gproxyresolver.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gthreadedresolver.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gthreadedresolver.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/c4/1e/68f3/src/sdir/src/hb-style.h' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/c4/1e/68f3/src/sdir/src/hb-style.h' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/8f/09/0cc9/src/sdir/pango/pango-language-sample-table.h' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/8f/09/0cc9/src/sdir/pango/pango-language-sample-table.h' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/c4/6e/a0a7/src/sdir/gobject/gsignalgroup.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/c4/6e/a0a7/src/sdir/gobject/gsignalgroup.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gcharsetconverter.c' -Encoding UTF8; $content | Set-Content -Path '.sw/storage/pkg/7b/bc/eeda/src/sdir/gio/gcharsetconverter.c' -Encoding UTF8" powershell -Command "$content = Get-Content '.sw\storage\pkg\04\dc\e58a\src\sdir\pango\pango-language-sample-table.h' -Encoding UTF8; $content | Set-Content -Path '.sw\storage\pkg\04\dc\e58a\src\sdir\pango\pango-language-sample-table.h' -Encoding UTF8" cd c:\tesseract\build cmake --build . --config Release cmake --build . --config Release --target install
- 終了の確認
エラーメッセージが出ていないこと.
- tessdata のダウンロード
次のコマンドを実行.
cd c:\tesseract\share rmdir /s /q tessdata git clone https://github.com/tesseract-ocr/tessdata
- Windows のシステム環境変数 Path に c:\tesseract\bin を追加することにより,パスを通す.
次のコマンドを実行
powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\tesseract\bin\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
- Windows の システム環境変数 TESSDATA_PREFIX の設定を行う.
Windows では, コマンドプロンプトを管理者として開き, 次のコマンドを実行することにより, システム環境変数 TESSDATA_PREFIX の設定を行うことができる.
コマンドプロンプトを管理者として実行: 別ページ »で説明
powershell -command "[System.Environment]::SetEnvironmentVariable(\"TESSDATA_PREFIX\", \"C:\tesseract\share\tessdata\", \"Machine\")"
動作確認(Windows 上)
- 日本語の文章が書かれた画像を用意する
次の画像は、Wikipedia「日本国憲法前文」から取得
Wikipedia「日本国憲法前文」のURL: https://ja.wikipedia.org/wiki/%E6%97%A5%E6%9C%AC%E5%9B%BD%E6%86%B2%E6%B3%95%E5%89%8D%E6%96%87#%E5%89%8D%E6%96%87
- 画像から文字を認識してみる
まず,コマンドプロンプトで,カレントディレクトリを,画像のファイルのあるディレクトリに移動する.
「-l jpn」のところ: 日本語の横書き文書なら「-l jpn」、 日本語の縦書き文書なら「-l jpn_vert」、
tesseract <画像ファイル名> outbase -l jpn
- outbase.txtというファイルができるので,メモ帳で確認
notepad outbase.txt