图像增强库imgaug的目标检测数据使用笔记

from imgaug import augmenters as iaa
import imgaug as ia
import matplotlib.pyplot as plt 

augmentation = iaa.SomeOf((0, 3), [
    iaa.Fliplr(0.5),
    iaa.Flipud(0.5),
    iaa.OneOf([iaa.Affine(rotate=90),
               iaa.Affine(rotate=90),
               iaa.Affine(rotate=270),
               iaa.Affine(rotate=180),
               iaa.Affine(rotate=180),
               iaa.Affine(rotate=270)]),
    iaa.Multiply((0.8, 1.5)),
    iaa.GaussianBlur(sigma=(0.0, 3.0))
])

temp_aug_bbox = []
for bbox in bboxes_resize1:
    temp_aug_bbox.append(ia.BoundingBox(x1=bbox[1], 
                                        x2=bbox[3], 
                                        y1=bbox[0], 
                                        y2=bbox[2]))
bbs = ia.BoundingBoxesOnImage(temp_aug_bbox, shape=image.shape)
#        if debug:
#            pass
#            plt.figure()
#            plt.imshow(bbs.draw_on_image(image, thickness=2))


seq_det = augmentation.to_deterministic()

image = seq_det.augment_image(image)
bbs_aug = seq_det.augment_bounding_boxes([bbs])[0]
#        plt.figure()
#        plt.imshow(bbs_aug.draw_on_image(image_aug, thickness=2))    

bboxes_resize1 = []
for one in bbs_aug.bounding_boxes:
    bboxes_resize1.append([ one.y1, one.x1, one.y2, one.x2])
if debug:
    pass
    debug_show(image, bboxes_resize1)

 

你可能感兴趣的:(深度学习,机器学习)