2012-08-22 8 views
0

ABBYY bussiness 카드의 텍스트를 인식하면 작동합니다. 내가 찍은 사진으로해볼 때 실패했습니다. ABBYY의 데모에서 작동하므로 내 하드웨어가 아닙니다.ABBYY는 bussiness 카드 작업을 인식하지만 사진은 실패합니다.

이유가 누구인지 아시겠습니까?

코드 나는 사진을 촬영하기 위해 사용

  Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
      startActivityForResult(intent, REQUESTCODE_PHOTO); 



    if(requestCode == REQUESTCODE_PHOTO){ 
     if(resultCode == Activity.RESULT_OK){ 
      RecognizerManager.recognizeText((Bitmap)data.getExtras().get("data"), this); 


     } 
    } 


public static void recognizeText(final Bitmap bitmap, final RecognitionCallback listener){ 
     RecognitionConfiguration config = new RecognitionConfiguration(); 
     config.setRecognitionLanguages(Engine.getInstance().getLanguagesAvailableForOcr()); 
     config.setRecognitionMode(RecognitionMode.FULL); 
     config.setImageProcessingOptions(RecognitionConfiguration.ImageProcessingOptions.FIND_ALL_TEXT); 
     RecognitionManager recManager = Engine.getInstance().getRecognitionManager(config); 
     try { 
      Object o = recManager.recognizeText(bitmap, listener); 
      Log.i("RESULT!", o.toString()); 
     } catch (IllegalStateException e) { 
      e.printStackTrace(); 
     } catch (RecognitionFailedException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 

답변

0

내가이 다음 코드를 사용하여 작업을 얻었다. 내 RecognizeActivy에 복용

사진 : 내가 몇 복용 사진 후에서 OutOfMemory 예외를하지 내가 않는 경우 때문에

  final File photo = new File(Environment.getExternalStorageDirectory(), genPhotoFileName()); 
      RecognizeActivity.this.imageUri = Uri.fromFile(photo); 
      Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE) 
       .putExtra(MediaStore.EXTRA_OUTPUT, imageUri); 
      startActivityForResult(intent, REQUESTCODE_PHOTO); 

@Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     if(requestCode == REQUESTCODE_PHOTO){ 
      if(resultCode == Activity.RESULT_OK){ 
       if(this.imageUri != null){  
        try{ 
         final AssetFileDescriptor assetFileDescriptor = 
          getApplicationContext().getContentResolver().openAssetFileDescriptor(this.imageUri, "r"); 
         long imageFileSize = assetFileDescriptor.getLength(); 
         if(imageFileSize == AssetFileDescriptor.UNKNOWN_LENGTH) { 
          throw new IOException("UNKNOWN_LENGTH"); 
         } 
         InputStream is = assetFileDescriptor.createInputStream(); 
         byte[] imageData = new byte[(int) imageFileSize]; 
         is.read(imageData); 
         if(this.bitmap != null){ 
          this.bitmap.recycle(); 
          this.bitmap = null; 
          System.gc(); 
         } 
         this.bitmap = BitmapFactory.decodeByteArray(imageData, 0, (int) imageFileSize, new Options()); 
         RecognizerManager.recognizeText(this.bitmap, this); 
        } catch(Exception e){ 
         e.printStackTrace(); 
        } 
       } else{ 
        Log.e("ERROR", "img = null"); 
       } 
      } 
     } 
    } 

내가 비트 맵을 재활용하고있다.

사진 처리 : 같은 활동에 RecognitionCallback을 구현하는 경우

public static void recognizeText(final Bitmap bitmap, final RecognitionCallback progressListener){ 
    final RecognitionConfiguration config = new RecognitionConfiguration(); 

    config.setImageResolution(0); 
    config.setImageProcessingOptions(RecognitionConfiguration.ImageProcessingOptions.PROHIBIT_VERTICAL_CJK_TEXT); 
    for(RecognitionLanguage e : Engine.getInstance().getLanguagesAvailableForOcr()){ 
     if(e.equals(RecognitionLanguage.English) || e.equals(RecognitionLanguage.Dutch)){ 
      final Set<RecognitionLanguage> languages = EnumSet.noneOf(RecognitionLanguage.class); 
      languages.add(e); 
      config.setRecognitionLanguages(languages); 
     } 
    } 

    RecognitionManager recManager = Engine.getInstance().getRecognitionManager(config); 
    try { 
     Object o = recManager.recognizeText(bitmap, progressListener); 
     Log.i("RESULT!", o.toString()); 
    } catch (IllegalStateException e) { 
     e.printStackTrace(); 
    } catch (RecognitionFailedException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 
0

당신이 먼저 구현해야합니다 후 호출 recognizeText (this.bitmap이)를 대신 RecognizerManager.recognizeText의 (this.bitmap를, 이); 또한 onPrebuiltWordsInfoReady, onRecognitionProgress, onRotationTypeDetected를 구현하는 것을 잊지 마십시오.

@Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     if(requestCode == REQUESTCODE_PHOTO){ 
      if(resultCode == Activity.RESULT_OK){ 
       if(this.imageUri != null){  
        try{ 
         final AssetFileDescriptor assetFileDescriptor = 
          getApplicationContext().getContentResolver().openAssetFileDescriptor(this.imageUri, "r"); 
         long imageFileSize = assetFileDescriptor.getLength(); 
         if(imageFileSize == AssetFileDescriptor.UNKNOWN_LENGTH) { 
          throw new IOException("UNKNOWN_LENGTH"); 
         } 
         InputStream is = assetFileDescriptor.createInputStream(); 
         byte[] imageData = new byte[(int) imageFileSize]; 
         is.read(imageData); 
         if(this.bitmap != null){ 
          this.bitmap.recycle(); 
          this.bitmap = null; 
          System.gc(); 
         } 
         this.bitmap = BitmapFactory.decodeByteArray(imageData, 0, (int) imageFileSize, new Options()); 
         // CALL recognizeText(this.bitmap, this); instead of RecognizerManager.recognizeText(this.bitmap, this); 
         recognizeText(this.bitmap, this); 
        } catch(Exception e){ 
         e.printStackTrace(); 
        } 
       } else{ 
        Log.e("ERROR", "img = null"); 
       } 
      } 
     } 
    }