Skip to content

Commit

Permalink
fix: pr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisochoatri committed Aug 29, 2022
1 parent 502f93e commit 7b099a3
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions dgp/annotations/camera_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def calc_affine_transform(
Parameters
----------
theta: float
Rotation angle in degrees.
scale: float
Expand All @@ -64,7 +63,6 @@ def calc_affine_transform(
Returns
-------
A: np.ndarray
3x3 matrix that expresses the requested transformations.
"""
Expand Down Expand Up @@ -94,16 +92,16 @@ def calc_affine_transform(


def box_crop_affine_transform(
box_xyxy: Tuple[int, int, int, int],
box_ltrb: Tuple[int, int, int, int],
target_shape: Tuple[int, int],
) -> np.ndarray:
"""Generates a matrix that crops a rectangular area from an image and resizes it to target shape.
Note, this preserves the aspect ratio in target shape.
Parameters
----------
box_xyxy: list or tuple
Box corners expressed as x1,y1,x2,y2.
box_ltrb: list or tuple
Box corners expressed as left, top, right, bottom (x1,y1,x2,y2).
target_shape: tuple
Desired image shape (h,w) after cropping and resizing.
Expand All @@ -113,7 +111,7 @@ def box_crop_affine_transform(
3x3 matrix that expresses the requested transformation.
"""
# get box center
x1, y1, x2, y2 = box_xyxy
x1, y1, x2, y2 = box_ltrb
cx, cy = (x1 + x2) / 2, (y1 + y2) / 2
w, h = x2 - x1, y2 - y1

Expand Down Expand Up @@ -284,6 +282,8 @@ def transform_image(
mode = PIL.Image.BILINEAR
elif mode == cv2.INTER_NEAREST:
mode = PIL.Image.NEAREST
else:
raise ValueError(f'{mode} not supported')

new_img = tx.transform((w, h), img, resample=mode)
else:
Expand All @@ -304,7 +304,6 @@ def transform_camera(
Returns
-------
mtxR: np.array
new camera intrinsics
new_pose: Pose
Expand All @@ -316,7 +315,8 @@ def transform_camera(
# Transform the camera matrix
h, w = self.shape[:2]

# Flipping leads to the wrong rotation below, so when there is a flip present, we unflip, do everything, and re flip
# Flipping leads to the wrong rotation below, so when there is a flip present,
# we unflip, do everything, and re flip
flip_mat = np.eye(3)
flip = False
if self.A[0, 0] < 0:
Expand Down Expand Up @@ -499,12 +499,12 @@ def transform_mask_2d(
Parameters
----------
mask: np.ndarray
mask: np.ndarray, optional
A boolean mask of same shape as the image that denotes a valid pixel
Returns
-------
new_mask: np.ndarray
new_mask: np.ndarray, optional
The transformed mask or None if the input mask was None
"""

Expand Down

0 comments on commit 7b099a3

Please sign in to comment.