示例#1
0
func (t *TesseractAPI) BaseAPIProcessPages(filename string, retry_config *C.char, timeout_millisec int) string {
	cFilename := C.CString(filename)
	defer C.free(unsafe.Pointer(cFilename))

	out := C.TessBaseAPIProcessPages(t.api, cFilename, retry_config,
		C.int(timeout_millisec))
	result := C.GoString(out)
	return result
}
示例#2
0
文件: main.go 项目: unbe/docsheep
func main() {
	// get the image to try
	flag.Parse()
	image := flag.Arg(0)

	// print the version
	fmt.Println(tesseract.Version())

	// create new tess instance and point it to the tessdata location. Set language to english.
	tessdata_prefix := os.Getenv("TESSDATA_PREFIX")
	if tessdata_prefix == "" {
		tessdata_prefix = "/usr/local/share"
	}
	datadir := filepath.Join(tessdata_prefix, "tessdata")
	t, err := tesseract.NewTess(datadir, "deu+eng")
	if err != nil {
		log.Fatalf("Error while initializing Tess: %s\n", err)
	}
	defer t.Close()
	// open a new Pix from file with leptonica
	/*	pix, err := leptonica.NewPixFromFile(image)
		if err != nil {
			log.Fatalf("Error while getting pix from file: %s\n", err)
		}
		defer pix.Close()
	*/
	t.SetPageSegMode(tesseract.PSM_AUTO_OSD)

	// setup a whitelist of all basic ascii
	/*err = t.SetVariable("tessedit_char_whitelist", ` !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~`+"`")
	if err != nil {
		log.Fatalf("Failed to SetVariable: %s\n", err)
	}*/

	cOutputbase := C.CString("./ocr")
	defer C.free(unsafe.Pointer(cOutputbase))
	cDatadir := C.CString(datadir)
	defer C.free(unsafe.Pointer(cDatadir))

	pdfRenderer := C.TessPDFRendererCreate(cOutputbase, cDatadir)
	C.TessDeleteResultRenderer(pdfRenderer)
	fmt.Printf("%#v\n", pdfRenderer)

	th := (*C.struct_TessBaseAPI)(t.Handle())

	cImage := C.CString(image)
	defer C.free(unsafe.Pointer(cImage))
	C.TessBaseAPIProcessPages(th, cImage, nil, 0, pdfRenderer)
	//	C.TessDeleteResultRenderer(pdfRenderer)

	/*
		t.SetImagePix(pix)

		text := t.Text()
		fmt.Printf("%s", text)

		ri := C.TessBaseAPIGetIterator(th)
		defer C.TessResultIteratorDelete(ri)

		words := make([]TessWord, 0)
		if ri != nil {
			pi := C.TessResultIteratorGetPageIterator(ri)
			for {
				words = append(words, GetWord(ri))
				if C.TessPageIteratorNext(pi, C.RIL_WORD) == C.int(0) {
					break
				}
			}
		}
		sort.Stable(sort.Reverse(ByFontSize(words)))
		for _, word := range words {
			if word.confidence > 75 && len(word.text) >= 3 {
				fmt.Printf("%#v\n", word)
			}
		}

		t.DumpVariables()
	*/
}