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
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);
}
@Override
public void draw(Canvas canvas) {
TextBlock text = mText;
if (text == null) {
return;
}
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);
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
RectF rect = new RectF(0,0,800,600);