Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
Vision-projects
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BOUSSARHANE Mohyeddine
Vision-projects
Commits
020e685c
Commit
020e685c
authored
6 months ago
by
Mohyeddine2
Browse files
Options
Downloads
Patches
Plain Diff
faceTracking
parent
80e82aee
Branches
main
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
faceTracking.py
+62
-0
62 additions, 0 deletions
faceTracking.py
sift.py
+0
-0
0 additions, 0 deletions
sift.py
with
62 additions
and
0 deletions
faceTracking.py
0 → 100644
+
62
−
0
View file @
020e685c
import
cv2
import
numpy
as
np
face_cascade
=
cv2
.
CascadeClassifier
(
cv2
.
data
.
haarcascades
+
'
haarcascade_frontalface_default.xml
'
)
# Initialisation des paramètres
N
=
100
process_noise
=
[
5
,
5
,
2
,
2
,
3
,
3
]
# Bruits pour [x, y, w, h, vx, vy]
observation_noise
=
10
cap
=
cv2
.
VideoCapture
(
0
)
ret
,
frame
=
cap
.
read
()
# Détecter le visage initial
gray
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
faces
=
face_cascade
.
detectMultiScale
(
gray
,
1.3
,
5
)
if
len
(
faces
)
>
0
:
x
,
y
,
w
,
h
=
faces
[
0
]
particles
=
np
.
random
.
normal
([
x
+
w
//
2
,
y
+
h
//
2
,
w
,
h
,
0
,
0
],
process_noise
,
(
N
,
6
))
weights
=
np
.
ones
(
N
)
/
N
else
:
print
(
"
Aucun visage détecté !
"
)
cap
.
release
()
exit
()
while
True
:
ret
,
frame
=
cap
.
read
()
if
not
ret
:
break
gray
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
# Détecter les visages
faces
=
face_cascade
.
detectMultiScale
(
gray
,
1.3
,
5
)
# Si un visage est détecté, on met à jour les particules
if
len
(
faces
)
>
0
:
x
,
y
,
w
,
h
=
faces
[
0
]
particles
=
np
.
random
.
normal
([
x
+
w
//
2
,
y
+
h
//
2
,
w
,
h
,
0
,
0
],
process_noise
,
(
N
,
6
))
weights
=
np
.
ones
(
N
)
/
N
observation
=
[
x
+
w
//
2
,
y
+
h
//
2
,
w
,
h
]
else
:
observation
=
None
# Propagation des particules
particles
[:,
:
2
]
+=
particles
[:,
4
:]
# Mise à jour de (x, y) avec (v_x, v_y)
particles
[:,
:
4
]
+=
np
.
random
.
normal
(
0
,
process_noise
[:
4
],
particles
[:,
:
4
].
shape
)
# Ajout du bruit
# Mise à jour des poids si un visage est détecté
if
observation
is
not
None
:
distances
=
np
.
linalg
.
norm
(
particles
[:,
:
2
]
-
observation
[:
2
],
axis
=
1
)
weights
=
np
.
exp
(
-
0.5
*
(
distances
**
2
)
/
observation_noise
**
2
)
weights
+=
1e-300
weights
/=
np
.
sum
(
weights
)
else
:
# Si aucun visage n'est détecté, on propague les particules sans mettre à jour les poids
weights
.
fill
(
1.0
/
N
)
# Rééchantillonnage
indices
=
np
.
random
.
choice
(
range
(
N
),
size
=
N
,
p
=
weights
)
particles
=
particles
[
indices
]
weights
.
fill
(
1.0
/
N
)
# Estimation par calcule de moyenne
estimated_state
=
np
.
mean
(
particles
,
axis
=
0
).
astype
(
int
)
x_est
,
y_est
,
w_est
,
h_est
=
estimated_state
[:
4
]
cv2
.
rectangle
(
frame
,
(
x_est
-
w_est
//
2
,
y_est
-
h_est
//
2
),
(
x_est
+
w_est
//
2
,
y_est
+
h_est
//
2
),
(
255
,
0
,
0
),
2
)
cv2
.
imshow
(
"
Suivi de Visage
"
,
frame
)
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'
q
'
):
break
cap
.
release
()
cv2
.
destroyAllWindows
()
This diff is collapsed.
Click to expand it.
sift.py
0 → 100644
+
0
−
0
View file @
020e685c
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