Как запустить скрипт с Tesseract OCR на Golang?

ПК работает на ОС Windows. Установил Tesseract OCR, с этим всё нормально. Использовать Tesseract OCR хочу с помощью gosseract. При компиляции проекта выдает ошибку:

PS F:\go-projects\github.com\fentezi\teseract> go run main.go
github.com/otiai10/gosseract/v2
tessbridge.cpp:5:10: fatal error: leptonica/allheaders.h: No such file or directory
5 | #include <leptonica/allheaders.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

package main

import (
    "fmt"

    "github.com/otiai10/gosseract/v2"
)

func main() {
    client := gosseract.NewClient()

    defer client.Close()

    err := client.SetImage("test.png")
    if err != nil {
        return
    }

    text, err := client.Text()
    if err != nil {
        return
    }

    fmt.Println(text)
}

Одну ошибку решил, но появилась другая.

F:\Go\pkg\tool\windows_amd64\link.exe: running g++ failed: exit status 1
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lleptonica
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ltesseract
collect2.exe: error: ld returned 1 exit status

go env

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\serou\AppData\Local\go-build
set GOENV=C:\Users\serou\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\serou\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\serou\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=F:\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=F:\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.4
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=F:\go-projects\github.com\fentezi\teseract\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=-I C:\Users\serou\source\repos\vcpkg\installed\x64-windows\include
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-L C:\Users\serou\source\repos\vcpkg\installed\x64-windows\lib
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\serou\AppData\Local\Temp\go-build1738487088=/tmp/go-build -gno

После этого еще одна ошибка:

F:\Go\pkg\tool\windows_amd64\link.exe: running g++ failed: exit status 1
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `Create':
C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:14: undefined reference to `tesseract::TessBaseAPI::TessBaseAPI()'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `Free':
C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:21: undefined reference to `tesseract::TessBaseAPI::End()'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `tesseract::TessBaseAPI::Init(char const*, char const*)':
C:/Users/serou/source/repos/vcpkg/installed/x64-windows/include/tesseract/baseapi.h:206: undefined reference to `tesseract::TessBaseAPI::Init(char const*, char const*, tesseract::OcrEngineMode, char**, int, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const*, bool)'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/serou/source/repos/vcpkg/installed/x64-windows/include/tesseract/baseapi.h:206: undefined reference to `tesseract::TessBaseAPI::Init(char const*, char const*, tesseract::OcrEngineMode, char**, int, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const*, bool)'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `SetPixImage':
C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:81: undefined reference to `tesseract::TessBaseAPI::SetImage(Pix*)'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:82: undefined reference to `tesseract::TessBaseAPI::GetSourceYResolution()'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `GetBoundingBoxesVerbose':
C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:119: undefined reference to `tesseract::TessBaseAPI::Recognize(tesseract::ETEXT_DESC*)'   
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:125: undefined reference to `tesseract::TessBaseAPI::GetIterator()'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:156: undefined reference to `tesseract::LTRResultIterator::Confidence(tesseract::PageIteratorLevel) const'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:157: undefined reference to `tesseract::PageIterator::BoundingBox(tesseract::PageIteratorLevel, int*, int*, int*, int*) const'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:126: undefined reference to `tesseract::PageIterator::Empty(tesseract::PageIteratorLevel) const'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:127: undefined reference to `tesseract::PageIterator::Empty(tesseract::PageIteratorLevel) const'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `GetBoundingBoxes':
C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:183: undefined reference to `tesseract::TessBaseAPI::Recognize(tesseract::ETEXT_DESC*)'   
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:184: undefined reference to `tesseract::TessBaseAPI::GetIterator()'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:195: undefined reference to `tesseract::LTRResultIterator::Confidence(tesseract::PageIteratorLevel) const'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:196: undefined reference to `tesseract::PageIterator::BoundingBox(tesseract::PageIteratorLevel, int*, int*, int*, int*) const'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `tesseract::TessBaseAPI::Init(char const*, char const*)':
C:/Users/serou/source/repos/vcpkg/installed/x64-windows/include/tesseract/baseapi.h:206: undefined reference to `tesseract::TessBaseAPI::Init(char const*, char const*, tesseract::OcrEngineMode, char**, int, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const*, bool)'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `GetDataPath':
C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:227: undefined reference to `tesseract::TessBaseAPI::TessBaseAPI()'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `Clear':
C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:29: undefined reference to `tesseract::TessBaseAPI::Clear()'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `ClearPersistentCache':
C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:35: undefined reference to `tesseract::TessBaseAPI::ClearPersistentCache()'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `SetVariable':
C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:75: undefined reference to `tesseract::TessBaseAPI::SetVariable(char const*, char const*)'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `SetPixImage':
C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:83: undefined reference to `tesseract::TessBaseAPI::SetSourceResolution(int)'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `SetPageSegMode':
C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:90: undefined reference to `tesseract::TessBaseAPI::SetPageSegMode(tesseract::PageSegMode)'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `GetPageSegMode':
C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:95: undefined reference to `tesseract::TessBaseAPI::GetPageSegMode() const'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `UTF8Text':
C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:100: undefined reference to `tesseract::TessBaseAPI::GetUTF8Text()'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `HOCRText':
C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:105: undefined reference to `tesseract::TessBaseAPI::GetHOCRText(int)'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `Version':
C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:207: undefined reference to `tesseract::TessBaseAPI::Version()'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `GetDataPath':
C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:229: undefined reference to `tesseract::TessBaseAPI::GetDatapath()'
F:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\serou\AppData\Local\Temp\go-link-1749183323\000003.o: in function `__tcf_0':
C:\Users\serou\go\pkg\mod\github.com\otiai10\gosseract\[email protected]/tessbridge.cpp:227: undefined reference to `tesseract::TessBaseAPI::~TessBaseAPI()'
collect2.exe: error: ld returned 1 exit status

Ответы (0 шт):