首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tesseract在android中识别阿拉伯文本

Tesseract在android中识别阿拉伯文本
EN

Stack Overflow用户
提问于 2017-04-16 12:40:30
回答 1查看 2.5K关注 0票数 0

我正在开发一个应用程序,我使用Tesseract OCR来识别图像中的文本。我测试了它的英语和日语,它运行良好,但当我尝试阿拉伯语应用程序崩溃,甚至在启动!为什么?

阿拉伯语和Tesseract OCR有什么问题?谁能告诉我吗?

代码:

代码语言:javascript
复制
    public class MainActivity extends AppCompatActivity {

Bitmap image;
private TessBaseAPI mTess;
String datapath = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //init image
    image = BitmapFactory.decodeResource(getResources(), R.drawable.test_ara);

    //initialize Tesseract API
    String language = "ra";
    datapath = getFilesDir()+ "/tesseract/";
    mTess = new TessBaseAPI();

    checkFile(new File(datapath + "tessdata/"));

    mTess.init(datapath, language);
}

public void processImage(View view){
    String OCRresult = null;
    mTess.setImage(image);
    OCRresult = mTess.getUTF8Text();
    TextView OCRTextView = (TextView) findViewById(R.id.OCRTextView);
    OCRTextView.setText(OCRresult);
}

private void checkFile(File dir) {
    if (!dir.exists()&& dir.mkdirs()){
            copyFiles();
    }
    if(dir.exists()) {
        String datafilepath = datapath+ "/tessdata/ara.traineddata";
        File datafile = new File(datafilepath);

        if (!datafile.exists()) {
            copyFiles();
        }
    }
}

private void copyFiles() {
    try {
        String filepath = datapath + "/tessdata/ara.traineddata";
        AssetManager assetManager = getAssets();

        InputStream instream = assetManager.open("tessdata/ara.traineddata");
        OutputStream outstream = new FileOutputStream(filepath);

        byte[] buffer = new byte[1024];
        int read;
        while ((read = instream.read(buffer)) != -1) {
            outstream.write(buffer, 0, read);
        }


        outstream.flush();
        outstream.close();
        instream.close();

        File file = new File(filepath);
        if (!file.exists()) {
            throw new FileNotFoundException();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
}

我得到的错误:

代码语言:javascript
复制
   04-16 18:37:08.451 7405-7405/com.imperialsoupgmail.tesseractexample A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 7405 (esseractexample)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-16 13:44:59

对于阿拉伯语,您需要使用Cube:使用init()引擎模式调用OEM_CUBE_ONLY,并使用Cube 数据文件

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43437342

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档