[974c13]: / DataAugmentation / MoveAllFiles.py

Download this file

58 lines (48 with data), 1.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Import Packages
from shutil import copy
import os
import errno
# Define Image Augumentation Operations
print(os.getcwd())
augOperations = ["GaussianNoise",
"GaussianBlur",
"Brightness",
"ContrastNormalization",
"Fliplr",
"Flipud",
"Rot90or270Degree"
]
# Define Helper Functions
def createFolder(folderName):
"""
Safely create folder when needed
:param folderName : the directory that you want to safely create
:return: None
"""
if not os.path.exists(folderName):
try:
os.makedirs(folderName)
except OSError as exc: # Guard against race condition
if exc.errno != errno.EEXIST:
raise
# Define the data folder
dataPath = "tmp/" #"./Data3TypesYminXminYmaxXmax6/"
createFolder(dataPath + "images")
createFolder(dataPath + "bounding_boxes")
# Loop through images and bboxes
for oper in augOperations:
for f in os.listdir('Aug/'+ oper + "Images/"):
print(f)
# Copy Images
copy('Aug/'+ oper + "Images/" + f, dataPath + "images")
# Copy TxT
copy('Aug/'+ oper + "TXT/" + f.rstrip(".jpg") + ".txt",
dataPath + "bounding_boxes")
print("Done!")
# for f in os.listdir(datDir):
# fs = f.split('.')
# if fs[1] == "tif":
# covertTIF2JPG(datDir + '/' + f, fs[0])
# copy(fs[0] + '.jpg', imgDir)
# if fs[1] == "csv":
# copy(datDir + '/' + f, csvDir)