-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
79 lines (58 loc) · 2.75 KB
/
Copy pathscript.py
File metadata and controls
79 lines (58 loc) · 2.75 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#
# Created by Cognolato Samuel 1237767 and Fusaro Daniel 1233437
#
import glob, os
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import xml.etree.ElementTree as ET
import shutil
sp = {}
#NOTE: absolute paths must be used!
target_train = '/train/'
target_test = '/test/'
path_train1 = '/ImageCLEF2013PlantTaskTrainPackage-PART-1/train/'
path_train2 = '/ImageCLEF2013PlantTaskTrainPackage-PART-2/train/'
path_test = '/ImageCLEF2013PlantTaskTestAndTaskPackage/TestAndTaskPackage/Data/Test/'
ground_test = '/ImageCLEF2013PlantTaskTestAndTaskPackage/TestAndTaskPackage/Data/GroundTruth/'
print("STARTING FROM path_train1")
os.chdir(path_train1)
for file in glob.glob("*.xml"):
tree = ET.parse(file)
root = tree.getroot()
image = root.iter('Image')
classID = root.find('ClassId').text
content = root.find('Content').text
typ = root.find('Type').text
if content=='Leaf' and typ=='SheetAsBackground' and (classID=='Fraxinus angustifolia' or classID == 'Liquidambar styraciflua' or classID == 'Ruscus aculeatus' or classID == 'Vitex agnus-castus' or classID=='Phillyrea angustifolia'):
fn = root.find('FileName').text
shutil.copy(path_train1+fn, target_train+fn) # copy the image jpg
shutil.copy(path_train1+file, target_train+file) # copy the xml
print(fn)
print("STARTING FROM path_train2")
os.chdir(path_train2)
for file in glob.glob("*.xml"):
tree = ET.parse(file)
root = tree.getroot()
image = root.iter('Image')
classID = root.find('ClassId').text
content = root.find('Content').text
typ = root.find('Type').text
if content=='Leaf' and typ=='SheetAsBackground' and (classID=='Fraxinus angustifolia' or classID == 'Liquidambar styraciflua' or classID == 'Ruscus aculeatus' or classID == 'Vitex agnus-castus' or classID=='Phillyrea angustifolia'):
fn = root.find('FileName').text
shutil.copy(path_train2+fn, target_train+fn) # copy the image jpg
shutil.copy(path_train2+file, target_train+file) # copy the xml
print(fn)
print("STARTING FROM path_test")
os.chdir(ground_test)
for file in glob.glob("*.xml"):
tree = ET.parse(file)
root = tree.getroot()
image = root.iter('Image')
classID = root.find('ClassId').text
content = root.find('Content').text
typ = root.find('Type').text
if content=='Leaf' and typ=='SheetAsBackground' and (classID=='Fraxinus angustifolia' or classID == 'Liquidambar styraciflua' or classID == 'Ruscus aculeatus' or classID == 'Vitex agnus-castus' or classID=='Phillyrea angustifolia'):
fn = root.find('FileName').text
shutil.copy(path_test+fn, target_test+fn) # copy the image jpg
shutil.copy(ground_test+file, target_test+file) # copy the xml
print(fn)