Initial commit
This commit is contained in:
4
Divers/tutoriel11/README.md
Normal file
4
Divers/tutoriel11/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Tutoriel 11
|
||||
## Utilisation de Labelimg et conversion des fichiers xml en np.array
|
||||
|
||||
La vidéo de ce tutoriel est disponible à l'adresse suivante: https://www.youtube.com/watch?v=VWXXFFDqBqA
|
||||
39
Divers/tutoriel11/xmltoarray.py
Normal file
39
Divers/tutoriel11/xmltoarray.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import xmltodict
|
||||
import numpy as np
|
||||
import glob
|
||||
import cv2
|
||||
|
||||
def xml_to_dataset(dir, size=None):
|
||||
tab_image=[]
|
||||
tab_label=[]
|
||||
for fichier in glob.glob(dir+"/*.xml"):
|
||||
with open(fichier) as fd:
|
||||
doc=xmltodict.parse(fd.read())
|
||||
image=doc['annotation']['filename']
|
||||
img=cv2.imread(dir+"/"+image)
|
||||
objects=doc['annotation']['object'] if type(doc['annotation']['object'])==list else [doc['annotation']['object']]
|
||||
for obj in objects:
|
||||
xmin=int(obj['bndbox']['xmin'])
|
||||
xmax=int(obj['bndbox']['xmax'])
|
||||
ymin=int(obj['bndbox']['ymin'])
|
||||
ymax=int(obj['bndbox']['ymax'])
|
||||
if size is not None:
|
||||
tab_image.append(cv2.resize(img[ymin:ymax, xmin:xmax], size))
|
||||
else:
|
||||
tab_image.append(img[ymin:ymax, xmin:xmax])
|
||||
tab_label.append(obj['name'])
|
||||
|
||||
l=list(set(tab_label))
|
||||
tab_one_hot=[]
|
||||
for e in tab_label:
|
||||
tab_one_hot.append(np.eye(len(l))[l.index(e)])
|
||||
|
||||
return tab_image, l, tab_one_hot
|
||||
|
||||
tab_image, tab_label, tab_one_hot=xml_to_dataset("./", (32, 32))
|
||||
|
||||
for i in range(len(tab_image)):
|
||||
cv2.imshow('image', tab_image[i])
|
||||
print(tab_label[np.argmax(tab_one_hot[i])], tab_one_hot[i])
|
||||
cv2.waitKey()
|
||||
|
||||
Reference in New Issue
Block a user