예제 #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
}
예제 #2
0
func BaseAPIInit3(env string, lang string) (*TesseractAPI, error) {
	cEnv := C.CString(env)
	defer C.free(unsafe.Pointer(cEnv))

	cLang := C.CString(lang)
	defer C.free(unsafe.Pointer(cLang))

	instance := baseAPINew()

	rc := C.TessBaseAPIInit3(instance.api, cEnv, cLang)
	if rc != success {
		return nil, errors.New("Could not initialize tesseract.")
	}

	runtime.SetFinalizer(instance, (*TesseractAPI).finalize)
	return instance, nil
}