Skip to content

Commit

Permalink
Merge pull request #310 from otiai10/revert-299-main
Browse files Browse the repository at this point in the history
Revert "feat: add DetectOrientationScript method"
  • Loading branch information
otiai10 authored Jun 21, 2024
2 parents 3d69987 + a32c9b3 commit 769a448
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 65 deletions.
10 changes: 0 additions & 10 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,6 @@ func TestClient_HTML(t *testing.T) {
})
}

func TestClient_DetectOrientationScript(t *testing.T) {
client := NewClient()
defer client.Close()
client.SetImage("./test/data/004-rotated-text.png")
deg, _, script_name, _, err := client.DetectOrientationScript()
Expect(t, err).ToBe(nil)
Expect(t, deg).ToBe(180)
Expect(t, script_name).ToBe("Latin")
}

func TestGetAvailableLangs(t *testing.T) {
t.Skip("TODO")
// langs, err := GetAvailableLanguages()
Expand Down
49 changes: 1 addition & 48 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,42 +312,14 @@ func (client *Client) init() error {
return nil
}

// Initialize tesseract::TessBaseAPI for OSD (Orientation and Script Detection)
func (client *Client) initOsd() error {
var tessdataPrefix *C.char
if client.TessdataPrefix != "" {
tessdataPrefix = C.CString(client.TessdataPrefix)
}
defer C.free(unsafe.Pointer(tessdataPrefix))

res := C.Init(client.api, tessdataPrefix, C.CString("osd"), nil, nil)
if res != 0 {
return fmt.Errorf("failed to initialize TessBaseAPI with code %d", res)
}

if err := client.setVariablesToInitializedAPI(); err != nil {
return err
}

if client.pixImage == nil {
return fmt.Errorf("PixImage is not set, use SetImage or SetImageFromBytes before DetectOrientationScript")
}

C.SetPixImage(client.api, client.pixImage)

client.shouldInit = true

return nil
}

// This method flag the current instance to be initialized again on the next call to a function that
// requires a gosseract API initialized: when user change the config file or the languages
// the instance needs to init a new gosseract api
func (client *Client) flagForInit() {
client.shouldInit = true
}

// This method sets all the specified variables to TessBaseAPI structure.
// This method sets all the sspecified variables to TessBaseAPI structure.
// Because `api->SetVariable` must be called after `api->Init()`,
// gosseract.Client.SetVariable cannot call `api->SetVariable` directly.
// See https://zdenop.github.io/tesseract-doc/classtesseract_1_1_tess_base_a_p_i.html#a2e09259c558c6d8e0f7e523cbaf5adf5
Expand Down Expand Up @@ -404,25 +376,6 @@ func (client *Client) HOCRText() (out string, err error) {
return
}

func (client *Client) DetectOrientationScript() (int, float32, string, float32, error) {
if err := client.initOsd(); err != nil {
return 0, 0, "", 0, err
}
var (
orient_deg C.int
orient_conf C.float
script_name *C.char
script_conf C.float
)
defer C.free(unsafe.Pointer(script_name))
C.DetectOrientationScript(client.api, &orient_deg, &orient_conf, &script_name, &script_conf)
if script_name == nil {
return int(orient_deg), float32(orient_conf), "", float32(script_conf), fmt.Errorf("script name is null")
}

return int(orient_deg), float32(orient_conf), C.GoString(script_name), float32(script_conf), nil
}

// BoundingBox contains the position, confidence and UTF8 text of the recognized word
type BoundingBox struct {
Box image.Rectangle
Expand Down
5 changes: 0 additions & 5 deletions tessbridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ char* HOCRText(TessBaseAPI a) {
return api->GetHOCRText(0);
}

void DetectOrientationScript(TessBaseAPI a, int* orient_deg, float* orient_conf, const char** script_name, float* script_conf) {
tesseract::TessBaseAPI* api = (tesseract::TessBaseAPI*)a;
api->DetectOrientationScript(orient_deg, orient_conf, script_name, script_conf);
}

bounding_boxes* GetBoundingBoxesVerbose(TessBaseAPI a) {
using namespace tesseract;
tesseract::TessBaseAPI* api = (tesseract::TessBaseAPI*)a;
Expand Down
1 change: 0 additions & 1 deletion tessbridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ void SetPageSegMode(TessBaseAPI, int);
int GetPageSegMode(TessBaseAPI);
char* UTF8Text(TessBaseAPI);
char* HOCRText(TessBaseAPI);
void DetectOrientationScript(TessBaseAPI, int*, float*, const char**, float*);
const char* Version(TessBaseAPI);
const char* GetDataPath();

Expand Down
Binary file removed test/data/004-rotated-text.png
Binary file not shown.
2 changes: 1 addition & 1 deletion test/runtimes/alpine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN apk add \
musl-dev \
go \
tesseract-ocr-dev
RUN apk add tesseract-ocr-data-osd tesseract-ocr-data-eng
RUN apk add tesseract-ocr-data-eng

ENV GOPATH=/root/go

Expand Down

0 comments on commit 769a448

Please sign in to comment.