-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update
- Loading branch information
Showing
9 changed files
with
351 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |