Skip to content

Commit e8999c7

Browse files
committed
Fix calling NewTess() with an empty datapath argument
Passing NULL is the only way to make Tesseract use the compiled in TESSDATA_PREFIX constant.
1 parent 60d1b18 commit e8999c7

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

tesseract.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,22 @@ func NewTess(datapath string, language string) (*Tess, error) {
4343
// create new empty TessBaseAPI
4444
tba := C.TessBaseAPICreate()
4545

46-
// prepare string for C call
47-
cDatapath := C.CString(datapath)
48-
defer C.free(unsafe.Pointer(cDatapath))
49-
5046
// prepare string for C call
5147
cLanguage := C.CString(language)
5248
defer C.free(unsafe.Pointer(cLanguage))
5349

54-
// initialize datapath and language on TessBaseAPI
55-
res := C.TessBaseAPIInit3(tba, cDatapath, cLanguage)
50+
var res C.int
51+
if datapath != "" {
52+
// prepare string for C call
53+
cDatapath := C.CString(datapath)
54+
defer C.free(unsafe.Pointer(cDatapath))
55+
56+
// initialize datapath and language on TessBaseAPI
57+
res = C.TessBaseAPIInit3(tba, cDatapath, cLanguage)
58+
} else {
59+
res = C.TessBaseAPIInit3(tba, nil, cLanguage)
60+
}
61+
5662
if res != 0 {
5763
return nil, errors.New("could not initiate new Tess instance")
5864
}

0 commit comments

Comments
 (0)