Skip to content

Commit

Permalink
Rotate images bases on image dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
monolidth committed Nov 22, 2020
1 parent 3e3d4f5 commit a50fc4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
14 changes: 7 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions receipt_parser_core/enhancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def rotate_image(input_file, output_file, angle=90):
"""
print(ORANGE + '\t~: ' + RESET + 'Rotate image' + RESET)
with WandImage(filename=input_file) as img:
height, width = img.shape
if width < height:
angle = 0

with img.clone() as rotated:
rotated.rotate(angle)
rotated.save(filename=output_file)
Expand Down Expand Up @@ -163,14 +167,14 @@ def detect_orientation(image):
coords = np.column_stack(np.where(image > 0))
angle = cv2.minAreaRect(coords)[-1]
print(ORANGE + '\t~: ' + RESET + 'Get rotation angle:' + str(angle) + RESET)
return image

return image

def enhance_image(img):
img = rescale_image(img)
img = grayscale_image(img)
img = remove_noise(img)
img = detect_orientation(img)
# img = detect_orientation(img)
return img


Expand Down

0 comments on commit a50fc4a

Please sign in to comment.