Update default exposure in picam and defaul LST values in tuning files, and set default colour gains from LST
This commit is contained in:
parent
c0362ee8dd
commit
982c55905c
6 changed files with 67 additions and 40 deletions
|
|
@ -163,6 +163,10 @@ class StreamingPiCamera2(BaseCamera):
|
||||||
# a server. But we know this, so we ignore the error.
|
# a server. But we know this, so we ignore the error.
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Also set the colour gains based on the tuning. Set to _colour_gains to not
|
||||||
|
# trigger a NotConnectedToServerError
|
||||||
|
self._colour_gains = tf_utils.get_colour_gains_from_lst(self.tuning)
|
||||||
|
|
||||||
stream_resolution = lt.ThingProperty(
|
stream_resolution = lt.ThingProperty(
|
||||||
tuple[int, int],
|
tuple[int, int],
|
||||||
initial_value=(820, 616),
|
initial_value=(820, 616),
|
||||||
|
|
@ -246,7 +250,7 @@ class StreamingPiCamera2(BaseCamera):
|
||||||
with self._streaming_picamera() as cam:
|
with self._streaming_picamera() as cam:
|
||||||
cam.set_controls({"ColourGains": value})
|
cam.set_controls({"ColourGains": value})
|
||||||
|
|
||||||
_exposure_time: int = 0
|
_exposure_time: int = 500
|
||||||
|
|
||||||
@lt.thing_setting
|
@lt.thing_setting
|
||||||
def exposure_time(self) -> int:
|
def exposure_time(self) -> int:
|
||||||
|
|
@ -691,8 +695,7 @@ class StreamingPiCamera2(BaseCamera):
|
||||||
# Re-initialise the picamera to reload the tuning file.
|
# Re-initialise the picamera to reload the tuning file.
|
||||||
self._initialise_picamera()
|
self._initialise_picamera()
|
||||||
|
|
||||||
# Set colour gains based on the LST results
|
self.colour_gains = tf_utils.get_colour_gains_from_lst(self.tuning)
|
||||||
self.colour_gains = (float(np.min(Cr)), float(np.min(Cb)))
|
|
||||||
|
|
||||||
@lt.thing_property
|
@lt.thing_property
|
||||||
def colour_correction_matrix(
|
def colour_correction_matrix(
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,19 @@ def get_lst(tuning: dict) -> LensShading:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_colour_gains_from_lst(tuning: dict) -> tuple[float, float]:
|
||||||
|
"""Get the colour gains that are needed from the lens shading tables.
|
||||||
|
|
||||||
|
The lens shading tables are calculated to create a white balanced image, but the
|
||||||
|
ISP normalises by the minimum Cr and Cb value. So these need to be set as colour
|
||||||
|
gains.
|
||||||
|
"""
|
||||||
|
alsc = find_tuning_algo(tuning, "rpi.alsc")
|
||||||
|
min_cr = float(min(alsc["calibrations_Cr"][0]["table"]))
|
||||||
|
min_cb = float(min(alsc["calibrations_Cb"][0]["table"]))
|
||||||
|
return (min_cr, min_cb)
|
||||||
|
|
||||||
|
|
||||||
def lst_calibrated(tuning: dict) -> bool:
|
def lst_calibrated(tuning: dict) -> bool:
|
||||||
"""Whether the lens shading table is calibrated.
|
"""Whether the lens shading table is calibrated.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,11 @@ We also set `n_iter: 0` this stops it adding iterative adaptuion.
|
||||||
|
|
||||||
As there is only one table the colour temperature is ignored. We set the colour temperature to 1234 in the tuning file to make it clear that we have not calibrated it on the microscope. We set the colour temperature to 5000 (our actual illumination colour temperature) once recalibrated.
|
As there is only one table the colour temperature is ignored. We set the colour temperature to 1234 in the tuning file to make it clear that we have not calibrated it on the microscope. We set the colour temperature to 5000 (our actual illumination colour temperature) once recalibrated.
|
||||||
|
|
||||||
|
The tables are flat 1s for luninance on for both sensors.
|
||||||
|
|
||||||
|
For the IMX477 (PiCamera HQ) the Cr and Cb tables are flat, but Cb is 2.0 not 1.0 for all values. This is so that the initial colour gains are set to (1.0, 2.0)
|
||||||
|
|
||||||
|
For the IMX219 (PiCamera v2) the Cr and Cb tables are symmetric tables taken from the top quadrant of a calibrated microscope. They are used to create a good enough correction that the microscope is usable for alignment.
|
||||||
|
|
||||||
### rpi.contrast - Contrast
|
### rpi.contrast - Contrast
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,18 +96,18 @@
|
||||||
{
|
{
|
||||||
"ct": 1234,
|
"ct": 1234,
|
||||||
"table": [
|
"table": [
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.209, 1.200, 1.197, 1.189, 1.169, 1.150, 1.135, 1.128, 1.128, 1.135, 1.150, 1.169, 1.189, 1.197, 1.200, 1.209,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.180, 1.195, 1.216, 1.233, 1.240, 1.238, 1.235, 1.233, 1.233, 1.235, 1.238, 1.240, 1.233, 1.216, 1.195, 1.180,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.147, 1.175, 1.217, 1.264, 1.304, 1.324, 1.338, 1.345, 1.345, 1.338, 1.324, 1.304, 1.264, 1.217, 1.175, 1.147,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.110, 1.144, 1.207, 1.279, 1.346, 1.391, 1.414, 1.425, 1.425, 1.414, 1.391, 1.346, 1.279, 1.207, 1.144, 1.110,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.083, 1.116, 1.184, 1.278, 1.363, 1.426, 1.464, 1.473, 1.473, 1.464, 1.426, 1.363, 1.278, 1.184, 1.116, 1.083,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.068, 1.101, 1.170, 1.267, 1.365, 1.441, 1.485, 1.497, 1.497, 1.485, 1.441, 1.365, 1.267, 1.170, 1.101, 1.068,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.068, 1.101, 1.170, 1.267, 1.365, 1.441, 1.485, 1.497, 1.497, 1.485, 1.441, 1.365, 1.267, 1.170, 1.101, 1.068,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.083, 1.116, 1.184, 1.278, 1.363, 1.426, 1.464, 1.473, 1.473, 1.464, 1.426, 1.363, 1.278, 1.184, 1.116, 1.083,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.110, 1.144, 1.207, 1.279, 1.346, 1.391, 1.414, 1.425, 1.425, 1.414, 1.391, 1.346, 1.279, 1.207, 1.144, 1.110,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.147, 1.175, 1.217, 1.264, 1.304, 1.324, 1.338, 1.345, 1.345, 1.338, 1.324, 1.304, 1.264, 1.217, 1.175, 1.147,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.180, 1.195, 1.216, 1.233, 1.240, 1.238, 1.235, 1.233, 1.233, 1.235, 1.238, 1.240, 1.233, 1.216, 1.195, 1.180,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
|
1.209, 1.200, 1.197, 1.189, 1.169, 1.150, 1.135, 1.128, 1.128, 1.135, 1.150, 1.169, 1.189, 1.197, 1.200, 1.209
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
@ -115,18 +115,18 @@
|
||||||
{
|
{
|
||||||
"ct": 1234,
|
"ct": 1234,
|
||||||
"table": [
|
"table": [
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.318, 1.320, 1.322, 1.329, 1.330, 1.327, 1.337, 1.343, 1.343, 1.337, 1.327, 1.330, 1.329, 1.322, 1.320, 1.318,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.296, 1.311, 1.332, 1.357, 1.374, 1.382, 1.400, 1.421, 1.421, 1.400, 1.382, 1.374, 1.357, 1.332, 1.311, 1.296,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.279, 1.296, 1.334, 1.376, 1.410, 1.435, 1.462, 1.490, 1.490, 1.462, 1.435, 1.410, 1.376, 1.334, 1.296, 1.279,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.268, 1.284, 1.325, 1.387, 1.439, 1.471, 1.508, 1.541, 1.541, 1.508, 1.471, 1.439, 1.387, 1.325, 1.284, 1.268,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.259, 1.286, 1.324, 1.392, 1.457, 1.506, 1.550, 1.586, 1.586, 1.550, 1.506, 1.457, 1.392, 1.324, 1.286, 1.259,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.262, 1.291, 1.337, 1.398, 1.461, 1.522, 1.576, 1.617, 1.617, 1.576, 1.522, 1.461, 1.398, 1.337, 1.291, 1.262,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.262, 1.291, 1.337, 1.398, 1.461, 1.522, 1.576, 1.617, 1.617, 1.576, 1.522, 1.461, 1.398, 1.337, 1.291, 1.262,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.259, 1.286, 1.324, 1.392, 1.457, 1.506, 1.550, 1.586, 1.586, 1.550, 1.506, 1.457, 1.392, 1.324, 1.286, 1.259,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.268, 1.284, 1.325, 1.387, 1.439, 1.471, 1.508, 1.541, 1.541, 1.508, 1.471, 1.439, 1.387, 1.325, 1.284, 1.268,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.279, 1.296, 1.334, 1.376, 1.410, 1.435, 1.462, 1.490, 1.490, 1.462, 1.435, 1.410, 1.376, 1.334, 1.296, 1.279,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
1.296, 1.311, 1.332, 1.357, 1.374, 1.382, 1.400, 1.421, 1.421, 1.400, 1.382, 1.374, 1.357, 1.332, 1.311, 1.296,
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
|
1.318, 1.320,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||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
|
2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ def test_load_tuning(imx219_tuning, imx477_tuning):
|
||||||
("rpi.sdn", True),
|
("rpi.sdn", True),
|
||||||
("rpi.awb", True),
|
("rpi.awb", True),
|
||||||
("rpi.agc", True),
|
("rpi.agc", True),
|
||||||
("rpi.alsc", True),
|
("rpi.alsc", False),
|
||||||
("rpi.contrast", True),
|
("rpi.contrast", True),
|
||||||
("rpi.ccm", False),
|
("rpi.ccm", False),
|
||||||
("rpi.sharpen", True),
|
("rpi.sharpen", True),
|
||||||
|
|
@ -124,6 +124,12 @@ def test_tuning_lst_tools(imx219_tuning, imx477_tuning):
|
||||||
assert lst_model.colour_temp == tf_utils.DEFAULT_COLOUR_TEMP
|
assert lst_model.colour_temp == tf_utils.DEFAULT_COLOUR_TEMP
|
||||||
|
|
||||||
|
|
||||||
|
def test_tuning_initial_colour_gains(imx219_tuning, imx477_tuning):
|
||||||
|
"""The initial colour gains are as expected."""
|
||||||
|
assert tf_utils.get_colour_gains_from_lst(imx219_tuning) == (1.068, 1.259)
|
||||||
|
assert tf_utils.get_colour_gains_from_lst(imx477_tuning) == (1.0, 2.0)
|
||||||
|
|
||||||
|
|
||||||
def test_setting_lst(imx219_tuning):
|
def test_setting_lst(imx219_tuning):
|
||||||
"""Check that the LST can be set."""
|
"""Check that the LST can be set."""
|
||||||
lum = RNG.normal(size=(12, 16))
|
lum = RNG.normal(size=(12, 16))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue