Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
update
  • Loading branch information
muzishen committed Jun 5, 2022
1 parent 6408d50 commit d55455d
Show file tree
Hide file tree
Showing 9 changed files with 351 additions and 0 deletions.
54 changes: 54 additions & 0 deletions offline_generate/offline_aug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 18 22:02:45 2021
@author: HUAWEI
"""

import imgaug as ia
from imgaug import augmenters as iaa
import numpy as np
import cv2
from pascal_voc_writer import Writer
import xml.etree.ElementTree as ET
import glob
from util import sequence
from util import annotation as an
import shutil
import sys

import os

OUTPUT_DIR = './fusai'
AUGMENT_SIZE = 1

image_path = r'./clear_rename_images_v2'
def main():
for file in glob.glob('%s/*.jpg' % image_path):

augment(file)



def augment(filename):

seq = sequence.get()

for i in range(AUGMENT_SIZE):

sp = filename.split('/')[-1].split('.')

new_name = sp[0] + '-'+str(i) + '.jpg'
outfile = os.path.join(OUTPUT_DIR, new_name)

seq_det = seq.to_deterministic()

image = cv2.imread(filename)

image_aug = seq_det.augment_images([image])[0]

cv2.imwrite(outfile, image_aug)


if __name__ == "__main__":
main()
7 changes: 7 additions & 0 deletions offline_generate/util/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions offline_generate/util/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions offline_generate/util/.idea/util.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

193 changes: 193 additions & 0 deletions offline_generate/util/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
42 changes: 42 additions & 0 deletions offline_generate/util/annotation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import imgaug as ia
from imgaug import augmenters as iaa
import numpy as np
import xml.etree.ElementTree as ET
import glob
import shutil

EMPTY_DIR = 'empty'


def parse_xml(filename):
tree = ET.parse(filename)
elem = tree.getroot()
result = {
'filename': elem.find('.//filename').text,
'size': {
'width': elem.find('.//size/width').text,
'height': elem.find('.//size/height').text,
'depth': elem.find('.//size/depth').text,
},
'objects': []
}

for e in elem.findall('.//object'):
obj = {
'name': e.find('.//name').text,
'xmin': e.find('.//bndbox/xmin').text,
'ymin': e.find('.//bndbox/ymin').text,
'xmax': e.find('.//bndbox/xmax').text,
'ymax': e.find('.//bndbox/ymax').text
}
result['objects'].append(obj)

return result


def inspect(filename):
annotation = parse_xml(filename)

if len(annotation['objects']) == 0:
print('Empty annotation file %s is moved.' % filename)
shutil.move(filename, EMPTY_DIR)
35 changes: 35 additions & 0 deletions offline_generate/util/sequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import imgaug as ia
from imgaug import augmenters as iaa


def get():
def sometimes(aug): return iaa.Sometimes(1.0, aug)

return iaa.Sequential(
[

sometimes(iaa.Affine(

rotate=(-15, 15), # rotate by -45 to +45 degrees

mode=ia.ALL # use any of scikit-image's warping modes (see 2nd image from the top for examples)
)),

iaa.SomeOf((0, 5),
[

iaa.OneOf([
iaa.GaussianBlur((1.0, 3.0)), # blur images with a sigma between 0 and 3.0
iaa.AverageBlur(k=(2, 7)),
iaa.MedianBlur(k=(3, 11)),


]),
iaa.Sharpen(alpha=(0, 1.0), lightness=(0.75, 1.5)), # sharpen images

],
random_order=True
)
],
random_order=True
)

0 comments on commit d55455d

Please sign in to comment.