Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LMS
FishUI
Commits
3bcdf5ea
Commit
3bcdf5ea
authored
Jun 18, 2020
by
Andy Regensky
Browse files
New feature: Support calibrated projection and read calibration coefficients from .txt file
parent
2ec37b19
Changes
5
Hide whitespace changes
Inline
Side-by-side
calib_data.txt
0 → 100644
View file @
3bcdf5ea
0.03145, -0.24345, 0.75722, -1.2132, 1.136, -0.78004, 0.43818, -0.10717, 0.0043719, 1.5678, 1.6278e-06
\ No newline at end of file
fishui/MainViewModel.py
View file @
3bcdf5ea
...
...
@@ -15,6 +15,7 @@ class MainViewModel(QObject):
self
.
sensor_size_px
=
(
1088
,
1088
)
self
.
focal_length_mm
=
1.8
self
.
projection_cls
=
projections
.
EquisolidProjection
self
.
calibration_coeffs
=
None
self
.
origin
=
(
512
,
512
)
self
.
blocksize
=
(
64
,
64
)
...
...
@@ -61,6 +62,14 @@ class MainViewModel(QObject):
self
.
projection_cls
=
projection_cls
self
.
updateProjections
()
def
setCalibrationData
(
self
,
calib_file
):
with
open
(
calib_file
,
'r'
)
as
file
:
calib_str
=
file
.
read
()
calib_coeffs
=
np
.
array
([
float
(
coeff
)
for
coeff
in
calib_str
.
split
(
","
)])
if
len
(
calib_coeffs
)
==
0
:
raise
ValueError
self
.
calibration_coeffs
=
calib_coeffs
def
setOrigin
(
self
,
origin
):
self
.
origin
=
origin
self
.
updateProjections
()
...
...
@@ -89,7 +98,12 @@ class MainViewModel(QObject):
def
updateProjections
(
self
):
focal_length_px
=
projections
.
Projection
.
to_focal_length_px
(
self
.
focal_length_mm
,
self
.
sensor_size_mm
,
self
.
sensor_size_px
)
self
.
projection
=
self
.
projection_cls
(
focal_length_px
)
if
self
.
projection_cls
==
projections
.
CalibratedProjection
:
px_per_mm
=
self
.
sensor_size_px
[
0
]
/
self
.
sensor_size_mm
[
0
]
calib_coeffs
=
self
.
calibration_coeffs
*
px_per_mm
self
.
projection
=
projections
.
CalibratedProjection
(
calib_coeffs
,
focal_length_px
)
else
:
self
.
projection
=
self
.
projection_cls
(
focal_length_px
)
self
.
perspective
=
projections
.
PerspectiveProjection
(
focal_length_px
)
self
.
fov_180_radius
=
self
.
projection
.
radius
(
np
.
deg2rad
(
90
))
self
.
blockSignals
(
True
)
...
...
@@ -206,17 +220,3 @@ class MainViewModel(QObject):
self
.
block_ctr_pym
=
block_ctr_pym
self
.
block_ctr_pxm
=
block_ctr_pxm
self
.
didChange
.
emit
()
# Preview
if
__name__
==
'__main__'
:
@
Slot
()
def
didChange
():
print
(
"Did change"
)
viewModel
=
MainViewModel
()
viewModel
.
didChange
.
connect
(
didChange
)
viewModel
.
setBlocksize
((
64
,
64
))
viewModel
.
setOrigin
((
256
,
256
))
fishui/widgets/FisheyeBlockWidget.py
View file @
3bcdf5ea
...
...
@@ -90,30 +90,3 @@ class FisheyeBlockWidget(QWidget):
def
mouseReleaseEvent
(
self
,
event
):
self
.
initialOrigin
=
None
self
.
initialMouse
=
None
# For preview
if
__name__
==
'__main__'
:
app
=
QApplication
(
sys
.
argv
)
app
.
setStyle
(
"Fusion"
)
palette
=
QPalette
()
palette
.
setColor
(
QPalette
.
Window
,
QColor
(
53
,
53
,
53
))
palette
.
setColor
(
QPalette
.
WindowText
,
Qt
.
white
)
palette
.
setColor
(
QPalette
.
Base
,
QColor
(
25
,
25
,
25
))
palette
.
setColor
(
QPalette
.
AlternateBase
,
QColor
(
53
,
53
,
53
))
palette
.
setColor
(
QPalette
.
ToolTipBase
,
Qt
.
white
)
palette
.
setColor
(
QPalette
.
ToolTipText
,
Qt
.
white
)
palette
.
setColor
(
QPalette
.
Text
,
Qt
.
white
)
palette
.
setColor
(
QPalette
.
Button
,
QColor
(
53
,
53
,
53
))
palette
.
setColor
(
QPalette
.
ButtonText
,
Qt
.
white
)
palette
.
setColor
(
QPalette
.
BrightText
,
Qt
.
red
)
palette
.
setColor
(
QPalette
.
Link
,
QColor
(
42
,
130
,
218
))
palette
.
setColor
(
QPalette
.
Highlight
,
QColor
(
42
,
130
,
218
))
palette
.
setColor
(
QPalette
.
HighlightedText
,
Qt
.
black
)
app
.
setPalette
(
palette
)
preview
=
FisheyeBlockWidget
(
None
,
MainViewModel
())
preview
.
show
()
sys
.
exit
(
app
.
exec_
())
\ No newline at end of file
fishui/widgets/PerspectiveBlockWidget.py
View file @
3bcdf5ea
...
...
@@ -118,30 +118,3 @@ class PerspectiveBlockWidget(QWidget):
self
.
initialMV0
=
None
self
.
initialMV1
=
None
self
.
initialMouse
=
None
# For preview
if
__name__
==
'__main__'
:
app
=
QApplication
(
sys
.
argv
)
app
.
setStyle
(
"Fusion"
)
palette
=
QPalette
()
palette
.
setColor
(
QPalette
.
Window
,
QColor
(
53
,
53
,
53
))
palette
.
setColor
(
QPalette
.
WindowText
,
Qt
.
white
)
palette
.
setColor
(
QPalette
.
Base
,
QColor
(
25
,
25
,
25
))
palette
.
setColor
(
QPalette
.
AlternateBase
,
QColor
(
53
,
53
,
53
))
palette
.
setColor
(
QPalette
.
ToolTipBase
,
Qt
.
white
)
palette
.
setColor
(
QPalette
.
ToolTipText
,
Qt
.
white
)
palette
.
setColor
(
QPalette
.
Text
,
Qt
.
white
)
palette
.
setColor
(
QPalette
.
Button
,
QColor
(
53
,
53
,
53
))
palette
.
setColor
(
QPalette
.
ButtonText
,
Qt
.
white
)
palette
.
setColor
(
QPalette
.
BrightText
,
Qt
.
red
)
palette
.
setColor
(
QPalette
.
Link
,
QColor
(
42
,
130
,
218
))
palette
.
setColor
(
QPalette
.
Highlight
,
QColor
(
42
,
130
,
218
))
palette
.
setColor
(
QPalette
.
HighlightedText
,
Qt
.
black
)
app
.
setPalette
(
palette
)
preview
=
PerspectiveBlockWidget
(
None
,
MainViewModel
())
preview
.
show
()
sys
.
exit
(
app
.
exec_
())
\ No newline at end of file
fishui/widgets/PropertiesWidget.py
View file @
3bcdf5ea
from
PySide2.QtGui
import
QIntValidator
,
QDoubleValidator
from
PySide2.QtWidgets
import
QWidget
,
QLabel
,
QLineEdit
,
QGridLayout
,
QSpacerItem
,
QSlider
,
QCheckBox
,
QComboBox
from
PySide2.QtWidgets
import
(
QWidget
,
QLabel
,
QLineEdit
,
QGridLayout
,
QSpacerItem
,
QSlider
,
QCheckBox
,
QComboBox
,
QFileDialog
)
from
PySide2.QtCore
import
Slot
,
Qt
from
fishui.MainViewModel
import
MainViewModel
import
fishui.projections
as
projections
...
...
@@ -61,7 +62,8 @@ class PropertiesWidget(QWidget):
self
.
projections
=
{
'equisolid'
:
projections
.
EquisolidProjection
,
'equidistant'
:
projections
.
EquidistantProjection
,
'orthographic'
:
projections
.
OrthographicProjection
,
'stereographic'
:
projections
.
StereographicProjection
}
'stereographic'
:
projections
.
StereographicProjection
,
'calibrated'
:
projections
.
CalibratedProjection
}
self
.
projectionComboBox
=
QComboBox
(
self
)
self
.
projectionComboBox
.
addItems
(
list
(
self
.
projections
.
keys
()))
self
.
projectionComboBox
.
currentTextChanged
.
connect
(
self
.
projectionComboBoxTextChanged
)
...
...
@@ -223,6 +225,17 @@ class PropertiesWidget(QWidget):
@
Slot
()
def
projectionComboBoxTextChanged
(
self
):
projection
=
self
.
projectionComboBox
.
currentText
()
if
projection
==
"calibrated"
:
calib_file
=
QFileDialog
.
getOpenFileName
(
self
,
"Open calibration data (.txt)"
,
"."
,
"Text files (""*.txt)"
)
try
:
self
.
viewModel
.
setCalibrationData
(
calib_file
[
0
])
except
:
self
.
updateValues
()
return
self
.
viewModel
.
setProjectionCls
(
self
.
projections
[
self
.
projectionComboBox
.
currentText
()])
@
Slot
()
...
...
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