Skip to content
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

squid: abc: Add the AbstractCamera interface, and a simulated camera implementation #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 15 additions & 10 deletions software/control/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import enum
import inspect
import os
import pathlib
Expand Down Expand Up @@ -62,9 +63,16 @@ def unsigned_to_signed(unsigned_array, N):
return signed


def rotate_and_flip_image(image, rotate_image_angle, flip_image):
class FlipVariant(enum.Enum):
# The mixed case is a historical artifact.
VERTICAL = "Vertical"
HORIZONTAL = "Horizontal"
BOTH = "Both"


def rotate_and_flip_image(image, rotate_image_angle: Optional[float], flip_image: Optional[FlipVariant]):
ret_image = image.copy()
if rotate_image_angle != 0:
if rotate_image_angle and rotate_image_angle != 0:
"""
# ROTATE_90_CLOCKWISE
# ROTATE_90_COUNTERCLOCKWISE
Expand All @@ -75,18 +83,15 @@ def rotate_and_flip_image(image, rotate_image_angle, flip_image):
ret_image = cv2.rotate(ret_image, cv2.ROTATE_90_COUNTERCLOCKWISE)
elif rotate_image_angle == 180:
ret_image = cv2.rotate(ret_image, cv2.ROTATE_180)
else:
raise ValueError(f"Unhandled rotation: {rotate_image_angle}")

if flip_image is not None:
"""
flipcode = 0: flip vertically
flipcode > 0: flip horizontally
flipcode < 0: flip vertically and horizontally
"""
if flip_image == "Vertical":
if flip_image == FlipVariant.VERTICAL:
ret_image = cv2.flip(ret_image, 0)
elif flip_image == "Horizontal":
elif flip_image == FlipVariant.HORIZONTAL:
ret_image = cv2.flip(ret_image, 1)
elif flip_image == "Both":
elif flip_image == FlipVariant.BOTH:
ret_image = cv2.flip(ret_image, -1)

return ret_image
Expand Down
Loading
Loading