机器人的tesseract OCR强制关闭机器人、tesseract、OCR

2023-09-07 10:47:35 作者:恋变

我开发,使用机器人的tesseract库函数的应用程序。我成功地编译的tesseract库,并导入到我的工作区。然后,我库引用添加到我的app.But这个方法,我写了近原因力:

I am developing an app that using tesseract android library functions. I succesfully compile the tesseract library and imported to my workspace. then I add the library reference to my app.But this method that I wrote causes the force close:

 public static String BitmapOku (Bitmap image){
            Bitmap image2=image.copy(Bitmap.Config.ARGB_8888, true);
    TessBaseAPI baseApi = new TessBaseAPI();
    baseApi.init("/mnt/sdcard/tessdata/eng.traineddata", "eng"); 
    baseApi.setImage(image2);
    String recognizedText = baseApi.getUTF8Text(); 
    baseApi.end();
return recognizedText;

我的问题是---我必须做什么的问题用的tesseract的Andr​​oid应用OCR审议和我要在我的应用程序进行图像处理functios - 例如rotating-使用leptonica工具(因为我用opencv的2.4。 0)?

my question is---> what issues do I have to consider with a tesseract android ocr app and do I have to use leptonica tool in my app for image processing functios -for example rotating- (because I use Opencv 2.4.0)?

推荐答案

有时候,即使语言文件被插入到SD卡,存在它不会被正确检测到的可能性。因此,对于有效地建立在SD卡的文件中,以下code可以是有用的。

sometimes , even if the language file is inserted in the sdcard, there is a possibility that it wont be detected properly . So for efficiently establishing the file in the sdcard , following code may be useful.

字符串DIRC = Environment.getExternalStorageDirectory()的getPath()的toString()。

String dirc= Environment.getExternalStorageDirectory().getPath().toString();

      String[] paths = new String[] { dirc,dirc + "/tessdata/" };

            for (String path :paths ) {
            File dir = new File(path);
            if (!dir.exists()) {
                if (!dir.mkdirs()) {
                   System.out.println("Creation of directory  on sdcard failed");

                } else {
                     System.out.println("Creation of directory  on sdcard successful");
                }
            }

        }

        // lang.traineddata file with the app (in assets folder)
                // You can get them at:
                // http://code.google.com/p/tesseract-ocr/downloads/list
                // This area needs work and optimization
                if (!(new File(dirc + "/tessdata/" + "eng.traineddata")).exists()) {
                    try {

                        AssetManager assetManager = getAssets();
                        InputStream in = assetManager.open("tessdata/eng.traineddata");
                        //GZIPInputStream gin = new GZIPInputStream(in);
                        OutputStream out = new FileOutputStream(dirc + "/tessdata/eng.traineddata");

                        // Transfer bytes from in to out
                        byte[] buf = new byte[1024];
                        int len;
                        //while ((lenf = gin.read(buff)) > 0) {
                        while ((len = in.read(buf)) > 0) {
                            out.write(buf, 0, len);
                        }
                        in.close();
                        //gin.close();
                        out.close();

                      System.out.println("copied eng.traineddata");;
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

在这里,语言文件eng.traineddata被添加到项目中的资产文件夹。在资产文件夹,创建一个文件夹tessdata并把eng.traineddata的文件夹中。

here , the language file eng.traineddata is added to the assets folder in the project . in assets folder, create a tessdata folder and put eng.traineddata in the folder ..

希望这能解决你的问题。

hope this solves your problem.