Gosseract无法运行。

huangapple go评论83阅读模式
英文:

Gosseract not run

问题

以下是我翻译好的内容:

// github.com/otiai10/gosseract/v2
tessbridge.cpp:5:10: 致命错误: leptonica/allheaders.h: 没有那个文件或目录
    5 | #include <leptonica/allheaders.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
编译终止

下面是我编写的代码

它出现了一个错误我重新安装了Tesseract-i但仍然出现相同的错误

```go
package main

import (
	"fmt"

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

func main() {

	client := gosseract.NewClient()

	defer client.Close()

	client.SetImage("C:\\Users\\labusers\\Downloads\\khan.png")

	text, _ := client.Text()
	fmt.Println(text)

}
英文:

# 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.

below is the code i wrote

it gives an error. I reinstalled Tesseract-i, it still gives the same error

package main

import (
	&quot;fmt&quot;

	&quot;github.com/otiai10/gosseract/v2&quot;
)

func main() {

	client := gosseract.NewClient()

	defer client.Close()

	client.SetImage(&quot;C:\\Users\\labusers\\Downloads\\khan.png&quot;)

	text, _ := client.Text()
	fmt.Println(text)

}

答案1

得分: 2

安装Tesseract可能会有些棘手。以下是一个可行的Dockerfile:

FROM golang:1.14.9

RUN cat /etc/os-release
# 输出:Debian GNU/Linux 10 (buster)
RUN apt-get -qy update

RUN apt-get install -qy libleptonica-dev libtesseract-dev
RUN apt-get install -qy libtool m4 automake cmake pkg-config
RUN apt-get install -qy libicu-dev libpango1.0-dev libcairo-dev

RUN cd /opt && git clone https://github.com/tesseract-ocr/tesseract
WORKDIR /opt/tesseract
RUN git reset --hard 4.1.1
RUN ./autogen.sh &&\
    ./configure --enable-debug LDFLAGS="-L/usr/local/lib" CFLAGS="-I/usr/local/include"
RUN make -j 8
RUN make install && ldconfig
RUN tesseract --version

ENV TESSDATA_PREFIX=/usr/local/share/tessdata
ENV TESSDATA_REPO=https://github.com/tesseract-ocr/tessdata_best
WORKDIR ${TESSDATA_PREFIX}
RUN wget -q ${TESSDATA_REPO}/raw/4.1.0/eng.traineddata

这个Dockerfile从源代码构建Tesseract,所以你可以选择Tesseract的版本。我是在两年前使用gosseract库时编写的这个Dockerfile。

英文:

Installing Tesseract can be tricky. The following Dockerfile works:

FROM golang:1.14.9

RUN cat /etc/os-release
# Output: Debian GNU/Linux 10 (buster)
RUN apt-get -qy update

RUN apt-get install -qy libleptonica-dev libtesseract-dev
RUN apt-get install -qy libtool m4 automake cmake pkg-config
RUN apt-get install -qy libicu-dev libpango1.0-dev libcairo-dev

RUN cd /opt &amp;&amp; git clone https://github.com/tesseract-ocr/tesseract
WORKDIR /opt/tesseract
RUN git reset --hard 4.1.1
RUN ./autogen.sh &amp;&amp;\
    ./configure --enable-debug LDFLAGS=&quot;-L/usr/local/lib&quot; CFLAGS=&quot;-I/usr/local/include&quot;
RUN make -j 8
RUN make install &amp;&amp; ldconfig
RUN tesseract --version

ENV TESSDATA_PREFIX=/usr/local/share/tessdata
ENV TESSDATA_REPO=https://github.com/tesseract-ocr/tessdata_best
WORKDIR ${TESSDATA_PREFIX}
RUN wget -q ${TESSDATA_REPO}/raw/4.1.0/eng.traineddata

The Dockerfile build Tesseract from source so you can choose Tesseract version. I wrote this Dockerfile when I used gosseract library 2 years ago.

huangapple
  • 本文由 发表于 2023年1月25日 18:28:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75232599.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定