2017-04-16 82 views
0

我正在开发一个应用程序,我使用Tesseract OCR识别图像中的文本。我测试了英文和日文,它工作正常,但是当我尝试使用阿拉伯语时,应用程序甚至在启动之前崩溃!为什么?Tesseract在android中识别阿拉伯语文本

阿拉伯语和Tesseract OCR有什么问题?有人可以告诉我吗?

代码:

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(); 
    } 
} 
} 

我得到的错误:

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) 
+1

当崩溃时发布确切的错误文本。 – sashoalm

+0

@sashoalm刚刚发布了它。 –

回答

1

对于阿拉伯语,你需要使用魔方:使用OEM_CUBE_ONLY引擎模式调用init()和使用多维数据集data files

+0

我刚刚发布了代码,您能否告诉我应该在哪里更改以及如何修改?或者是否有任何有关如何使用Cube的好例子? –

+0

谢谢!现在它工作:)但承认是错误的!你知道为什么吗? –

+0

我不能说没有更多的信息。问一个新的问题,并包括所有的细节。 – rmtheis