Files
Let's create some test files
Table[
Export[
StringTemplate["Test``.jpg"][k],
Rasterize@TextCell[
RandomChoice[DictionaryLookup["*"]],
RandomChoice[{"Text", "Subsection", "Section", "Title"}]
]
]
, {k, 10}
]
Test a single file using RunProcess
(advisable).
RunProcess[
{
"C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe",
"Test1.jpg",
"Test1"
}
]
(* <|"ExitCode" -> 0, "StandardOutput" -> "",
"StandardError" ->
"Tesseract Open Source OCR Engine v3.02 with Leptonica
"|> *)
Test a single file using Run
, notice the extra quotation marks go only around the long path name to protect the spaces. Arguments do not need quotation marks.
Run[
"\"C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe\" Test1.jpg Test1"
]
(* 0 *)
Processing many files
Table[
{
StringTemplate["Test``.jpg"][k],
RunProcess[
{
"C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe",
StringTemplate["Test``.jpg"][k],
StringTemplate["Test``"][k]
}
]["ExitCode"]
}
, {k, 10}
]
Compare with Mathematica's TextRecognize
TableForm[
Table[
{
StringTemplate["Test``.jpg"][k],
Import[StringTemplate["Test``.jpg"][k]],
Import[StringTemplate["Test``.txt"][k], "String"],
TextRecognize[StringTemplate["Test``.jpg"][k]]
}
, {k, 10}
]
, TableHeadings -> {Automatic, {"File Name", "Image", "Tesseract",
"Mathematica\nTextRecognize" }}
]
Run
,Import["! <<command line code here>>", "Text"]
works for me. Maybe you want to give it a try. Is is also capable of returning the error message and not only the error code (IRRC, you have to append"2>&1"
to the command line code for that...) $\endgroup$