Tesseract运行错误

问题描述 投票:56回答:9

我在linux上运行tesseract-ocr引擎时遇到问题。我已经下载了RUS语言数据并将其放到tessdata目录(/ usr / local / share / tessdata)。当我尝试使用命令tesseract blob.jpg out -l rus运行tesseract时,它会显示错误:

Error opening data file /usr/local/share/tessdata/eng.traineddata

Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory.

Failed loading language eng
Tesseract couldn't load any languages!

Could not initialize tesseract.

根据compiling guide,我使用export TESSDATA_PREFIX='/usr/local/share/' 指向我的tessdata目录。也许我应该编辑任何配置文件? Tesseract尝试加载'eng'数据文件而不是'rus'。

屏幕截图:http://i.stack.imgur.com/I0Guc.png

ocr tesseract
9个回答
64
投票

你可以从谷歌抓住eng.traineddata(压缩):

wget https://tesseract-ocr.googlecode.com/files/eng.traineddata.gz

或Github(原始):

wget https://github.com/tesseract-ocr/tessdata/raw/master/eng.traineddata

查看https://github.com/tesseract-ocr/tessdata以获取经过培训的语言数据的完整列表。

抓取文件时,将它们移动到/usr/local/share/tessdata文件夹。警告:一些Linux发行版(例如openSUSE和Ubuntu)可能会在/usr/share/tessdata中期待它。

# If you got the data from Google, unzip it first!
gunzip eng.traineddata.gz 
# Move the data
sudo mv -v eng.traineddata /usr/local/share/tessdata/

35
投票

最简单的方法是安装所需的包:

sudo apt-get install tesseract-ocr-eng  #for english
sudo apt-get install tesseract-ocr-tam  #for tamil
sudo apt-get install tesseract-ocr-deu  #for deutsch (German)

正如您所注意到的,它打开了通往其他语言的道路(即tesseract-ocr-fra)。


17
投票

我在Windows机器上也遇到了这个错误。

我的解决方案

1)从https://github.com/tesseract-ocr/tessdata/tree/3.04.00下载您的语言文件

例如,对于eng,我下载了所有带有eng前缀的文件。

2)将它们放入某个文件夹内的tessdata目录中。将此文件夹作为TESSDATA_PREFIX添加到系统路径变量中。

结果将是System env var:TESSDATA_PREFIX = D:/ Java / OCR和OCR文件夹包含带语言文件的tessdata。

这是目录的屏幕截图:

enter image description here


4
投票

没有以前的解决方案适合我。

我已经安装了apt-get和手动下载tessdata,移动/usr等等,即使我导出变量千次也没有人工作。

最后,在开始哭之前的最后一次尝试中,我试图将路径直接传递给Tesseract()的实例。

在Python:tr = Tesseract("/usr/local/share/tesseract-ocr/"),现在它的工作原理。为了澄清,我使用tesserwrap模块。


2
投票

您可以从C代码调用tesseract API函数:

#include <tesseract/baseapi.h>
#include <tesseract/ocrclass.h>; // ETEXT_DESC

using namespace tesseract;

class TessAPI : public TessBaseAPI {
    public:
    void PrintRects(int len);
};

...
TessAPI *api = new TessAPI();
int res = api->Init(NULL, "rus");
api->SetAccuracyVSpeed(AVS_MOST_ACCURATE);
api->SetImage(data, w0, h0, bpp, stride);
api->SetRectangle(x0,y0,w0,h0);

char *text;
ETEXT_DESC monitor;
api->RecognizeForChopTest(&monitor);
text = api->GetUTF8Text();
printf("text: %s\n", text);
printf("m.count: %s\n", monitor.count);
printf("m.progress: %s\n", monitor.progress);

api->RecognizeForChopTest(&monitor);
text = api->GetUTF8Text();
printf("text: %s\n", text);
...
api->End();

并构建此代码:

g++ -g -I. -I/usr/local/include -o _test test.cpp -ltesseract_api -lfreeimageplus

(我需要FreeImage来加载图片)


1
投票

我正在使用Visual Studio 2017社区版。 我通过在项目的Debug目录中创建一个名为tessdata的目录来解决这个问题。然后我将eng.traineddata文件放入所述目录。


0
投票
tesseract  --tessdata-dir <tessdata-folder> <image-path> stdout --oem 2 -l <lng>

就我而言,我所犯的错误或尝试都没有成功。

  • 我克隆了github repo并从那里复制了文件 在/ usr / local / share下/ tessdata / 的/ usr /共享/的tesseract-OCR / tessdata / 的/ usr /共享/ tessdata /
  • 使用上面的路径TESSDATA_PREFIX
  • sudo apt-get install tesseract-ocr-eng

前两次尝试没有奏效,因为来自git clone的文件由于我不知道的原因而无效。我不确定为什么#3尝试对我有用。

最后,

  1. 我使用wget下载了eng.traindata文件
  2. 将其复制到某个文件夹
  3. 使用--tessdata-dir文件夹名称

带走我的是学好工具并使用它,而不是依赖于包管理器安装和文件夹


0
投票

我正在使用Windows操作系统,我尝试了上面的所有解决方案,但没有一个工作。

最后,我在D驱动器(我从哪里运行我的python脚本)而不是C驱动器上安装Tesseract-OCR,它可以工作。

因此,如果您使用的是Windows,请在与Tesseract-OCR相同的驱动器中运行您的python脚本。


-1
投票

C:\ Users \用户pankaj.neupaney \应用程序数据\本地\连续\ anaconda3 \ ENVS \ ocrtextrecog \ LIB \站点包\ tesserocr

添加你的tesssdatahere

© www.soinside.com 2019 - 2024. All rights reserved.