Initial commit

This commit is contained in:
2026-03-31 13:28:59 +02:00
commit 7ec43ca17d
314 changed files with 189852 additions and 0 deletions

View 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

View 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()