Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
Smart E- Learn Tracer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
23_22 - J 01
Smart E- Learn Tracer
Commits
7c679e08
Commit
7c679e08
authored
Jan 25, 2023
by
Shenthuri Vimaleshwaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
278d59e2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
0 deletions
+51
-0
eyemove_ment/face_direction.py
eyemove_ment/face_direction.py
+51
-0
No files found.
eyemove_ment/face_direction.py
0 → 100644
View file @
7c679e08
import
cv2
# Load the cascade
face_cascade
=
cv2
.
CascadeClassifier
(
"haarcascade_frontalface_default.xml"
)
# Load the video
cap
=
cv2
.
VideoCapture
(
0
)
# Get the video dimensions
width
=
int
(
cap
.
get
(
3
))
height
=
int
(
cap
.
get
(
4
))
# Define the center of the frame
center_x
=
width
//
2
center_y
=
height
//
2
while
True
:
# Read the frame
_
,
frame
=
cap
.
read
()
# Convert to grayscale
gray
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
# Detect faces
faces
=
face_cascade
.
detectMultiScale
(
gray
,
scaleFactor
=
1.1
,
minNeighbors
=
5
)
# Loop over the face detections
for
(
x
,
y
,
w
,
h
)
in
faces
:
cv2
.
rectangle
(
frame
,
(
x
,
y
),
(
x
+
w
,
y
+
h
),
(
255
,
0
,
0
),
2
)
# Get the center of the face
face_center_x
=
x
+
w
//
2
face_center_y
=
y
+
h
//
2
# Check the direction of the face
if
face_center_x
<
center_x
-
50
:
print
(
"Face is looking to the left."
)
# Send an alert
#alert()
elif
face_center_x
>
center_x
+
50
:
print
(
"Face is looking to the right."
)
# Send an alert
#alert()
else
:
print
(
"Face is looking straight ahead."
)
# Show the frame
cv2
.
imshow
(
"Face Detection"
,
frame
)
# Exit if the user presses 'q'
if
cv2
.
waitKey
(
1
)
==
ord
(
'q'
):
break
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment