Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cyclops eye-tracker
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
ROBERT Francois-Mael
Cyclops eye-tracker
Commits
7dfa9ecd
Commit
7dfa9ecd
authored
2 years ago
by
ROBERT Francois-Mael
Browse files
Options
Downloads
Patches
Plain Diff
Calibration method v1 and implemented in main.py
parent
f2d4b936
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
calibration.py
+58
-0
58 additions, 0 deletions
calibration.py
main.py
+43
-29
43 additions, 29 deletions
main.py
with
101 additions
and
29 deletions
calibration.py
+
58
−
0
View file @
7dfa9ecd
import
numpy
as
np
import
matplotlib.pyplot
as
plt
from
sklearn.preprocessing
import
PolynomialFeatures
from
sklearn.linear_model
import
LinearRegression
from
sklearn.pipeline
import
Pipeline
def
polynomial_regression
(
x
,
y
,
angles_calib
,
deg
):
"""
Return the coefficients of a polynomial regression of degree deg on x and y.
x: x-positions of the spot (np-array of dim n_calib_steps)
x: y-positions of the spot (np-array of dim n_calib_steps)
angles_calib: H and V angles of calibration (np-array of dim n_calib_steps*2)
deg: degree of the regression
'
s polynome (int)
RETURNS
coefs: coefficients for the two polynomes (np-array of dim n_coefs*2)
"""
# Preprocessing of the data
measured_values
=
np
.
array
([
x
,
y
]).
transpose
()
angles_horizontal
=
angles_calib
[
0
,
:]
angles_vertical
=
angles_calib
[
1
,
:]
# Creation of the models
model_horizontal
=
Pipeline
([(
'
poly
'
,
PolynomialFeatures
(
degree
=
deg
,
interaction_only
=
False
)),
(
'
linear
'
,
LinearRegression
(
fit_intercept
=
False
))])
model_vertical
=
Pipeline
([(
'
poly
'
,
PolynomialFeatures
(
degree
=
deg
,
interaction_only
=
False
)),
(
'
linear
'
,
LinearRegression
(
fit_intercept
=
False
))])
# Fitting of the models and return of the results
model_horizontal
=
model_horizontal
.
fit
(
measured_values
,
angles_horizontal
)
coefs_horizontal
=
model_horizontal
.
named_steps
[
'
linear
'
].
coef_
print
(
coefs_horizontal
)
model_vertical
=
model_vertical
.
fit
(
measured_values
,
angles_vertical
)
coefs_vertical
=
model_vertical
.
named_steps
[
'
linear
'
].
coef_
print
(
coefs_vertical
)
return
np
.
array
([
coefs_horizontal
,
coefs_vertical
]).
transpose
()
if
__name__
==
'
__main__
'
:
import
matplotlib.pyplot
as
plt
x
=
np
.
array
([
-
10
,
0
,
10
])
y
=
np
.
array
([
4
,
5
,
6
])
angles_horizontal
=
np
.
array
([
-
8
,
8
,
93
])
angles_vertical
=
np
.
array
([
10
,
11
,
12
])
angles
=
np
.
array
([
angles_horizontal
,
angles_vertical
])
coefs
=
polynomial_regression
(
x
,
y
,
angles
,
3
)
import
pdb
;
pdb
.
set_trace
()
coefs_horizontal
=
coefs
[:,
0
]
x_plot
=
np
.
linspace
(
-
10
,
10
,
100
)
y_plot
=
x_plot
angle_horizontal_reg
=
coefs_horizontal
[
0
]
+
coefs_horizontal
[
1
]
*
x_plot
+
coefs_horizontal
[
2
]
*
y_plot
+
coefs_horizontal
[
3
]
*
x_plot
**
2
+
coefs_horizontal
[
4
]
*
x_plot
*
y_plot
+
coefs_horizontal
[
5
]
*
y_plot
**
2
+
coefs_horizontal
[
6
]
*
x_plot
**
3
+
coefs_horizontal
[
7
]
*
x_plot
**
2
*
y_plot
+
coefs_horizontal
[
8
]
*
x_plot
*
y_plot
**
2
+
coefs_horizontal
[
9
]
*
y_plot
**
3
plt
.
figure
()
plt
.
scatter
(
x
,
angles_horizontal
)
plt
.
plot
(
x_plot
,
angle_horizontal_reg
)
plt
.
show
()
This diff is collapsed.
Click to expand it.
main.py
+
43
−
29
View file @
7dfa9ecd
...
@@ -11,6 +11,7 @@ import numpy as np
...
@@ -11,6 +11,7 @@ import numpy as np
import
uvc
import
uvc
from
sklearn.linear_model
import
LinearRegression
from
sklearn.linear_model
import
LinearRegression
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
import
calibration
### Variables initiales
### Variables initiales
dev_list
=
uvc
.
device_list
()
dev_list
=
uvc
.
device_list
()
...
@@ -270,10 +271,20 @@ class App(QWidget):
...
@@ -270,10 +271,20 @@ class App(QWidget):
self
.
centroid_right_text_3
.
setText
(
str
(
self
.
centroids
[
1
][
1
]))
self
.
centroid_right_text_3
.
setText
(
str
(
self
.
centroids
[
1
][
1
]))
# print(self.centroids)
# print(self.centroids)
if
self
.
calib_done
:
if
self
.
calib_done
:
self
.
angles
[
0
][
0
]
=
(
centroids
[
0
][
0
]
-
self
.
b_leftH
)
/
self
.
a_leftH
# self.angles[0][0] = (centroids[0][0] - self.b_leftH) / self.a_leftH
self
.
angles
[
0
][
1
]
=
(
centroids
[
0
][
1
]
-
self
.
b_leftV
)
/
self
.
a_leftV
# self.angles[0][1] = (centroids[0][1] - self.b_leftV) / self.a_leftV
self
.
angles
[
1
][
0
]
=
(
centroids
[
1
][
0
]
-
self
.
b_rightH
)
/
self
.
a_rightH
# self.angles[1][0] = (centroids[1][0] - self.b_rightH) / self.a_rightH
self
.
angles
[
1
][
1
]
=
(
centroids
[
1
][
1
]
-
self
.
b_rightV
)
/
self
.
a_rightV
# self.angles[1][1] = (centroids[1][1] - self.b_rightV) / self.a_rightV
x_l
=
centroids
[
0
][
0
]
y_l
=
centroids
[
0
][
1
]
x_r
=
centroids
[
1
][
0
]
y_r
=
centroids
[
1
][
1
]
c_l
=
self
.
regression_coefs_left
c_r
=
self
.
regression_coefs_right
self
.
angles
[
0
][
0
]
=
c_l
[
0
][
0
]
+
c_l
[
1
][
0
]
*
x_l
+
c_l
[
2
][
0
]
*
y_l
+
c_l
[
3
][
0
]
*
x_l
**
2
+
c_l
[
4
][
0
]
*
x_l
*
y_l
+
c_l
[
5
][
0
]
*
y_l
**
2
self
.
angles
[
0
][
1
]
=
c_l
[
0
][
1
]
+
c_l
[
1
][
1
]
*
x_l
+
c_l
[
2
][
1
]
*
y_l
+
c_l
[
3
][
1
]
*
x_l
**
2
+
c_l
[
4
][
1
]
*
x_l
*
y_l
+
c_l
[
5
][
1
]
*
y_l
**
2
self
.
angles
[
1
][
0
]
=
c_r
[
0
][
0
]
+
c_r
[
1
][
0
]
*
x_r
+
c_r
[
2
][
0
]
*
y_r
+
c_r
[
3
][
0
]
*
x_r
**
2
+
c_r
[
4
][
0
]
*
x_r
*
y_r
+
c_r
[
5
][
0
]
*
y_r
**
2
self
.
angles
[
1
][
1
]
=
c_r
[
0
][
1
]
+
c_r
[
1
][
1
]
*
x_r
+
c_r
[
2
][
1
]
*
y_r
+
c_r
[
3
][
1
]
*
x_r
**
2
+
c_r
[
4
][
1
]
*
x_r
*
y_r
+
c_r
[
5
][
1
]
*
y_r
**
2
# print(self.angles)
# print(self.angles)
self
.
angle_left_text_2
.
setText
(
str
(
self
.
angles
[
0
][
0
]))
self
.
angle_left_text_2
.
setText
(
str
(
self
.
angles
[
0
][
0
]))
self
.
angle_left_text_3
.
setText
(
str
(
self
.
angles
[
0
][
1
]))
self
.
angle_left_text_3
.
setText
(
str
(
self
.
angles
[
0
][
1
]))
...
@@ -375,31 +386,34 @@ class App(QWidget):
...
@@ -375,31 +386,34 @@ class App(QWidget):
print
(
anglesH_calib
.
reshape
(
1
,
-
1
).
shape
)
print
(
anglesH_calib
.
reshape
(
1
,
-
1
).
shape
)
print
(
self
.
calibH
[
0
,:].
shape
)
print
(
self
.
calibH
[
0
,:].
shape
)
self
.
reg_leftH
.
fit
(
anglesH_calib
.
reshape
(
-
1
,
1
),
self
.
calibH
[
0
,:])
self
.
angles_calib
=
np
.
array
([
anglesH_calib
,
anglesV_calib
]).
transpose
()
print
(
anglesH_calib
.
reshape
(
-
1
,
1
))
self
.
regression_coefs_left
=
calibration
.
polynomial_regression
(
self
.
calibH
[:,
0
],
self
.
calibV
[:,
0
],
self
.
angles_calib
,
deg
=
3
)
print
(
self
.
calibH
[
0
,:])
self
.
regression_coefs_right
=
calibration
.
polynomial_regression
(
self
.
calibH
[:,
1
],
self
.
calibV
[:,
1
],
self
.
angles_calib
,
deg
=
3
)
self
.
reg_rightH
.
fit
(
anglesH_calib
.
reshape
(
-
1
,
1
),
self
.
calibH
[
1
,:])
# self.reg_leftH.fit(anglesH_calib.reshape(-1,1), self.calibH[0,:])
self
.
reg_leftV
.
fit
(
anglesV_calib
.
reshape
(
-
1
,
1
),
self
.
calibV
[
0
,:])
# print(anglesH_calib.reshape(-1,1))
self
.
reg_rightV
.
fit
(
anglesV_calib
.
reshape
(
-
1
,
1
),
self
.
calibV
[
1
,:])
# print(self.calibH[0,:])
self
.
a_leftH
=
self
.
reg_leftH
.
coef_
# self.reg_rightH.fit(anglesH_calib.reshape(-1,1), self.calibH[1,:])
self
.
b_leftH
=
self
.
reg_leftH
.
intercept_
# self.reg_leftV.fit(anglesV_calib.reshape(-1,1), self.calibV[0,:])
self
.
a_rightH
=
self
.
reg_rightH
.
coef_
# self.reg_rightV.fit(anglesV_calib.reshape(-1,1), self.calibV[1,:])
self
.
b_rightH
=
self
.
reg_leftH
.
intercept_
# self.a_leftH = self.reg_leftH.coef_
self
.
a_leftV
=
self
.
reg_leftV
.
coef_
# self.b_leftH = self.reg_leftH.intercept_
self
.
b_leftV
=
self
.
reg_leftH
.
intercept_
# self.a_rightH = self.reg_rightH.coef_
self
.
a_rightV
=
self
.
reg_rightV
.
coef_
# self.b_rightH = self.reg_leftH.intercept_
self
.
b_rightV
=
self
.
reg_leftH
.
intercept_
# self.a_leftV = self.reg_leftV.coef_
print
(
self
.
a_leftH
)
# self.b_leftV = self.reg_leftH.intercept_
print
(
self
.
b_leftV
)
# self.a_rightV = self.reg_rightV.coef_
print
(
self
.
a_rightH
)
# self.b_rightV = self.reg_leftH.intercept_
print
(
self
.
b_rightV
)
# print(self.a_leftH)
print
(
self
.
a_leftH
)
# print(self.b_leftV)
print
(
self
.
b_leftV
)
# print(self.a_rightH)
print
(
self
.
a_rightH
)
# print(self.b_rightV)
print
(
self
.
b_rightV
)
# print(self.a_leftH)
plt
.
plot
(
anglesH_calib
,
self
.
calibH
[
0
,:],
'
r*
'
)
# print(self.b_leftV)
plt
.
plot
(
anglesH_calib
,
self
.
a_leftH
[
0
]
*
anglesH_calib
+
self
.
b_leftH
,
'
r-
'
)
# print(self.a_rightH)
plt
.
show
()
# print(self.b_rightV)
# plt.plot(anglesH_calib, self.calibH[0,:], 'r*')
# plt.plot(anglesH_calib, self.a_leftH[0] * anglesH_calib + self.b_leftH, 'r-')
# plt.show()
print
(
'
Calibration complete !
'
)
print
(
'
Calibration complete !
'
)
self
.
calib_step_label
.
setText
(
'
Calibration complete !
'
)
self
.
calib_step_label
.
setText
(
'
Calibration complete !
'
)
...
...
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