Search code examples
goocr

Gosseract not run


# 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 (
    "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)

}

Solution

  • 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 && 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
    

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