Pankaj Srivastava
Pankaj Srivastava

Reputation: 11

TableBoundHints in Google Cloud Document AI not working

I am trying to give a hint in Document AI to get table only in specific area. but it is not working.

TableBoundHint tableBoundHints = TableBoundHint.newBuilder()
                    .setBoundingBox(BoundingPoly.newBuilder()
//                   top left
                    .addNormalizedVertices(NormalizedVertex.newBuilder().setX(0).setX(0).build())
//                   top right
                    .addNormalizedVertices(NormalizedVertex.newBuilder().setX(1).setX(0).build())
//                   bottom right
                    .addNormalizedVertices(NormalizedVertex.newBuilder().setX(1).setX(0.25f).build())
//                   bottom left
                    .addNormalizedVertices(NormalizedVertex.newBuilder().setX(0).setX(0.25f).build()).build())
                    .setPageNumber(1)
                    .build();

Am I doing it wrong or since it is in beta phase so it is not working?

Upvotes: 1

Views: 303

Answers (2)

Holt Skinner
Holt Skinner

Reputation: 2234

FYI, there is an actively monitored tag for Document AI [cloud-document-ai]


Document AI became Generally Available in 2021, and the v1 API was released. The API behavior and output has changed significantly between v1beta2 and the current GA version v1. It's recommended to use the v1 API for all activity going forward.

TableBoundHint is no longer supported in the GA version.

The Form Parser is designed for recognizing form fields as key-value pairs and tables in documents. The documentation has been recently updated to show how to handle the processing response from the Form Parser to recognize Tables in the document.

https://cloud.google.com/document-ai/docs/handle-response#forms_and_tables

Upvotes: 0

Noe Romero
Noe Romero

Reputation: 400

According to your code snippet, you're only setting the "x" coordinate for the normalized vertex coordinates; however, it is necessary to set "x, y" coordinates to specify the polygon. As reference, you could take a look at the Node.js sample and Python example.

Checking the Client Library for Java, it also has a method to set the "y" coordinate.

public Builder setY(float value) {
  y_ = value;
  onChanged();
  return this;
}

Based on that, the code should look like:

TableBoundHint tableBoundHints = TableBoundHint.newBuilder()
                    .setBoundingBox(BoundingPoly.newBuilder()
//                   top left
                    .addNormalizedVertices(NormalizedVertex.newBuilder().setX(0).setY(0).build())
//                   top right
                    .addNormalizedVertices(NormalizedVertex.newBuilder().setX(1).setY(0).build())
//                   bottom right
                    .addNormalizedVertices(NormalizedVertex.newBuilder().setX(1).setY(0.25f).build())
//                   bottom left
                    .addNormalizedVertices(NormalizedVertex.newBuilder().setX(0).setY(0.25f).build()).build())
                    .setPageNumber(1)
                    .build();

On the other hand, the Document AI API is based on Machine Learning models and approach problems statistically and it cannot be guaranteed that the results are going to be perfectly accurate, nevertheless it is continuously improving.

As you mentioned this feature is in a Beta stage and might change or have limited support. For more information, see the product launch stages.

Upvotes: 0

Related Questions