2017-08-28 10 views
0

Fotoapparat Libraryを使用して画像を取得してファイルに保存するアクティビティがあります。次に、Google Mobile Vision APIを使用して、そのファイルのビットマップを作成し、テキストを検出します。私はこれのために提供された標準的なコードを使用しました。Google Mobile Vision APIでポートレートモードのテキストが検出されない

TextRecognizer ocrFrame = new TextRecognizer.Builder(context).build(); 
    Frame frame = new Frame.Builder().setBitmap(BitmapFactory.decodeFile(pathToPhoto)).build(); 

    SparseArray<TextBlock> sparseTextBlocks = ocrFrame.detect(frame); 
    if (sparseTextBlocks.size() <= 0) 
     return null; 

    ArrayList<TextBlock> textBlocks = new ArrayList<>(); 
    for (int i = 0; i < sparseTextBlocks.size(); i++) { 
     textBlocks.add(sparseTextBlocks.get(sparseTextBlocks.keyAt(i))); 
    } 

OCRはランドスケープモードでは完全に機能しますが、ポートレートモードではテキストがほとんど検出されません。ポートレートモードで画像が反転していないことを画像で表示して確認しました。それは垂直の画像を与える。私は本当になぜこれが起こっているのか理解できません。任意の手がかり?ここで

答えて

3

はあなたがモジュールのbuild.gradle

dependencies { 
    compile 'com.google.android.gms:play-services-vision:9.4.0' 
} 

におけるモバイルビジョンの依存関係を含めることを確認し、また、上でこれを含める必要があり、モバイルビジョンAPI

// imageBitmap is the Bitmap image you're trying to process for text 
if(imageBitmap != null) { 

    TextRecognizer textRecognizer = new TextRecognizer.Builder(this).build(); 

    if(!textRecognizer.isOperational()) { 
     // Note: The first time that an app using a Vision API is installed on a 
     // device, GMS will download a native libraries to the device in order to do detection. 
     // Usually this completes before the app is run for the first time. But if that 
     // download has not yet completed, then the above call will not detect any text, 
     // barcodes, or faces. 
     // isOperational() can be used to check if the required native libraries are currently 
     // available. The detectors will automatically become operational once the library 
     // downloads complete on device. 
     Log.w(LOG_TAG, "Detector dependencies are not yet available."); 

     // Check for low storage. If there is low storage, the native library will not be 
     // downloaded, so detection will not become operational. 
     IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); 
     boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null; 

     if (hasLowStorage) { 
      Toast.makeText(this,"Low Storage", Toast.LENGTH_LONG).show(); 
      Log.w(LOG_TAG, "Low Storage"); 
     } 
    } 


    Frame imageFrame = new Frame.Builder() 
      .setBitmap(imageBitmap) 
      .build(); 

    SparseArray<TextBlock> textBlocks = textRecognizer.detect(imageFrame); 

    for (int i = 0; i < textBlocks.size(); i++) { 
     TextBlock textBlock = textBlocks.get(textBlocks.keyAt(i)); 

     Log.i(LOG_TAG, textBlock.getValue()); 
     // Do something with value 
    } 
} 

を実装するための別の代替でありますアプリのAndroidマニフェスト

<meta-data 
    android:name="com.google.android.gms.vision.DEPENDENCIES" 
    android:value="ocr" /> 

あなたのライブラリーが保存する写真の向きがMobile Vision APIと競合する可能性があると思います。アプリがまだ動作していない場合は、横のプロジェクトや別のライブラリーでネイティブのAndroidキャプチャーを使用してみてください。彼らは助けることができるの肖像画で撮影されている場合でも、同様

+1

はありがとう、それがお役に立てば幸い!はい、あなたは正しいです。 FotoApparatは、Mobile Vision APIと競合する画像の向きを保存していました。マトリックスを回転させることで修正しました。どうもありがとうございます! –

+0

ありがとうございました!撮った写真も間違って回転してしまい、やっと私はそれを理解しました。とても素敵! – Trickzter

関連する問題