Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TSVText method #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions tesseract.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"unicode/utf8"
"unsafe"

"gopkg.in/GeertJohan/go.leptonica.v1"
leptonica "gopkg.in/GeertJohan/go.leptonica.v1"
)

const version = "1.0"
Expand Down Expand Up @@ -121,6 +121,14 @@ func (t *Tess) SetImagePix(pix *leptonica.Pix) {
C.TessBaseAPISetImage2(t.tba, (*C.struct_Pix)(unsafe.Pointer(pix.CPIX())))
}

// void TessBaseAPISetSourceResolution(TessBaseAPI* handle, int ppi);

// SetSourceResolution set the resolution of the source image in pixels per inch.
// The must be called after SetInputName or SetImagePix and has the same reslut as the --dpi flag.
func (t *Tess) SetSourceResolution(ppi int) {
C.TessBaseAPISetSourceResolution(t.tba, C.int(ppi))
}

/* char* TessBaseAPIGetUTF8Text(TessBaseAPI* handle);

Make a text string from the internal data structures.
Expand Down Expand Up @@ -152,6 +160,21 @@ func (t *Tess) HOCRText(pagenumber int) string {
return text
}

/* char* TessBaseAPIGetTsvText(TessBaseAPI* handle, int page_number);

Make a TSV-formatted string from the internal data structures.
page_number is 0-based but will appear in the output as 1-based.
Returned string must be freed with the delete [] operator.
*/

// TSVText returns a TSV-formatted string.
func (t *Tess) TSVText(pagenumber int) string {
cText := C.TessBaseAPIGetTsvText(t.tba, C.int(pagenumber))
defer C.free(unsafe.Pointer(cText))
text := C.GoString(cText)
return text
}

/* char* TessBaseAPIGetBoxText(TessBaseAPI* handle, int page_number);

The recognized text is returned as a char* which is coded
Expand Down Expand Up @@ -472,8 +495,6 @@ func (r *ResultIterator) Text(level PageIteratorLevel) (string, error) {

// void TessBaseAPISetImage(TessBaseAPI* handle, const unsigned char* imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line);

// void TessBaseAPISetSourceResolution(TessBaseAPI* handle, int ppi);

// PIX* TessBaseAPIGetThresholdedImage( TessBaseAPI* handle);
// BOXA* TessBaseAPIGetRegions( TessBaseAPI* handle, PIXA** pixa);
// BOXA* TessBaseAPIGetTextlines( TessBaseAPI* handle, PIXA** pixa, int** blockids);
Expand Down