Ejemplo n.º 1
0
// NewTess creates and returns a new tesseract instance.
func NewTess(datapath string, language string) (*Tess, error) {
	// create new empty TessBaseAPI
	tba := C.TessBaseAPICreate()

	// prepare string for C call
	cDatapath := C.CString(datapath)
	defer C.free(unsafe.Pointer(cDatapath))

	// prepare string for C call
	cLanguage := C.CString(language)
	defer C.free(unsafe.Pointer(cLanguage))

	// initialize datapath and language on TessBaseAPI
	res := C.TessBaseAPIInit3(tba, cDatapath, cLanguage)
	if res != 0 {
		return nil, errors.New("could not initiate new Tess instance")
	}

	// create tesseract instance (Tess)
	tess := &Tess{
		tba: tba,
	}

	// set GC finalizer, to be ran in case the user forgets to call Close()
	runtime.SetFinalizer(tess, (*Tess).delete)

	// all done
	return tess, nil
}
Ejemplo n.º 2
0
func baseAPINew() *TesseractAPI {
	tesseract := C.TessBaseAPICreate()
	t := &TesseractAPI{api: tesseract}
	return t
}