2012-05-15 2 views
-1

tesseract 안드로이드 라이브러리 함수를 사용하여 응용 프로그램을 개발 중입니다. 필자는 tesseract 라이브러리를 성공적으로 컴파일하고 내 작업 영역으로 가져 왔습니다. 나는 내가 힘 가까운 원인을 쓴 내 app.But이 방법으로 라이브러리 참조를 추가 :android tesseract ocr 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; 

내 질문은 ---> 나는 정팔 포체 안드로이드 OCR 응용 프로그램으로 고려해야하고 할 일을 문제 이미지 처리 기능을 위해 내 응용 프로그램에서 leptonica 도구를 사용해야합니다 (예 : 회전식) (Opencv 2.4.0을 사용하기 때문에)?

+0

내가 실수하지 않으면 그림은 .tiff 형식이어야합니다. – sschrass

답변

0

가끔 언어 파일이 sdcard에 삽입 되더라도 제대로 감지되지 않을 가능성이 있습니다. 따라서 sdcard에 파일을 효율적으로 설정하려면 다음 코드가 유용 할 수 있습니다.

문자열 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가 프로젝트의 assets 폴더에 추가됩니다. assets 폴더에 tessdata 폴더를 만들고 eng.traineddata를 폴더에 넣습니다.

희망이 문제를 해결했습니다.

관련 문제