I have an activity which uses the Fotoapparat Library to obtain a picture and save it to a file. Next I use Google Mobile Vision API to create a bitmap of that file and detect text. I have used the standard code provided for this.
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)));
}
The OCR works perfectly in landscape mode but in portrait mode it hardly detects any text. I have verified by displaying the image that the image is not inverted in portrait mode. It gives a vertical image. I really can not figure out why this is happening. any clues?
Here is another alternative for implementing the Mobile Vision API
You need to ensure you include the mobile vision dependency in the module's build.gradle
And also include this on the app's Android Manifest
Overall your code looks fine, i think it could be the way your library saves the orientation of the pictures could conflicting with the Mobile Vision API, try using native android captures on a side project or another library, if your app still not working try saving the still in landscape even if they are taken on portrait that could help as well
Hope it helps