albumentations-team / albumentations

Fast and flexible image augmentation library. Paper about the library: https://www.mdpi.com/2078-2489/11/2/125
https://albumentations.ai
MIT License
13.81k stars 1.61k forks source link

keypoint position shifting during image rotation #1819

Closed medmabcf closed 3 weeks ago

medmabcf commented 4 weeks ago

Describe the bug

When applying a rotation of π to an image, the positions of the keypoints slightly shift.

To Reproduce

random.seed(7)

transform = A.Compose(
    [
        A.Affine(rotate=90, p=1.0, mode=cv2.BORDER_CONSTANT, fit_output=True),  # Added shear
    ],
    keypoint_params=A.KeypointParams(format='xy', label_fields=['class_labels'], remove_invisible=False),
    bbox_params=A.BboxParams(format='yolo')
)

transformed = transform(image=image, keypoints=keypoints, bboxes=bboxes, class_labels=class_labels, cropping_bbox=random.choice(bboxes))

Expected behavior

The original image is on the left. expected

Actual behavior

The original image is on the left. current

ternaus commented 4 weeks ago

Thanks, will look at this ASAP.

Do you have an example of the code that I could run to reproduce the behavior?

I.e. =

Image + bbox coordinates and keypoint coordinates before and expected result?

medmabcf commented 3 weeks ago

This is a link to a colab notebook

https://colab.research.google.com/drive/12C_iWolT-ybEfJOajDOizYwaLaVgM6fu?usp=sharing#scrollTo=2T1K2O3lb8na

ternaus commented 3 weeks ago

Should be fixed in https://github.com/albumentations-team/albumentations/pull/1823

Could you please try use int(x), int(y) before passing in your notebook?