0

I followed the OCR text reader guide on Codelabs (https://codelabs.developers.google.com/codelabs/mobile-vision-ocr/#0). Now, I would like to save, a single portion of the text that I am scanning. I tried with reducing width, and height of the preview; but it doesn't work, the APK crashes (at least on the only device I have to test it). I am completely new to Java, and Android development, but my Internship mentor said to do this; completely alone, with zero help (as no one in the company knows about development).

So, the app opens, it recognizes text. Now, I would like to to know if there is a way to take that text, and save it (XML or TXT file). I tried to look in the code, and see if at some point, the text read is saved in a variable or something; but it looks like a live preview, done trough the Google's dependencies (or a similar process).

I am not sure, but this might be off topic, as it is similar to an open question, but I am giving details on what I have done so far, and what I have tried.

Thanks.

Rakib
  • 3
  • 4
  • (code can be found on the codelabs link, they also have the entire zip file. If you don't trust the link just google it). I thought about putting the code here, but it is too long, and because I am new, I don't know which file are important. – Rakib Aug 15 '18 at 13:02
  • Thanks for replying, but on the page I don't find anything about looping it, or using TextBlock#getValue(). Can you send the link? Thanks – Rakib Aug 16 '18 at 09:22

1 Answers1

0

The detected text is displayed in the OcrGraphic.draw(Canvas) method. There, it is returned as a TextBlock. You can call textBlock.getComponents() to get the lines and textBlock.getComponents() again to get each individual word (as a Text object).

Then you can convert it to a string and write the text to a file if you would like.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
moisu
  • 343
  • 2
  • 10