Untitled

 avatar
unknown
python
4 years ago
1.1 kB
19
Indexable
import numpy as np
import matplotlib.pyplot as plt
import albumentations

import cv2
from albumentations import (
    ShiftScaleRotate, Blur, MotionBlur, RandomBrightnessContrast, Compose
)

KEYPOINT_COLOR = (0, 0, 0) # Green

def vis_keypoints(image, keypoints, color=KEYPOINT_COLOR, diameter=15):
    plt.figure()
    plt.imshow(image)
    for landmarks in keypoints:
        plt.scatter(landmarks[0], landmarks[1], c = 'c', s = 5)
    plt.show()

transform = Compose([
        ShiftScaleRotate(shift_limit=0.0625, scale_limit=0.4, rotate_limit=45, p=1.0,interpolation=1),
        RandomBrightnessContrast(p=0.75)
    ], keypoint_params=albumentations.KeypointParams(format='xy', remove_invisible=False))

keypoints = [
    (50, 5),
    (50, 90),
    (50, 50),
]

# Create a temporary image of size 100X100X3 with pixel value of 12
image = np.ones((100,100,3), np.uint8) * 127

# Apply keypoint transformation
transformed = transform(image=image, keypoints=keypoints)

# Visualize transformation
vis_keypoints(transformed['image'], transformed['keypoints'])
Editor is loading...