amazon-textract-response-parser icon indicating copy to clipboard operation
amazon-textract-response-parser copied to clipboard

Rotation correction does not work as expected

Open MrinalJain17 opened this issue 1 year ago • 2 comments

Are there plans to fix this issue:

https://github.com/aws-samples/amazon-textract-response-parser/blob/cd24097feb4349d35822ff039dd0f40a6ad8b48c/src-python/trp/trp2.py#L595

I've noticed that the corrections applied align well when the document/image is rotated at right angles (90, 180, ...). But otherwise, the transformed geometries don't line up.

MrinalJain17 avatar Apr 01 '23 18:04 MrinalJain17

It is not scheduled yet, but gladly accept PRs that handle the rotation better.

schadem avatar Apr 03 '23 18:04 schadem

I can give it a shot, but will need some help.

As far as I understand, this is the issue:

  • The current geometry rotation (bounding box and polygons) applies the rotation along some center.
  • The document (image) when rotated generally is allowed to "expand". This rotated document image is now a plane that is misaligned with that of the geometry (bounding boxes, polygons).
  • This only occurs when the rotation is performed at non-right angles.

I have been looking into ways to tackle this, but haven't found much literature. Maybe something like PyTorch is doing - https://github.com/pytorch/vision/blob/781f512b01bc2324d7fdd11f0901f60571fc476f/torchvision/transforms/v2/functional/_geometry.py#L883

@schadem Do you happen to know if there exists some blog or something that can explain the potential solution in a better way?

MrinalJain17 avatar Apr 03 '23 19:04 MrinalJain17