forked from cosmo0920/tesseractocr-capi-go
/
sample_test.go
50 lines (45 loc) · 1.74 KB
/
sample_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package tesseractocr_test
import (
ocr "."
"fmt"
lept "github.com/cosmo0920/leptonica-capi-go"
"os"
)
const abort = 3
func setupExampleTesseractAPI() *ocr.TesseractAPI {
env := ocr.Env()
lang := "eng"
api, err := ocr.BaseAPIInit3(env, lang)
if err != nil {
os.Exit(abort)
}
return api
}
func ExampleUsage() {
filename := "fixture/golangref.tiff"
api := setupExampleTesseractAPI()
result := api.BaseAPIProcessPages(filename, nil, 0)
fmt.Println(result)
// output: Function pointer callbacks
//
// C code can call exported Go functions with their explicit name. But if a C—program wants a function pointer, a gateway function has to be written.
// This is because we can't take the address of a Go function and give that to C—code since the cgo tool will generate a stub in C that should be
// called. The following example shows how to integrate with C code wanting a function pointer of a give type.
//
// Place these source files under $GOPATH/src/ccallbacks/. Compile and run with:
}
func ExampleBasicUsage() {
filename := "fixture/golangref.tiff"
api := setupExampleTesseractAPI()
pix, _ := lept.PixRead(filename)
api.BaseAPISetImage(pix)
text := api.BaseAPIGetUTF8Text()
fmt.Println(text)
// output: Function pointer callbacks
//
// C code can call exported Go functions with their explicit name. But if a C—program wants a function pointer, a gateway function has to be written.
// This is because we can't take the address of a Go function and give that to C—code since the cgo tool will generate a stub in C that should be
// called. The following example shows how to integrate with C code wanting a function pointer of a give type.
//
// Place these source files under $GOPATH/src/ccallbacks/. Compile and run with:
}