Skip to content

[formrecognizer] adjust text angle to fit in specified interval #12248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# Change Log azure-ai-formrecognizer

## 1.0.0b4 (Unreleased)

**Breaking Changes**

- Remove `RecognizedReceipts` Class.
- `begin_recognize_receipts` and `begin_recognize_receipts_from_url` now return `RecognizedForm`.
- `requested_on` renamed to `training_started_on` and `completed_on` renamed to `training_completed_on` on `CustomFormModel`
and `CustomFormModelInfo`

**Fixes and improvements**

- Fixes a bug where `text_angle` was being returned out of the specified interval (-180, 180]

## 1.0.0b3 (2020-06-10)

**Breaking Changes**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def adjust_confidence(score):
return score


def adjust_text_angle(text_angle):
"""Adjust to (-180, 180]
"""
if text_angle > 180:
text_angle -= 360
return text_angle


def get_elements(field, read_result):
text_elements = []

Expand Down Expand Up @@ -327,7 +335,7 @@ def __init__(self, **kwargs):
def _from_generated(cls, read_result):
return [cls(
page_number=page.page,
text_angle=page.angle,
text_angle=adjust_text_angle(page.angle),
width=page.width,
height=page.height,
unit=page.unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
FormTable,
FormTableCell,
FormPageRange,
RecognizedForm
RecognizedForm,
adjust_text_angle
)


Expand Down Expand Up @@ -70,7 +71,7 @@ def prepare_content_result(response):
for idx, page in enumerate(read_result):
form_page = FormPage(
page_number=page.page,
text_angle=page.angle,
text_angle=adjust_text_angle(page.angle),
width=page.width,
height=page.height,
unit=page.unit,
Expand Down
5 changes: 4 additions & 1 deletion sdk/formrecognizer/azure-ai-formrecognizer/tests/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ def assertFormPagesTransformCorrect(self, pages, actual_read, page_result=None,
if hasattr(page, "pages"): # this is necessary for how unlabeled forms are structured
page = page.pages[0]
self.assertEqual(page.page_number, actual_page.page)
self.assertEqual(page.text_angle, actual_page.angle)
if actual_page.angle <= 180:
self.assertEqual(page.text_angle, actual_page.angle)
if actual_page.angle > 180:
self.assertEqual(page.text_angle, actual_page.angle - 360)
self.assertEqual(page.width, actual_page.width)
self.assertEqual(page.height, actual_page.height)
self.assertEqual(page.unit, actual_page.unit)
Expand Down