Hello Iseahound, I like your tesseract wrapper and I'am watching your progress since month's. I'am using your library for some experiments with pdf files.
I missed a solution to use my own leptonica and tesseract directory's. More than about 3 times I changed your Vis2.ahk file at this position to the path's I use.
Code: Select all
class Tesseract {
static leptonica := A_ScriptDir "\bin\leptonica_util\leptonica_util.exe"
static tesseract := A_ScriptDir "\bin\tesseract\tesseract.exe"
static tessdata_best := A_ScriptDir "\bin\tesseract\tessdata_best"
static tessdata_fast := A_ScriptDir "\bin\tesseract\tessdata_fast"
Today I just wanted to write a function in the hope that you find this useful. The function will write's the path of tesseract, tessdata and leptonica_util to an .ini file.
If someone want to use tesseract from your repository the function will write and read relative path's. So you can leave a ready made .ini file in your \lib directory of your repository.
Is this file is deleted or some key are deleted or missed, my function will ask for it.
This is an ini-file with relative paths:
Code: Select all
[leptonica]
exePath=\bin\leptonica_util\leptonica_util.exe
[tesseract]
exePath=\bin\tesseract\tesseract.exe
data_best=\bin\tesseract\tessdata_best
tessdata_fast=\bin\tesseract\tessdata_fast
Part1:
Code: Select all
class Tesseract {
static leptonica := Vis2.stdlib.paths("leptonica")
static tesseract := Vis2.stdlib.paths("tesseract")
static tessdata_best := Vis2.stdlib.paths("tessdata_best")
static tessdata_fast := Vis2.stdlib.paths("tessdata_fast")
...
Part2:
Code: Select all
class stdlib {
...
; for user customable paths to leptonica and tesseract
paths(toWhat){
static lastdir
If Instr(toWhat, "leptonica")
{
IniRead, leptonica, % A_ScriptDir "\lib\Vis2.ini", leptonica, exePath
If ( (leptonica="ERROR") or !InStr(leptonica, "leptonica_util.exe") )
{
Vis2.Graphics.Subtitle.Render("You have not specified a path to leptonica_util.exe.`nPlease select the file now!", "t7000 xCenter y5% p1.35% c88EAB6 r8", "s2.23% cBlack")
again:=1
While (again=1)
{
FileSelectFile, leptonica,, C:, Please select leptonica.exe, *.exe
If InStr(leptonica, "leptonica_util.exe")
again=0
}
If Instr(leptonica, A_ScriptDir)
leptonica:= StrReplace(leptonica, A_ScriptDir)
IniWrite, % leptonica, % A_ScriptDir "\lib\Vis2.ini", leptonica, exePath
If ErrorLevel
throw Exception("Can not write to ini file!",, A_ScriptDir "\lib\Vis2.ini")
}
lastDir:= Vis2.stdlib.GetParentDir(leptonica)
return SubStr(leptonica, 1, 1) = "\" ? A_ScriptDir . leptonica : leptonica
}
If Instr(toWhat, "tesseract")
{
IniRead, tesseract, % A_ScriptDir "\lib\Vis2.ini", tesseract, exePath
If ( (tesseract="ERROR") or !InStr(tesseract, "tesseract.exe") )
{
Vis2.Graphics.Subtitle.Render("You have not specified a path to tesseract.exe.`nPlease select the file now!", "t7000 xCenter y5% p1.35% c88EAB6 r8", "s2.23% cBlack")
again:=1
While (again=1)
{
FileSelectFile, tesseract,, % lastDir, Please select tesseract.exe, *.exe
If InStr(tesseract, "tesseract.exe")
again=0
}
If Instr(tesseract, A_ScriptDir)
tesseract:= StrReplace(tesseract, A_ScriptDir)
IniWrite, % tesseract, % A_ScriptDir "\lib\Vis2.ini", tesseract, exePath
If ErrorLevel
throw Exception("Can not write to ini file!",, A_ScriptDir "\lib\Vis2.ini")
}
lastDir:= Vis2.stdlib.GetParentDir(tesseract)
return SubStr(tesseract, 1, 1) = "\" ? A_ScriptDir . tesseract : tesseract
}
If Instr(toWhat, "tessdata_best")
{
IniRead, tessdata_best, % A_ScriptDir "\lib\Vis2.ini", tesseract, data_best
If (tessdata_best="ERROR")
{
Vis2.Graphics.Subtitle.Render("You have not specified a path to tessdata_best.`nPlease select the path now!", "t7000 xCenter y5% p1.35% c88EAB6 r8", "s2.23% cBlack")
again:=1
While (again=1)
{
FileSelectFolder, tessdata_best, % lastDir, 2, Please select path to tessdata_best
again:=ErrorLevel
}
If Instr(tessdata_best, A_ScriptDir)
tessdata_best:= StrReplace(tessdata_best, A_ScriptDir)
IniWrite, % tessdata_best, % A_ScriptDir "\lib\Vis2.ini", tesseract, data_best
If ErrorLevel
throw Exception("Can not write to ini file!",, A_ScriptDir "\lib\Vis2.ini")
}
lastDir:= Vis2.stdlib.GetParentDir(tessdata_best)
return SubStr(tessdata_best, 1, 1) = "\" ? A_ScriptDir . tessdata_best : tessdata_best
}
If Instr(toWhat, "tessdata_fast")
{
IniRead, tessdata_fast, % A_ScriptDir "\lib\Vis2.ini", tesseract, tessdata_fast
If (tessdata_fast="ERROR")
{
Vis2.Graphics.Subtitle.Render("You have not specified a path to tessdata_fast.`nPlease select the path now!", "t7000 xCenter y5% p1.35% c88EAB6 r8", "s2.23% cBlack")
again:=1
While (again=1)
{
FileSelectFolder, tessdata_fast, % lastDir, 2, Please select path to tessdata_fast
again:=ErrorLevel
}
If Instr(tessdata_fast, A_ScriptDir)
tessdata_fast:= StrReplace(tessdata_fast, A_ScriptDir)
IniWrite, % tessdata_fast, % A_ScriptDir "\lib\Vis2.ini", tesseract, tessdata_fast
If ErrorLevel
throw Exception("Can not write to ini file!",, A_ScriptDir "\lib\Vis2.ini")
}
return SubStr(tessdata_fast, 1, 1) = "\" ? A_ScriptDir . tessdata_fast : tessdata_fast
}
}
; small RegEx function to get parent dir from a given string
GetParentDir(Dir){
Return RegExReplace(Dir, "\\[^\\]+$")
}
}
class Text {