Tesseract-OCR 批处理所有子文件夹中的文件,Windows cmd?
Tesseract-OCR to batch files in all subfolders, Windows cmd?
我正在尝试使用 Tesseract-OCR 读取和 OCR 所有 .png 文件,不仅在当前文件夹中(因为有答案)而且在所有子文件夹中.
这适用于文件夹:
for %%A in ("C:\Users\x\AppData\Local\Tesseract-OCR\temp\*.png") do C:\Users\x\AppData\Local\Tesseract-OCR\tesseract.exe "%%~fA" "%%~dpnxA"
我尝试用它浏览 "temp" 文件夹中的所有子文件夹:
(for /r %%a in (*.png) do C:\Users\x\AppData\Local\Tesseract-OCR\tesseract.exe "%%~nxa" "%%~dpnxA")
但我对每个文件都遇到了这个错误:
C:\Users\x\AppData\Local\Tesseract-OCR\temp>C:\Users\x\AppData\Local\Tesseract-OCR\tesseract.exe "01.png" "%~dpnxA"
Tesseract Open Source OCR Engine v4.1.0-elag2019 with Leptonica
Error, cannot read input file 01.png: No such file or directory
Error during processing.
很明显,脚本找到了所有子文件夹中的所有文件,但由于某种原因无法读取?
此外,此脚本适用于一个文件夹,但当我尝试与 /r 一起使用时,它不会遍历所有子文件夹:
:Start
@Echo off
Set _SourcePath=C:\Users\x\AppData\Local\Tesseract-OCR\temp\*.png
Set _OutputPath=C:\Users\x\AppData\Local\Tesseract-OCR\temp\
Set _Tesseract="C:\Users\x\AppData\Local\Tesseract-OCR\tesseract.exe"
:Convert
For %%A in (%_SourcePath%) Do Echo Converting %%A...&%_Tesseract% %%A %_OutputPath%%%~nA
:End
Set "_SourcePath="
Set "_OutputPath="
Set "_Tesseract="
有什么想法吗?
也许您正在寻找这样的东西:
@Echo Off
SetLocal DisableDelayedExpansion
Set "_SourcePath=%LocalAppData%\Tesseract-OCR\temp"
Set "_SourceMask=*.png"
Set "_OutputPath=%LocalAppData%\Tesseract-OCR\temp"
Set "_TesserFile=%LocalAppData%\Tesseract-OCR\tesseract.exe"
For /F "Delims=" %%A In (
'""%__AppDir__%where.exe" /R "%_SourcePath%" "%_SourceMask%" 2>Nul"'
) Do Echo Converting %%A...& "%_TesserFile%" "%%A" "%_OutputPath%\%%~nA"
注意,这假设 tesseract 允许指定输出目录并接受双引号字符串等。它还假设您打算将所有输出文件放在 %_OutputPath%
.
如果您希望它们与各自的 .png
并排放置,那么也许可以这样做:
@Echo Off
SetLocal DisableDelayedExpansion
Set "_SourcePath=%LocalAppData%\Tesseract-OCR\temp"
Set "_SourceMask=*.png"
Set "_TesserFile=%LocalAppData%\Tesseract-OCR\tesseract.exe"
For /F "Delims=" %%A In (
'""%__AppDir__%where.exe" /R "%_SourcePath%" "%_SourceMask%" 2>Nul"'
) Do Echo Converting %%A...& "%_TesserFile%" "%%A" "%%~nA"
我正在尝试使用 Tesseract-OCR 读取和 OCR 所有 .png 文件,不仅在当前文件夹中(因为有答案)而且在所有子文件夹中. 这适用于文件夹:
for %%A in ("C:\Users\x\AppData\Local\Tesseract-OCR\temp\*.png") do C:\Users\x\AppData\Local\Tesseract-OCR\tesseract.exe "%%~fA" "%%~dpnxA"
我尝试用它浏览 "temp" 文件夹中的所有子文件夹:
(for /r %%a in (*.png) do C:\Users\x\AppData\Local\Tesseract-OCR\tesseract.exe "%%~nxa" "%%~dpnxA")
但我对每个文件都遇到了这个错误:
C:\Users\x\AppData\Local\Tesseract-OCR\temp>C:\Users\x\AppData\Local\Tesseract-OCR\tesseract.exe "01.png" "%~dpnxA"
Tesseract Open Source OCR Engine v4.1.0-elag2019 with Leptonica
Error, cannot read input file 01.png: No such file or directory
Error during processing.
很明显,脚本找到了所有子文件夹中的所有文件,但由于某种原因无法读取?
此外,此脚本适用于一个文件夹,但当我尝试与 /r 一起使用时,它不会遍历所有子文件夹:
:Start
@Echo off
Set _SourcePath=C:\Users\x\AppData\Local\Tesseract-OCR\temp\*.png
Set _OutputPath=C:\Users\x\AppData\Local\Tesseract-OCR\temp\
Set _Tesseract="C:\Users\x\AppData\Local\Tesseract-OCR\tesseract.exe"
:Convert
For %%A in (%_SourcePath%) Do Echo Converting %%A...&%_Tesseract% %%A %_OutputPath%%%~nA
:End
Set "_SourcePath="
Set "_OutputPath="
Set "_Tesseract="
有什么想法吗?
也许您正在寻找这样的东西:
@Echo Off
SetLocal DisableDelayedExpansion
Set "_SourcePath=%LocalAppData%\Tesseract-OCR\temp"
Set "_SourceMask=*.png"
Set "_OutputPath=%LocalAppData%\Tesseract-OCR\temp"
Set "_TesserFile=%LocalAppData%\Tesseract-OCR\tesseract.exe"
For /F "Delims=" %%A In (
'""%__AppDir__%where.exe" /R "%_SourcePath%" "%_SourceMask%" 2>Nul"'
) Do Echo Converting %%A...& "%_TesserFile%" "%%A" "%_OutputPath%\%%~nA"
注意,这假设 tesseract 允许指定输出目录并接受双引号字符串等。它还假设您打算将所有输出文件放在 %_OutputPath%
.
如果您希望它们与各自的 .png
并排放置,那么也许可以这样做:
@Echo Off
SetLocal DisableDelayedExpansion
Set "_SourcePath=%LocalAppData%\Tesseract-OCR\temp"
Set "_SourceMask=*.png"
Set "_TesserFile=%LocalAppData%\Tesseract-OCR\tesseract.exe"
For /F "Delims=" %%A In (
'""%__AppDir__%where.exe" /R "%_SourcePath%" "%_SourceMask%" 2>Nul"'
) Do Echo Converting %%A...& "%_TesserFile%" "%%A" "%%~nA"