Skip to content

Commit

Permalink
dev(narugo): fix bug of expected height
Browse files Browse the repository at this point in the history
  • Loading branch information
narugo1992 committed Oct 16, 2023
1 parent 18fe0f8 commit 724f169
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions imgutils/ocr/recognize.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,19 @@ def decode(text_index, model: str, text_prob=None, is_remove_duplicate=False):

def _text_recognize(image: ImageTyping, model: str = 'ch_PP-OCRv4_rec',

Check warning on line 62 in imgutils/ocr/recognize.py

View check run for this annotation

Codecov / codecov/patch

imgutils/ocr/recognize.py#L62

Added line #L62 was not covered by tests
is_remove_duplicate: bool = False) -> Tuple[str, float]:
_ort_session = _open_ocr_recognition_model(model)
expected_height = _ort_session.get_inputs()[0].shape[2]

Check warning on line 65 in imgutils/ocr/recognize.py

View check run for this annotation

Codecov / codecov/patch

imgutils/ocr/recognize.py#L64-L65

Added lines #L64 - L65 were not covered by tests

image = load_image(image, force_background='white', mode='RGB')
r = 48 / image.height
r = expected_height / image.height
new_height = int(round(image.height * r))
new_width = int(round(image.width * r))
image = image.resize((new_width, new_height))

Check warning on line 71 in imgutils/ocr/recognize.py

View check run for this annotation

Codecov / codecov/patch

imgutils/ocr/recognize.py#L67-L71

Added lines #L67 - L71 were not covered by tests

input_ = np.array(image).transpose((2, 0, 1)).astype(np.float32) / 255.0

Check warning on line 73 in imgutils/ocr/recognize.py

View check run for this annotation

Codecov / codecov/patch

imgutils/ocr/recognize.py#L73

Added line #L73 was not covered by tests

input_ = ((input_ - 0.5) / 0.5)[None, ...].astype(np.float32)

Check warning on line 75 in imgutils/ocr/recognize.py

View check run for this annotation

Codecov / codecov/patch

imgutils/ocr/recognize.py#L75

Added line #L75 was not covered by tests
_ort_session = _open_ocr_recognition_model(model)

_input_name = _ort_session.get_inputs()[0].name
_output_name = _ort_session.get_outputs()[0].name
output, = _ort_session.run([_output_name], {_input_name: input_})

Check warning on line 79 in imgutils/ocr/recognize.py

View check run for this annotation

Codecov / codecov/patch

imgutils/ocr/recognize.py#L77-L79

Added lines #L77 - L79 were not covered by tests
Expand Down

0 comments on commit 724f169

Please sign in to comment.