Skip to content

Commit

Permalink
[formrecognizer] adjust text angle to fit in specified interval (#12248)
Browse files Browse the repository at this point in the history
* adjust text angle to fit in specified interval

* fix testcase expression
  • Loading branch information
kristapratico authored Jun 30, 2020
1 parent de7168a commit 83ac5e9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
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

0 comments on commit 83ac5e9

Please sign in to comment.