Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IA DETECTION SIGNE
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KHRIS Badreddine
IA DETECTION SIGNE
Commits
bcc3f694
Commit
bcc3f694
authored
4 months ago
by
KHRIS Badreddine
Browse files
Options
Downloads
Patches
Plain Diff
Update 2 files
- /create_dataset.py - /collect_imgs.py
parent
ee64a956
No related branches found
No related tags found
Loading
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
collect_imgs.py
+9
-9
9 additions, 9 deletions
collect_imgs.py
create_dataset.py
+23
-12
23 additions, 12 deletions
create_dataset.py
with
32 additions
and
21 deletions
collect_imgs.py
+
9
−
9
View file @
bcc3f694
...
@@ -3,22 +3,22 @@ import os
...
@@ -3,22 +3,22 @@ import os
import
cv2
import
cv2
DATA_DIR
=
'
./data
'
DATA_DIR
=
'
./data
'
# Rep de stockage
if
not
os
.
path
.
exists
(
DATA_DIR
):
if
not
os
.
path
.
exists
(
DATA_DIR
):
# Création si il n'existe pas
os
.
makedirs
(
DATA_DIR
)
os
.
makedirs
(
DATA_DIR
)
nombre_de_classe
=
3
nombre_de_classe
=
3
#Nombre different d'elements que le modèle devra connaitre
taille_du_dataset
=
100
taille_du_dataset
=
100
#Nombre d'image d'entrainement pour une classe
cap
=
cv2
.
VideoCapture
(
0
)
cap
=
cv2
.
VideoCapture
(
0
)
#On recupere la caméra
for
j
in
range
(
nombre_de_classe
):
for
j
in
range
(
nombre_de_classe
):
# Pour chaque classe je crée un réptoire pour stocker les images
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
DATA_DIR
,
str
(
j
))):
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
DATA_DIR
,
str
(
j
))):
os
.
makedirs
(
os
.
path
.
join
(
DATA_DIR
,
str
(
j
)))
os
.
makedirs
(
os
.
path
.
join
(
DATA_DIR
,
str
(
j
)))
print
(
'
Collecte image pour la classe {}
'
.
format
(
j
))
print
(
'
Collecte image pour la classe {}
'
.
format
(
j
))
done
=
False
done
=
False
while
True
:
while
True
:
#Lancement de la vidéo
ret
,
frame
=
cap
.
read
()
ret
,
frame
=
cap
.
read
()
cv2
.
putText
(
frame
,
'
Appuyez sur Q :)
'
,
(
100
,
50
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
1.3
,
(
0
,
255
,
0
),
3
,
cv2
.
putText
(
frame
,
'
Appuyez sur Q :)
'
,
(
100
,
50
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
1.3
,
(
0
,
255
,
0
),
3
,
cv2
.
LINE_AA
)
cv2
.
LINE_AA
)
...
@@ -26,7 +26,7 @@ for j in range(nombre_de_classe):
...
@@ -26,7 +26,7 @@ for j in range(nombre_de_classe):
if
cv2
.
waitKey
(
25
)
==
ord
(
'
q
'
):
if
cv2
.
waitKey
(
25
)
==
ord
(
'
q
'
):
break
break
counter
=
0
counter
=
0
# si il appuye sur Q alors le programme sauvegarde n frame de la vidéo selon la variable taille_du_dateset
while
counter
<
taille_du_dataset
:
while
counter
<
taille_du_dataset
:
ret
,
frame
=
cap
.
read
()
ret
,
frame
=
cap
.
read
()
cv2
.
imshow
(
'
frame
'
,
frame
)
cv2
.
imshow
(
'
frame
'
,
frame
)
...
...
This diff is collapsed.
Click to expand it.
create_dataset.py
+
23
−
12
View file @
bcc3f694
...
@@ -6,29 +6,38 @@ import cv2
...
@@ -6,29 +6,38 @@ import cv2
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
mp_hands
=
mp
.
solutions
.
hands
# Initialisation des outils de Mediapipe pour la détection des mains
mp_drawing
=
mp
.
solutions
.
drawing_utils
mp_hands
=
mp
.
solutions
.
hands
# Module Mediapipe Hands pour la détection des mains
mp_drawing_styles
=
mp
.
solutions
.
drawing_styles
mp_drawing
=
mp
.
solutions
.
drawing_utils
# Utilitaire pour dessiner les landmarks des mains
mp_drawing_styles
=
mp
.
solutions
.
drawing_styles
# Styles pour afficher les landmarks des mains
hands
=
mp_hands
.
Hands
(
static_image_mode
=
True
,
min_detection_confidence
=
0.3
)
hands
=
mp_hands
.
Hands
(
static_image_mode
=
True
,
min_detection_confidence
=
0.3
)
# Répertoire contenant les images collectées
DATA_DIR
=
'
./data
'
DATA_DIR
=
'
./data
'
data
=
[]
# Initialisation des listes pour stocker les données et les labels
labels
=
[]
data
=
[]
# Contiendra les caractéristiques extraites des images
for
dir_
in
os
.
listdir
(
DATA_DIR
):
labels
=
[]
# Contiendra les étiquettes associées aux images
for
img_path
in
os
.
listdir
(
os
.
path
.
join
(
DATA_DIR
,
dir_
)):
data_aux
=
[]
x_
=
[]
# Parcours de chaque classe de gestes (répertoires contenant les images)
y_
=
[]
for
dir_
in
os
.
listdir
(
DATA_DIR
):
for
img_path
in
os
.
listdir
(
os
.
path
.
join
(
DATA_DIR
,
dir_
)):
# Parcours de toutes les images d'une classe
data_aux
=
[]
# Liste temporaire pour stocker les caractéristiques d'une image
x_
=
[]
# Liste pour stocker les coordonnées X des landmarks
y_
=
[]
# Liste pour stocker les coordonnées Y des landmarks
# Lecture de l'image et conversion en format RGB (Mediapipe nécessite le format RGB)
img
=
cv2
.
imread
(
os
.
path
.
join
(
DATA_DIR
,
dir_
,
img_path
))
img
=
cv2
.
imread
(
os
.
path
.
join
(
DATA_DIR
,
dir_
,
img_path
))
img_rgb
=
cv2
.
cvtColor
(
img
,
cv2
.
COLOR_BGR2RGB
)
img_rgb
=
cv2
.
cvtColor
(
img
,
cv2
.
COLOR_BGR2RGB
)
# Détection de la main dans l'image
results
=
hands
.
process
(
img_rgb
)
results
=
hands
.
process
(
img_rgb
)
# Vérification si une main a bien été détectée
if
results
.
multi_hand_landmarks
:
if
results
.
multi_hand_landmarks
:
for
hand_landmarks
in
results
.
multi_hand_landmarks
:
for
hand_landmarks
in
results
.
multi_hand_landmarks
:
# Extraction des coordonnées X et Y de chaque point de repère de la main
for
i
in
range
(
len
(
hand_landmarks
.
landmark
)):
for
i
in
range
(
len
(
hand_landmarks
.
landmark
)):
x
=
hand_landmarks
.
landmark
[
i
].
x
x
=
hand_landmarks
.
landmark
[
i
].
x
y
=
hand_landmarks
.
landmark
[
i
].
y
y
=
hand_landmarks
.
landmark
[
i
].
y
...
@@ -36,12 +45,14 @@ for dir_ in os.listdir(DATA_DIR):
...
@@ -36,12 +45,14 @@ for dir_ in os.listdir(DATA_DIR):
x_
.
append
(
x
)
x_
.
append
(
x
)
y_
.
append
(
y
)
y_
.
append
(
y
)
# Normalisation des coordonnées : soustraction du minimum pour centrer les données
for
i
in
range
(
len
(
hand_landmarks
.
landmark
)):
for
i
in
range
(
len
(
hand_landmarks
.
landmark
)):
x
=
hand_landmarks
.
landmark
[
i
].
x
x
=
hand_landmarks
.
landmark
[
i
].
x
y
=
hand_landmarks
.
landmark
[
i
].
y
y
=
hand_landmarks
.
landmark
[
i
].
y
data_aux
.
append
(
x
-
min
(
x_
))
data_aux
.
append
(
x
-
min
(
x_
))
# Normalisation X
data_aux
.
append
(
y
-
min
(
y_
))
data_aux
.
append
(
y
-
min
(
y_
))
# Normalisation Y
# Ajout des caractéristiques extraites et de l'étiquette associée à l'image
data
.
append
(
data_aux
)
data
.
append
(
data_aux
)
labels
.
append
(
dir_
)
labels
.
append
(
dir_
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment