From b120479bcbfe06e422e387bff2a6d659935fef66 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Fri, 1 Mar 2019 07:46:30 -0400 Subject: [PATCH] update go mod vendor --- go.mod | 11 +- go.sum | 16 +-- vendor/github.com/go-ole/go-ole/.travis.yml | 7 +- vendor/github.com/go-ole/go-ole/go.mod | 3 + vendor/github.com/lxn/win/AUTHORS | 1 + vendor/github.com/lxn/win/comctl32.go | 4 + vendor/github.com/lxn/win/kernel32.go | 17 +-- vendor/github.com/lxn/win/user32.go | 105 ++++++++++++++++++ vendor/github.com/otiai10/gosseract/client.go | 46 +++++++- .../github.com/otiai10/gosseract/constant.go | 20 ++++ .../otiai10/gosseract/tessbridge.cpp | 57 +++++++++- .../github.com/otiai10/gosseract/tessbridge.h | 14 ++- vendor/github.com/robotn/gohook/appveyor.yml | 2 +- vendor/modules.txt | 14 +-- 14 files changed, 277 insertions(+), 40 deletions(-) create mode 100644 vendor/github.com/go-ole/go-ole/go.mod diff --git a/go.mod b/go.mod index b880f80..70b87b1 100644 --- a/go.mod +++ b/go.mod @@ -4,14 +4,15 @@ require ( github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 github.com/BurntSushi/xgbutil v0.0.0-20160919175755-f7c97cef3b4e github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 // indirect - github.com/go-ole/go-ole v1.2.2 // indirect - github.com/lxn/win v0.0.0-20181015143721-a7f87360b10e - github.com/otiai10/gosseract v2.2.0+incompatible - github.com/robotn/gohook v0.0.0-20190227135941-4e658a44067c + github.com/go-ole/go-ole v1.2.4 // indirect + github.com/lxn/win v0.0.0-20190226192825-50e22abd4ff9 + github.com/otiai10/gosseract v2.2.1+incompatible + github.com/robotn/gohook v0.0.0-20190227143424-9bf349ed0b6d github.com/shirou/gopsutil v2.18.12+incompatible github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect github.com/vcaesar/imgo v0.0.0-20181209162409-13af122cf2fa - golang.org/x/sys v0.0.0-20190109145017-48ac38b7c8cb // indirect + golang.org/x/image v0.0.0-20190227222117-0694c2d4d067 // indirect + golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e // indirect ) replace ( diff --git a/go.sum b/go.sum index ed8cf86..742a95c 100644 --- a/go.sum +++ b/go.sum @@ -4,18 +4,18 @@ github.com/BurntSushi/xgbutil v0.0.0-20160919175755-f7c97cef3b4e h1:4ZrkT/RzpnRO github.com/BurntSushi/xgbutil v0.0.0-20160919175755-f7c97cef3b4e/go.mod h1:uw9h2sd4WWHOPdJ13MQpwK5qYWKYDumDqxWWIknEQ+k= github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 h1:UUppSQnhf4Yc6xGxSkoQpPhb7RVzuv5Nb1mwJ5VId9s= github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= -github.com/go-ole/go-ole v1.2.2 h1:HXmymm3IQ8iAfpqlbbUGLHd+SZrnmI4y1pv+WL/3R7c= -github.com/go-ole/go-ole v1.2.2/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= +github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI= +github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM= github.com/golang/image v0.0.0-20181116024801-cd38e8056d9b h1:560WQdaWjsfqNwVBNZLN3uPrHCoa0OiZkFIvb/x+PwE= github.com/golang/image v0.0.0-20181116024801-cd38e8056d9b/go.mod h1:W3cvIh6MZCq53QRt4EH8hvU9HPLAPXNxfcoJxCiaTV4= github.com/golang/sys v0.0.0-20190109145017-48ac38b7c8cb h1:W0jr+BhzUWF6woATVXwDdmDkouJfNJEiITOjtOEIlfI= github.com/golang/sys v0.0.0-20190109145017-48ac38b7c8cb/go.mod h1:5JyrLPvD/ZdaYkT7IqKhsP5xt7aLjA99KXRtk4EIYDk= -github.com/lxn/win v0.0.0-20181015143721-a7f87360b10e h1:dz4TzIsrPe4XtUyhLkOLdCS8UkVwJKQu4WY8VcIwo3I= -github.com/lxn/win v0.0.0-20181015143721-a7f87360b10e/go.mod h1:jACzEp9RV7NhfPJQkiCNTteU4nkZZVlvkNpYtVOZPfE= -github.com/otiai10/gosseract v2.2.0+incompatible h1:r2Icyba/doznLy0MgsDMWJADETgJNjlX78x/BBbhCUY= -github.com/otiai10/gosseract v2.2.0+incompatible/go.mod h1:XrzWItCzCpFRZ35n3YtVTgq5bLAhFIkascoRo8G32QE= -github.com/robotn/gohook v0.0.0-20190227135941-4e658a44067c h1:lhKBCH1mWQcvD2eVZevWlXYBJ2npFArzFVAFj3p6z58= -github.com/robotn/gohook v0.0.0-20190227135941-4e658a44067c/go.mod h1:YD5RyCnUEY2xqtkkgeQVZ31UAfAnVPwUxpTE5cwSXg4= +github.com/lxn/win v0.0.0-20190226192825-50e22abd4ff9 h1:7noriXA0DUpF8QGGBsuGCRn+LLs7uR0MlDfVccQuvEg= +github.com/lxn/win v0.0.0-20190226192825-50e22abd4ff9/go.mod h1:jACzEp9RV7NhfPJQkiCNTteU4nkZZVlvkNpYtVOZPfE= +github.com/otiai10/gosseract v2.2.1+incompatible h1:Ry5ltVdpdp4LAa2bMjsSJH34XHVOV7XMi41HtzL8X2I= +github.com/otiai10/gosseract v2.2.1+incompatible/go.mod h1:XrzWItCzCpFRZ35n3YtVTgq5bLAhFIkascoRo8G32QE= +github.com/robotn/gohook v0.0.0-20190227143424-9bf349ed0b6d h1:AYuqgHF+CzRt+kNH7MVXu6GL8CEScvlIkmBO7cpaMAo= +github.com/robotn/gohook v0.0.0-20190227143424-9bf349ed0b6d/go.mod h1:YD5RyCnUEY2xqtkkgeQVZ31UAfAnVPwUxpTE5cwSXg4= github.com/shirou/gopsutil v2.18.12+incompatible h1:1eaJvGomDnH74/5cF4CTmTbLHAriGFsTZppLXDX93OM= github.com/shirou/gopsutil v2.18.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U= diff --git a/vendor/github.com/go-ole/go-ole/.travis.yml b/vendor/github.com/go-ole/go-ole/.travis.yml index 0c2c02b..28f740c 100644 --- a/vendor/github.com/go-ole/go-ole/.travis.yml +++ b/vendor/github.com/go-ole/go-ole/.travis.yml @@ -2,8 +2,7 @@ language: go sudo: false go: - - 1.1 - - 1.2 - - 1.3 - - 1.4 + - 1.9.x + - 1.10.x + - 1.11.x - tip diff --git a/vendor/github.com/go-ole/go-ole/go.mod b/vendor/github.com/go-ole/go-ole/go.mod new file mode 100644 index 0000000..df98533 --- /dev/null +++ b/vendor/github.com/go-ole/go-ole/go.mod @@ -0,0 +1,3 @@ +module github.com/go-ole/go-ole + +go 1.12 diff --git a/vendor/github.com/lxn/win/AUTHORS b/vendor/github.com/lxn/win/AUTHORS index e93ff83..41723e3 100644 --- a/vendor/github.com/lxn/win/AUTHORS +++ b/vendor/github.com/lxn/win/AUTHORS @@ -20,6 +20,7 @@ Cary Cherng David Porter gonutz Hill +Jason A. Donenfeld Joseph Watson Kevin Pors ktye diff --git a/vendor/github.com/lxn/win/comctl32.go b/vendor/github.com/lxn/win/comctl32.go index 3e204a2..2965d78 100644 --- a/vendor/github.com/lxn/win/comctl32.go +++ b/vendor/github.com/lxn/win/comctl32.go @@ -133,6 +133,10 @@ const ( TBM_SETPOS = WM_USER + 5 TBM_SETRANGEMIN = WM_USER + 7 TBM_SETRANGEMAX = WM_USER + 8 + TBM_SETPAGESIZE = WM_USER + 21 + TBM_GETPAGESIZE = WM_USER + 22 + TBM_SETLINESIZE = WM_USER + 23 + TBM_GETLINESIZE = WM_USER + 24 ) // TrackBar (Slider) styles diff --git a/vendor/github.com/lxn/win/kernel32.go b/vendor/github.com/lxn/win/kernel32.go index 33c9c36..dba014d 100644 --- a/vendor/github.com/lxn/win/kernel32.go +++ b/vendor/github.com/lxn/win/kernel32.go @@ -84,14 +84,15 @@ var ( ) type ( - ATOM uint16 - HANDLE uintptr - HGLOBAL HANDLE - HINSTANCE HANDLE - LCID uint32 - LCTYPE uint32 - LANGID uint16 - HMODULE uintptr + ATOM uint16 + HANDLE uintptr + HGLOBAL HANDLE + HINSTANCE HANDLE + LCID uint32 + LCTYPE uint32 + LANGID uint16 + HMODULE uintptr + HWINEVENTHOOK HANDLE ) type FILETIME struct { diff --git a/vendor/github.com/lxn/win/user32.go b/vendor/github.com/lxn/win/user32.go index 5d21dae..550f16b 100644 --- a/vendor/github.com/lxn/win/user32.go +++ b/vendor/github.com/lxn/win/user32.go @@ -7,6 +7,7 @@ package win import ( + "golang.org/x/sys/windows" "syscall" "unsafe" ) @@ -875,6 +876,54 @@ const ( WM_CLIPBOARDUPDATE = 0x031D ) +// event constants +const ( + EVENT_OBJECT_CREATE = 0x8000 + EVENT_OBJECT_DESTROY = 0x8001 + EVENT_OBJECT_SHOW = 0x8002 + EVENT_OBJECT_HIDE = 0x8003 + EVENT_OBJECT_REORDER = 0x8004 + EVENT_OBJECT_FOCUS = 0x8005 + EVENT_OBJECT_SELECTION = 0x8006 + EVENT_OBJECT_SELECTIONADD = 0x8007 + EVENT_OBJECT_SELECTIONREMOVE = 0x8008 + EVENT_OBJECT_SELECTIONWITHIN = 0x8009 + EVENT_OBJECT_STATECHANGE = 0x800A + EVENT_OBJECT_LOCATIONCHANGE = 0x800B + EVENT_OBJECT_NAMECHANGE = 0x800C + EVENT_OBJECT_DESCRIPTIONCHANGE = 0x800D + EVENT_OBJECT_VALUECHANGE = 0x800E + EVENT_OBJECT_PARENTCHANGE = 0x800F + EVENT_OBJECT_HELPCHANGE = 0x8010 + EVENT_OBJECT_DEFACTIONCHANGE = 0x8011 + EVENT_OBJECT_ACCELERATORCHANGE = 0x8012 + EVENT_OBJECT_INVOKED = 0x8013 + EVENT_OBJECT_TEXTSELECTIONCHANGED = 0x8014 + EVENT_OBJECT_CONTENTSCROLLED = 0x8015 + EVENT_SYSTEM_ARRANGMENTPREVIEW = 0x8016 + EVENT_OBJECT_CLOAKED = 0x8017 + EVENT_OBJECT_UNCLOAKED = 0x8018 + EVENT_OBJECT_LIVEREGIONCHANGED = 0x8019 + EVENT_OBJECT_HOSTEDOBJECTSINVALIDATED = 0x8020 + EVENT_OBJECT_DRAGSTART = 0x8021 + EVENT_OBJECT_DRAGCANCEL = 0x8022 + EVENT_OBJECT_DRAGCOMPLETE = 0x8023 + EVENT_OBJECT_DRAGENTER = 0x8024 + EVENT_OBJECT_DRAGLEAVE = 0x8025 + EVENT_OBJECT_DRAGDROPPED = 0x8026 + EVENT_OBJECT_IME_SHOW = 0x8027 + EVENT_OBJECT_IME_HIDE = 0x8028 + EVENT_OBJECT_IME_CHANGE = 0x8029 + EVENT_OBJECT_END = 0x80ff + EVENT_AIA_START = 0xa000 + EVENT_AIA_END = 0xafff + + WINEVENT_OUTOFCONTEXT = 0x0000 + WINEVENT_SKIPOWNTHREAD = 0x0001 + WINEVENT_SKIPOWNPROCESS = 0x0002 + WINEVENT_INCONTEXT = 0x0004 +) + // mouse button constants const ( MK_CONTROL = 0x0008 @@ -1552,6 +1601,7 @@ var ( beginDeferWindowPos uintptr beginPaint uintptr callWindowProc uintptr + checkMenuRadioItem uintptr clientToScreen uintptr closeClipboard uintptr createDialogParam uintptr @@ -1580,6 +1630,7 @@ var ( getActiveWindow uintptr getAncestor uintptr getCaretPos uintptr + getClassName uintptr getClientRect uintptr getClipboardData uintptr getCursorPos uintptr @@ -1648,6 +1699,7 @@ var ( setRect uintptr setScrollInfo uintptr setTimer uintptr + setWinEventHook uintptr setWindowLong uintptr setWindowLongPtr uintptr setWindowPlacement uintptr @@ -1656,6 +1708,7 @@ var ( systemParametersInfo uintptr trackPopupMenuEx uintptr translateMessage uintptr + unhookWinEvent uintptr updateWindow uintptr windowFromDC uintptr windowFromPoint uintptr @@ -1674,6 +1727,7 @@ func init() { beginDeferWindowPos = MustGetProcAddress(libuser32, "BeginDeferWindowPos") beginPaint = MustGetProcAddress(libuser32, "BeginPaint") callWindowProc = MustGetProcAddress(libuser32, "CallWindowProcW") + checkMenuRadioItem = MustGetProcAddress(libuser32, "CheckMenuRadioItem") clientToScreen = MustGetProcAddress(libuser32, "ClientToScreen") closeClipboard = MustGetProcAddress(libuser32, "CloseClipboard") createDialogParam = MustGetProcAddress(libuser32, "CreateDialogParamW") @@ -1702,6 +1756,7 @@ func init() { getActiveWindow = MustGetProcAddress(libuser32, "GetActiveWindow") getAncestor = MustGetProcAddress(libuser32, "GetAncestor") getCaretPos = MustGetProcAddress(libuser32, "GetCaretPos") + getClassName = MustGetProcAddress(libuser32, "GetClassNameW") getClientRect = MustGetProcAddress(libuser32, "GetClientRect") getClipboardData = MustGetProcAddress(libuser32, "GetClipboardData") getCursorPos = MustGetProcAddress(libuser32, "GetCursorPos") @@ -1775,6 +1830,7 @@ func init() { setParent = MustGetProcAddress(libuser32, "SetParent") setScrollInfo = MustGetProcAddress(libuser32, "SetScrollInfo") setTimer = MustGetProcAddress(libuser32, "SetTimer") + setWinEventHook = MustGetProcAddress(libuser32, "SetWinEventHook") setWindowLong = MustGetProcAddress(libuser32, "SetWindowLongW") // On 32 bit SetWindowLongPtrW is not available if is64bit { @@ -1788,6 +1844,7 @@ func init() { systemParametersInfo = MustGetProcAddress(libuser32, "SystemParametersInfoW") trackPopupMenuEx = MustGetProcAddress(libuser32, "TrackPopupMenuEx") translateMessage = MustGetProcAddress(libuser32, "TranslateMessage") + unhookWinEvent = MustGetProcAddress(libuser32, "UnhookWinEvent") updateWindow = MustGetProcAddress(libuser32, "UpdateWindow") windowFromDC = MustGetProcAddress(libuser32, "WindowFromDC") windowFromPoint = MustGetProcAddress(libuser32, "WindowFromPoint") @@ -1854,6 +1911,18 @@ func CallWindowProc(lpPrevWndFunc uintptr, hWnd HWND, Msg uint32, wParam, lParam return ret } +func CheckMenuRadioItem(hmenu HMENU, first, last, check, flags uint32) bool { + ret, _, _ := syscall.Syscall6(checkMenuRadioItem, 5, + uintptr(hmenu), + uintptr(first), + uintptr(last), + uintptr(check), + uintptr(flags), + 0) + + return ret != 0 +} + func ClientToScreen(hwnd HWND, lpPoint *POINT) bool { ret, _, _ := syscall.Syscall(clientToScreen, 2, uintptr(hwnd), @@ -2140,6 +2209,17 @@ func GetCaretPos(lpPoint *POINT) bool { return ret != 0 } +func GetClassName(hWnd HWND, className *uint16, maxCount int) (int, error) { + ret, _, e := syscall.Syscall(getClassName, 3, + uintptr(hWnd), + uintptr(unsafe.Pointer(className)), + uintptr(maxCount)) + if ret == 0 { + return 0, e + } + return int(ret), nil +} + func GetClientRect(hWnd HWND, rect *RECT) bool { ret, _, _ := syscall.Syscall(getClientRect, 2, uintptr(hWnd), @@ -2810,6 +2890,26 @@ func SetTimer(hWnd HWND, nIDEvent uintptr, uElapse uint32, lpTimerFunc uintptr) return ret } +type WINEVENTPROC func(hWinEventHook HWINEVENTHOOK, event uint32, hwnd HWND, idObject int32, idChild int32, idEventThread uint32, dwmsEventTime uint32) uintptr + +func SetWinEventHook(eventMin uint32, eventMax uint32, hmodWinEventProc HMODULE, callbackFunction WINEVENTPROC, idProcess uint32, idThread uint32, dwFlags uint32) (HWINEVENTHOOK, error) { + ret, _, err := syscall.Syscall9(setWinEventHook, 7, + uintptr(eventMin), + uintptr(eventMax), + uintptr(hmodWinEventProc), + windows.NewCallback(callbackFunction), + uintptr(idProcess), + uintptr(idThread), + uintptr(dwFlags), + 0, 0) + + if ret == 0 { + return 0, err + } + + return HWINEVENTHOOK(ret), nil +} + func SetWindowLong(hWnd HWND, index, value int32) int32 { ret, _, _ := syscall.Syscall(setWindowLong, 3, uintptr(hWnd), @@ -2894,6 +2994,11 @@ func TranslateMessage(msg *MSG) bool { return ret != 0 } +func UnhookWinEvent(hWinHookEvent HWINEVENTHOOK) bool { + ret, _, _ := syscall.Syscall(unhookWinEvent, 1, uintptr(hWinHookEvent), 0, 0) + return ret != 0 +} + func UpdateWindow(hwnd HWND) bool { ret, _, _ := syscall.Syscall(updateWindow, 1, uintptr(hwnd), diff --git a/vendor/github.com/otiai10/gosseract/client.go b/vendor/github.com/otiai10/gosseract/client.go index 05bf17f..1558239 100644 --- a/vendor/github.com/otiai10/gosseract/client.go +++ b/vendor/github.com/otiai10/gosseract/client.go @@ -12,6 +12,7 @@ package gosseract import "C" import ( "fmt" + "image" "os" "strings" "unsafe" @@ -146,6 +147,10 @@ func (client *Client) SetLanguage(langs ...string) error { return nil } +func (client *Client) DisableOutput() error { + return client.SetVariable(DEBUG_FILE, os.DevNull) +} + // SetWhitelist sets whitelist chars. // See official documentation for whitelist here https://github.com/tesseract-ocr/tesseract/wiki/ImproveQuality#dictionaries-word-lists-and-patterns func (client *Client) SetWhitelist(whitelist string) error { @@ -204,10 +209,12 @@ func (client *Client) init() error { } defer C.free(unsafe.Pointer(configfile)) - res := C.Init(client.api, nil, languages, configfile) + errbuf := [512]C.char{} + res := C.Init(client.api, nil, languages, configfile, &errbuf[0]) + msg := C.GoString(&errbuf[0]) + if res != 0 { - // TODO: capture and vacuum stderr from Cgo - return fmt.Errorf("failed to initialize TessBaseAPI with code %d", res) + return fmt.Errorf("failed to initialize TessBaseAPI with code %d: %s", res, msg) } if err := client.setVariablesToInitializedAPI(); err != nil { @@ -260,3 +267,36 @@ func (client *Client) HOCRText() (out string, err error) { out = C.GoString(C.HOCRText(client.api)) return } + +// BoundingBox contains the position, confidence and UTF8 text of the recognized word +type BoundingBox struct { + Box image.Rectangle + Word string + Confidence float64 +} + +// GetBoundingBoxes returns bounding boxes for each matched word +func (client *Client) GetBoundingBoxes(level PageIteratorLevel) (out []BoundingBox, err error) { + if client.api == nil { + return out, fmt.Errorf("TessBaseAPI is not constructed, please use `gosseract.NewClient`") + } + if err = client.init(); err != nil { + return + } + boxArray := C.GetBoundingBoxes(client.api, C.int(level)) + length := int(boxArray.length) + defer C.free(unsafe.Pointer(boxArray.boxes)) + defer C.free(unsafe.Pointer(boxArray)) + + for i := 0; i < length; i++ { + // cast to bounding_box: boxes + i*sizeof(box) + box := (*C.struct_bounding_box)(unsafe.Pointer(uintptr(unsafe.Pointer(boxArray.boxes)) + uintptr(i)*unsafe.Sizeof(C.struct_bounding_box{}))) + out = append(out, BoundingBox{ + Box: image.Rect(int(box.x1), int(box.y1), int(box.x2), int(box.y2)), + Word: C.GoString(box.word), + Confidence: float64(box.confidence), + }) + } + + return +} diff --git a/vendor/github.com/otiai10/gosseract/constant.go b/vendor/github.com/otiai10/gosseract/constant.go index cb8e426..4c39205 100644 --- a/vendor/github.com/otiai10/gosseract/constant.go +++ b/vendor/github.com/otiai10/gosseract/constant.go @@ -39,6 +39,24 @@ const ( PSM_COUNT ) +// PageIteratorLevel maps directly to tesseracts enum tesseract::PageIteratorLevel +// represents the hierarchy of the page elements used in ResultIterator. +// https://github.com/tesseract-ocr/tesseract/blob/a18620cfea33d03032b71fe1b9fc424777e34252/ccstruct/publictypes.h#L219-L225 +type PageIteratorLevel int + +const ( + // RIL_BLOCK - Block of text/image/separator line. + RIL_BLOCK PageIteratorLevel = iota + // RIL_PARA - Paragraph within a block. + RIL_PARA + // RIL_TEXTLINE - Line within a paragraph. + RIL_TEXTLINE + // RIL_WORD - Word within a textline. + RIL_WORD + // RIL_SYMBOL - Symbol/character within a word. + RIL_SYMBOL +) + // SettableVariable represents available strings for TessBaseAPI::SetVariable. // See https://groups.google.com/forum/#!topic/tesseract-ocr/eHTBzrBiwvQ // and https://github.com/tesseract-ocr/tesseract/blob/master/ccmain/tesseractclass.h @@ -47,6 +65,8 @@ type SettableVariable string // Followings are variables which can be used for TessBaseAPI::SetVariable. // If anything missing (I know there are many), please add one below. const ( + // DEBUG_FILE - File to send output to. + DEBUG_FILE SettableVariable = "debug_file" // TESSEDIT_CHAR_WHITELIST - Whitelist of chars to recognize // There is a known issue in 4.00 with LSTM // https://github.com/tesseract-ocr/tesseract/issues/751 diff --git a/vendor/github.com/otiai10/gosseract/tessbridge.cpp b/vendor/github.com/otiai10/gosseract/tessbridge.cpp index 6287c9b..73583f1 100644 --- a/vendor/github.com/otiai10/gosseract/tessbridge.cpp +++ b/vendor/github.com/otiai10/gosseract/tessbridge.cpp @@ -7,6 +7,8 @@ #endif #include "tessbridge.h" +#include +#include TessBaseAPI Create() { tesseract::TessBaseAPI * api = new tesseract::TessBaseAPI(); @@ -34,15 +36,33 @@ int Init(TessBaseAPI a, char* tessdataprefix, char* languages) { return api->Init(tessdataprefix, languages); } -int Init(TessBaseAPI a, char* tessdataprefix, char* languages, char* configfilepath) { +int Init(TessBaseAPI a, char* tessdataprefix, char* languages, char* configfilepath, char* errbuf) { tesseract::TessBaseAPI * api = (tesseract::TessBaseAPI*)a; + + // {{{ Redirect STDERR to given buffer + fflush(stderr); + int original_stderr; + original_stderr = dup(STDERR_FILENO); + freopen("/dev/null", "a", stderr); + setbuf(stderr, errbuf); + // }}} + + int ret; if (configfilepath != NULL) { char *configs[]={configfilepath}; int configs_size = 1; - return api->Init(tessdataprefix, languages, tesseract::OEM_DEFAULT, configs, configs_size, NULL, NULL, false); + ret = api->Init(tessdataprefix, languages, tesseract::OEM_DEFAULT, configs, configs_size, NULL, NULL, false); } else { - return api->Init(tessdataprefix, languages); + ret = api->Init(tessdataprefix, languages); } + + // {{{ Restore default stderr + freopen("/dev/null", "a", stderr); + dup2(original_stderr, STDERR_FILENO); + setbuf(stderr, NULL); + // }}} + + return ret; } bool SetVariable(TessBaseAPI a, char* name, char* value) { @@ -80,6 +100,37 @@ char* HOCRText(TessBaseAPI a) { return api->GetHOCRText(0); } +bounding_boxes* GetBoundingBoxes(TessBaseAPI a, int pageIteratorLevel) { + tesseract::TessBaseAPI * api = (tesseract::TessBaseAPI*)a; + struct bounding_boxes* box_array; + box_array = (bounding_boxes*)malloc(sizeof(bounding_boxes)); + // linearly resize boxes array + int realloc_threshold = 900; + int realloc_raise = 1000; + int capacity = 1000; + box_array->boxes = (bounding_box*)malloc(capacity * sizeof(bounding_box)); + box_array->length = 0; + api->Recognize(NULL); + tesseract::ResultIterator* ri = api->GetIterator(); + tesseract::PageIteratorLevel level = (tesseract::PageIteratorLevel)pageIteratorLevel; + + if (ri != 0) { + do { + if ( box_array->length >= realloc_threshold ) { + capacity += realloc_raise; + box_array->boxes = (bounding_box*)realloc(box_array->boxes, capacity * sizeof(bounding_box)); + realloc_threshold += realloc_raise; + } + box_array->boxes[box_array->length].word = ri->GetUTF8Text(level); + box_array->boxes[box_array->length].confidence = ri->Confidence(level); + ri->BoundingBox(level, &box_array->boxes[box_array->length].x1, &box_array->boxes[box_array->length].y1, &box_array->boxes[box_array->length].x2, &box_array->boxes[box_array->length].y2); + box_array->length++; + } while (ri->Next(level)); + } + + return box_array; +} + const char* Version(TessBaseAPI a) { tesseract::TessBaseAPI * api = (tesseract::TessBaseAPI*)a; const char* v = api->Version(); diff --git a/vendor/github.com/otiai10/gosseract/tessbridge.h b/vendor/github.com/otiai10/gosseract/tessbridge.h index 3559547..c6b20e0 100644 --- a/vendor/github.com/otiai10/gosseract/tessbridge.h +++ b/vendor/github.com/otiai10/gosseract/tessbridge.h @@ -5,12 +5,24 @@ extern "C" { typedef void* TessBaseAPI; typedef void* PixImage; +struct bounding_box { + int x1,y1,x2,y2; + char* word; + float confidence; +}; + +struct bounding_boxes { + int length; + struct bounding_box* boxes; +}; + TessBaseAPI Create(void); void Free(TessBaseAPI); void Clear(TessBaseAPI); void ClearPersistentCache(TessBaseAPI); -int Init(TessBaseAPI, char*, char*, char*); +int Init(TessBaseAPI, char*, char*, char*, char*); +struct bounding_boxes* GetBoundingBoxes(TessBaseAPI, int); bool SetVariable(TessBaseAPI, char*, char*); void SetPixImage(TessBaseAPI a, PixImage pix); void SetPageSegMode(TessBaseAPI, int); diff --git a/vendor/github.com/robotn/gohook/appveyor.yml b/vendor/github.com/robotn/gohook/appveyor.yml index 7d8bfb8..43c8bc8 100644 --- a/vendor/github.com/robotn/gohook/appveyor.yml +++ b/vendor/github.com/robotn/gohook/appveyor.yml @@ -34,7 +34,7 @@ environment: PATH: C:\msys64\mingw32\bin\;C:\Program Files (x86)\NSIS\;%PATH% # - COMPILER: MINGW_W64 # ARCHITECTURE: x64 - GOVERSION: 1.11.5 + GOVERSION: 1.12 # GOPATH: c:\gopath # scripts that run after cloning repository diff --git a/vendor/modules.txt b/vendor/modules.txt index 5eb104e..04b1264 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -10,14 +10,14 @@ github.com/BurntSushi/xgbutil/xevent github.com/BurntSushi/xgbutil/xprop # github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 github.com/StackExchange/wmi -# github.com/go-ole/go-ole v1.2.2 +# github.com/go-ole/go-ole v1.2.4 github.com/go-ole/go-ole github.com/go-ole/go-ole/oleutil -# github.com/lxn/win v0.0.0-20181015143721-a7f87360b10e +# github.com/lxn/win v0.0.0-20190226192825-50e22abd4ff9 github.com/lxn/win -# github.com/otiai10/gosseract v2.2.0+incompatible +# github.com/otiai10/gosseract v2.2.1+incompatible github.com/otiai10/gosseract -# github.com/robotn/gohook v0.0.0-20190227135941-4e658a44067c +# github.com/robotn/gohook v0.0.0-20190227143424-9bf349ed0b6d github.com/robotn/gohook # github.com/shirou/gopsutil v2.18.12+incompatible github.com/shirou/gopsutil/process @@ -30,8 +30,8 @@ github.com/shirou/gopsutil/net github.com/shirou/w32 # github.com/vcaesar/imgo v0.0.0-20181209162409-13af122cf2fa github.com/vcaesar/imgo -# golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b => github.com/golang/image v0.0.0-20181116024801-cd38e8056d9b +# golang.org/x/image v0.0.0-20190227222117-0694c2d4d067 => github.com/golang/image v0.0.0-20181116024801-cd38e8056d9b golang.org/x/image/bmp -# golang.org/x/sys v0.0.0-20190109145017-48ac38b7c8cb => github.com/golang/sys v0.0.0-20190109145017-48ac38b7c8cb -golang.org/x/sys/unix +# golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e => github.com/golang/sys v0.0.0-20190109145017-48ac38b7c8cb golang.org/x/sys/windows +golang.org/x/sys/unix