Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,22 @@ func TestClient_ConfigFilePath(t *testing.T) {

}

func TestClient_PSMNotResetInFirstInitCall(t *testing.T) {
// see https://github.com/otiai10/gosseract/issues/167
psm := PSM_SINGLE_BLOCK_VERT_TEXT
client := NewClient()
defer client.Close()

err := client.SetPageSegMode(psm) //set 5
Expect(t, err).ToBe(nil)
Expect(t, client.PageSegMode()).ToBe(psm)

client.SetImage("./test/data/001-helloworld.png")
_, err = client.Text() //This step will execute client.init() before outputting the OCR text.
Expect(t, err).ToBe(nil)
Expect(t, client.PageSegMode()).ToBe(psm)
}

func TestClientBoundingBox(t *testing.T) {

if os.Getenv("TESS_BOX_DISABLED") == "1" {
Expand Down
6 changes: 6 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ func (client *Client) SetPageSegMode(mode PageSegMode) error {
return nil
}

// PageSegMode returns the "Page Segmentation Mode" (PSM)
// See official documentation for PSM here https://tesseract-ocr.github.io/tessdoc/ImproveQuality#page-segmentation-method
func (client *Client) PageSegMode() PageSegMode {
return PageSegMode(C.GetPageSegMode(client.api))
}

// SetConfigFile sets the file path to config file.
func (client *Client) SetConfigFile(fpath string) error {
if client.api == nil {
Expand Down
2 changes: 2 additions & 0 deletions tessbridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ int Init(TessBaseAPI a, char* tessdataprefix, char* languages, char* configfilep
setbuf(stderr, errbuf);
// }}}

int psm = GetPageSegMode(api);
int ret;
if (configfilepath != NULL) {
char* configs[] = {configfilepath};
Expand All @@ -59,6 +60,7 @@ int Init(TessBaseAPI a, char* tessdataprefix, char* languages, char* configfilep
} else {
ret = api->Init(tessdataprefix, languages);
}
SetPageSegMode(api, psm);

// {{{ Restore default stderr
(void)freopen("/dev/null", "a", stderr);
Expand Down