-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbateauxCsvPos.py
42 lines (34 loc) · 1.92 KB
/
bateauxCsvPos.py
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
import csv
import os
from lxml import etree
ABSOLUTE = 'D:/Documents/Prepa/TIPE'
pathBateaux = ABSOLUTE + "/data/MASATI-v2/ship"
pathXml = ABSOLUTE + "/data/MASATI-v2/ship_labels"
pathMer = ABSOLUTE + "/data/MASATI-v2/water"
NUMBERSHIP = 5 # 1027
NUMBERWATER = 5 # 1022
def generateCsv(nombre, total):
listeBateaux = os.listdir(pathBateaux)
with open(ABSOLUTE + '/bateauxPos.csv', 'w') as fichier:
filewriter = csv.writer(fichier, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
for i in range(nombre):
nom = pathBateaux + '/' + listeBateaux[i]
#filewriter.writerow([pathBateaux + '/' + listeBateaux[i] + ',0'])
tree = etree.parse(pathXml + '/' + (listeBateaux[i].replace('.png', '.xml')))
xmin = tree.xpath('/annotation/object/bndbox/xmin')[0].text
xmax = tree.xpath('/annotation/object/bndbox/xmax')[0].text
ymin = tree.xpath('/annotation/object/bndbox/ymin')[0].text
ymax = tree.xpath('/annotation/object/bndbox/ymax')[0].text
filewriter.writerow([nom + ',' + xmin + ',' + xmax + ',' + ymin + ',' + ymax])
with open(ABSOLUTE + '/bateauxPosVal.csv', 'w') as fichier:
filewriter = csv.writer(fichier, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
for i in range(nombre, total):
nom = pathBateaux + '/' + listeBateaux[i]
#filewriter.writerow([pathBateaux + '/' + listeBateaux[i] + ',0'])
tree = etree.parse(pathXml + '/' + (listeBateaux[i].replace('.png', '.xml')))
xmin = tree.xpath('/annotation/object/bndbox/xmin')[0].text
xmax = tree.xpath('/annotation/object/bndbox/xmax')[0].text
ymin = tree.xpath('/annotation/object/bndbox/ymin')[0].text
ymax = tree.xpath('/annotation/object/bndbox/ymax')[0].text
filewriter.writerow([nom + ',' + xmin + ',' + xmax + ',' + ymin + ',' + ymax])
return None