Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using google OCR image to text api. Because i want to store food menu in my database. But TextRecognizer can only detect TextBlocks. i want to scan column wise so i can get food dish name and its price same time so it will be easy for me to store it into database.

OcrCaptureActivity
// this method display which block has been clicked and display it into textview

private boolean onTap(float rawX, float rawY) {
      OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY);
      TextBlock text = null;
      if (graphic != null) {
          text = graphic.getTextBlock();
          if (text != null && text.getValue() != null) {
              Intent data = new Intent();
              data.putExtra(TextBlockObject, text.getValue());
              setResult(CommonStatusCodes.SUCCESS, data);
              finish();
          }
          else {
              Log.d(TAG, "text data is null");
          }
      }
      else {
          Log.d(TAG,"no text detected");
      }
      return text != null;
  }

OcrGraphic Class
/**
     * Checks whether a point is within the bounding box of this graphic.
     * The provided point should be relative to this graphic's containing overlay.
     * @param x An x parameter in the relative context of the canvas.
     * @param y A y parameter in the relative context of the canvas.
     * @return True if the provided point is contained within this graphic's bounding box.
     */
 
 public boolean contains(float x, float y) {
        TextBlock text = mText;
        if (text == null) {
            return false;
        }
        RectF rect = new RectF(text.getBoundingBox());
        rect.left = translateX(rect.left);
        rect.top = translateY(rect.top);
        rect.right = translateX(rect.right);
        rect.bottom = translateY(rect.bottom);
        return (rect.left < x && rect.right > x && rect.top < y && rect.bottom > y);
    }
 
    /**
     * Draws the text block annotations for position, size, and raw value on the supplied canvas.
     */
    @Override
    public void draw(Canvas canvas) {
        TextBlock text = mText;
        if (text == null) {
            return;
        }
 
        // Draws the bounding box around the TextBlock.
        RectF rect = new RectF(text.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);
 
        // Break the text into multiple lines and draw each one according to its own bounding box.
        List<? extends Text> textComponents = text.getComponents();
        for(Text currentText : textComponents) {
            float left = translateX(currentText.getBoundingBox().left);
            float bottom = translateY(currentText.getBoundingBox().bottom);
            canvas.drawText(currentText.getValue(), left, bottom, sTextPaint);
        }
    }
}


What I have tried:

i have tried to set width and hight of the bouding box but it still taking text as text box
Java
RectF rect = new RectF(0,0,800,600); 
Posted
Updated 7-Mar-18 7:10am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900