2016-08-04 2 views
0

Я начал с изучения учебника Text API, чтобы обнаружить TextBlocks, который отлично работал. Но теперь я хочу обнаружить текстовые строки и столкнулся с проблемой.TextRecognizer может обнаруживать только текстовые блокировки

// TODO: Create the TextRecognizer 
    TextRecognizer textRecognizer = new TextRecognizer.Builder(context).build(); 
    // TODO: Set the TextRecognizer's Processor. 
    textRecognizer.setProcessor(new OcrDetectorProcessor(mGraphicOverlay)); 

textRecognizer.setПроцессор может использовать только TextBlock. Есть ли способ обнаружить линии?

ответ

0

Решение, которое я придумал, идя от ответа Педро Мадейры, был таков:

List<? extends Text> textComponents = mText.getComponents(); 
    for (Text currentText : textComponents) { 
     RectF rect = new RectF(currentText.getBoundingBox()); 
     rect.left = translateX(rect.left); 
     rect.top = translateY(rect.top); 
     rect.right = translateX(rect.right); 
     rect.bottom = translateY(rect.bottom); 
     canvas.drawRect(rect, sRectPaint); 
+0

Однако я до сих пор не имею ни малейшего представления о том, как я могу использовать каждую отдельную строку и что-то выдавать. – GeeSplit

0

Этот учебник (https://codelabs.developers.google.com/codelabs/mobile-vision-ocr/#6) говорит, что «двигатель ставит все текст он признает в TextBlock в один полный приговор, даже если он видит, что предложение сломана на несколько строк.»

«Вы можете получить Lines от TextBlock по телефону getComponents, а затем вы можете перебирать каждую строку, чтобы получить расположение и значение текста в нем. Это позволяет поместить текст в том месте, на самом деле появляется. "

// Break the text into multiple lines and draw each one according to its own bounding box. 
List<? extends Text> textComponents = mText.getComponents(); 
for(Text currentText : textComponents) { 
    float left = translateX(currentText.getBoundingBox().left); 
    float bottom = translateY(currentText.getBoundingBox().bottom); 
    canvas.drawText(currentText.getValue(), left, bottom, sTextPaint); 
} 
+0

Да, это то, что он делает сейчас. Но я хочу, чтобы иметь возможность рисовать очертающую рамку вокруг каждой «Линии» вместо всего «TextBlock». Таким образом, пользователь может использовать каждую отдельную линию. – GeeSplit

1

использовать этот один: List<Line> lines = (List<Line>) text.getComponents(); for(Line elements : lines){ Log.i("current lines ", ": " + elements.getValue()); }

0

Нажмите Here, чтобы прочитать полный код. Надеюсь, это поможет вам.

Bitmap bitmap = decodeBitmapUri(this, imageUri); 
      if (detector.isOperational() && bitmap != null) { 
       Frame frame = new Frame.Builder().setBitmap(bitmap).build(); 
       SparseArray<TextBlock> textBlocks = detector.detect(frame); 
       String blocks = ""; 
       String lines = ""; 
       String words = ""; 
       for (int index = 0; index < textBlocks.size(); index++) { 
        //extract scanned text blocks here 
        TextBlock tBlock = textBlocks.valueAt(index); 
        blocks = blocks + tBlock.getValue() + "\n" + "\n"; 
        for (Text line : tBlock.getComponents()) { 
         //extract scanned text lines here 
         lines = lines + line.getValue() + "\n"; 
         for (Text element : line.getComponents()) { 
          //extract scanned text words here 
          words = words + element.getValue() + ", "; 
         } 
        } 
Смежные вопросы