FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-eyetracking/tutorial/run_example.py at main · juno-hwang/python-eyetracking · GitHub
juno-hwang
/
python-eyetracking
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-eyetracking
/
tutorial
/
run_example.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
104 lines (88 loc) · 3.91 KB
Breadcrumbs
python-eyetracking
/
tutorial
/
run_example.py
Copy path
File metadata and controls
104 lines (88 loc) · 3.91 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import
time
,
pickle
import
cv2
import
mediapipe
as
mp
import
numpy
as
np
import
pandas
as
pd
from
pynput
.
mouse
import
Listener
import
matplotlib
.
pyplot
as
plt
import
seaborn
as
sns
from
sklearn
.
linear_model
import
LinearRegression
from
sklearn
.
model_selection
import
train_test_split
from
sklearn
.
gaussian_process
import
GaussianProcessRegressor
from
sklearn
.
gaussian_process
.
kernels
import
RationalQuadratic
,
RBF
,
WhiteKernel
,
DotProduct
,
ConstantKernel
records
=
pickle
.
load
(
open
(
'records_sample.pkl'
,
'rb'
))
X
=
[
r
[
'landmark'
]
for
r
in
records
]
X
=
np
.
array
(
X
).
reshape
(
-
1
,
478
*
3
)
y
=
[
r
[
'coord'
]
for
r
in
records
]
y
=
np
.
array
(
y
)
print
(
X
.
shape
,
y
.
shape
)
def
predict_landmark
(
landmark
):
X
=
np
.
array
([ [
d
.
x
,
d
.
y
,
d
.
z
]
for
d
in
landmark
])
X
=
X
.
reshape
(
1
,
478
*
3
)
return
model
.
predict
(
X
)[
0
]
def
predict_landmark_smooth
(
landmark
):
if
len
(
coords_traj
)
>
0
:
prev
=
coords_traj
[
-
1
]
curr
=
predict_landmark
(
landmark
)
curr
=
prev
*
0.8
+
curr
*
0.2
else
:
curr
=
predict_landmark
(
landmark
)
return
curr
mp_drawing
=
mp
.
solutions
.
drawing_utils
mp_drawing_styles
=
mp
.
solutions
.
drawing_styles
mp_face_mesh
=
mp
.
solutions
.
face_mesh
drawing_spec
=
mp_drawing
.
DrawingSpec
(
thickness
=
1
,
circle_radius
=
1
)
cap
=
cv2
.
VideoCapture
(
0
,
cv2
.
CAP_DSHOW
)
model
=
GaussianProcessRegressor
(
kernel
=
RationalQuadratic
())
model
.
fit
(
X
,
y
)
# 웹캠 화면이 최상단에 뜨게 하기 위한 설정
# 최상단을 유지하려는 경우에만 주석을 해제해주세요
# cv2.namedWindow('window', cv2.WINDOW_AUTOSIZE)
# cv2.setWindowProperty('window', cv2.WND_PROP_TOPMOST, 1)
coords_traj
=
[]
with
mp_face_mesh
.
FaceMesh
(
max_num_faces
=
1
,
refine_landmarks
=
True
,
min_detection_confidence
=
0.5
,
min_tracking_confidence
=
0.5
)
as
face_mesh
:
while
cap
.
isOpened
():
success
,
image
=
cap
.
read
()
if
not
success
:
print
(
"웹캠을 찾을 수 없습니다."
)
break
image
.
flags
.
writeable
=
False
# 성능 향상을 위해 이미지를 읽기 전용으로 만듭니다.
image
=
cv2
.
cvtColor
(
image
,
cv2
.
COLOR_BGR2RGB
)
results
=
face_mesh
.
process
(
image
)
image
.
flags
.
writeable
=
True
image
=
cv2
.
cvtColor
(
image
,
cv2
.
COLOR_RGB2BGR
)
if
results
.
multi_face_landmarks
:
for
face_landmarks
in
results
.
multi_face_landmarks
:
mp_drawing
.
draw_landmarks
(
image
=
image
,
landmark_list
=
face_landmarks
,
connections
=
mp_face_mesh
.
FACEMESH_TESSELATION
,
landmark_drawing_spec
=
None
,
connection_drawing_spec
=
mp_drawing_styles
.
get_default_face_mesh_tesselation_style
())
mp_drawing
.
draw_landmarks
(
image
=
image
,
landmark_list
=
face_landmarks
,
connections
=
mp_face_mesh
.
FACEMESH_CONTOURS
,
landmark_drawing_spec
=
None
,
connection_drawing_spec
=
mp_drawing_styles
.
get_default_face_mesh_contours_style
())
mp_drawing
.
draw_landmarks
(
image
=
image
,
landmark_list
=
face_landmarks
,
connections
=
mp_face_mesh
.
FACEMESH_IRISES
,
landmark_drawing_spec
=
None
,
connection_drawing_spec
=
mp_drawing_styles
.
get_default_face_mesh_iris_connections_style
())
image
=
cv2
.
flip
(
image
,
1
)
coord
=
predict_landmark_smooth
(
face_landmarks
.
landmark
)
coords_traj
.
append
(
coord
)
cv2
.
putText
(
image
,
f'x:
{
coord
[
0
]:.2f
}
, y:
{
coord
[
1
]:.2f
}
'
, (
10
,
30
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
1
, (
0
,
255
,
0
),
2
)
cv2
.
imshow
(
'window'
,
image
)
# 이미지 재생을 위한 대기시간
cv2
.
waitKey
(
5
)
cap
.
release
()
Back
|
FazBrowse Home
|
New Git URL