Add get_tuning_algo method to StreamingPiCamera2
This commit is contained in:
parent
46be94383a
commit
fdae0b9226
2 changed files with 37 additions and 3 deletions
|
|
@ -38,6 +38,26 @@ def client(picamera_thing) -> lt.ThingClient:
|
||||||
yield client
|
yield client
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_tuning_algo(picamera_thing):
|
||||||
|
"""Test that get_tuning algorithm retrieves tuning algorithms."""
|
||||||
|
# Missing algorithm returns None
|
||||||
|
assert picamera_thing.get_tuning_algo("foo") is None
|
||||||
|
# Real algorithm is a dict and contains expected keys
|
||||||
|
assert isinstance(picamera_thing.get_tuning_algo("rpi.geq"), dict)
|
||||||
|
assert "offset" in picamera_thing.get_tuning_algo("rpi.geq")
|
||||||
|
|
||||||
|
# Set the tuning to None as it is technically optional. And check this
|
||||||
|
# is handled gracefully.
|
||||||
|
try:
|
||||||
|
picamera_thing.tuning = None
|
||||||
|
except lt.exceptions.NotConnectedToServerError:
|
||||||
|
# Labthings will complain that it is not connected to a server
|
||||||
|
pass
|
||||||
|
# Check it is set to None.
|
||||||
|
assert picamera_thing.tuning is None
|
||||||
|
assert picamera_thing.get_tuning_algo("rpi.geq") is None
|
||||||
|
|
||||||
|
|
||||||
def test_calibration(picamera_thing, client):
|
def test_calibration(picamera_thing, client):
|
||||||
"""Check that full auto calibrate completes without an exception."""
|
"""Check that full auto calibrate completes without an exception."""
|
||||||
tuning = picamera_thing.tuning
|
tuning = picamera_thing.tuning
|
||||||
|
|
|
||||||
|
|
@ -308,6 +308,19 @@ class StreamingPiCamera2(BaseCamera):
|
||||||
tuning = lt.ThingSetting(Optional[dict], None, readonly=True)
|
tuning = lt.ThingSetting(Optional[dict], None, readonly=True)
|
||||||
"""The Raspberry PiCamera Tuning File JSON."""
|
"""The Raspberry PiCamera Tuning File JSON."""
|
||||||
|
|
||||||
|
def get_tuning_algo(self, algorithm_name: str) -> Optional[dict]:
|
||||||
|
"""Return the active tuning algorithm settings for the given algorithm.
|
||||||
|
|
||||||
|
:returns: The algorithm dictionary if found, returns None if no tuning data
|
||||||
|
is loaded or if the tuning algorithm is not found.
|
||||||
|
"""
|
||||||
|
if self.tuning is None:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
return Picamera2.find_tuning_algo(self.tuning, algorithm_name)
|
||||||
|
except StopIteration:
|
||||||
|
return None
|
||||||
|
|
||||||
def _initialise_picamera(self):
|
def _initialise_picamera(self):
|
||||||
"""Acquire the picamera device and store it as ``self._picamera``.
|
"""Acquire the picamera device and store it as ``self._picamera``.
|
||||||
|
|
||||||
|
|
@ -754,6 +767,7 @@ class StreamingPiCamera2(BaseCamera):
|
||||||
* ``auto_expose_from_minimum``
|
* ``auto_expose_from_minimum``
|
||||||
* ``set_static_green_equalisation`` to set geq offset to max
|
* ``set_static_green_equalisation`` to set geq offset to max
|
||||||
* ``calibrate_lens_shading``
|
* ``calibrate_lens_shading``
|
||||||
|
* ``reset_ccm``
|
||||||
* ``calibrate_white_balance``
|
* ``calibrate_white_balance``
|
||||||
* ``set_background``
|
* ``set_background``
|
||||||
"""
|
"""
|
||||||
|
|
@ -761,8 +775,8 @@ class StreamingPiCamera2(BaseCamera):
|
||||||
self.auto_expose_from_minimum()
|
self.auto_expose_from_minimum()
|
||||||
self.set_static_green_equalisation()
|
self.set_static_green_equalisation()
|
||||||
self.calibrate_lens_shading()
|
self.calibrate_lens_shading()
|
||||||
self.calibrate_white_balance()
|
|
||||||
self.reset_ccm()
|
self.reset_ccm()
|
||||||
|
self.calibrate_white_balance()
|
||||||
self.set_background(portal)
|
self.set_background(portal)
|
||||||
|
|
||||||
@lt.thing_action
|
@lt.thing_action
|
||||||
|
|
@ -881,7 +895,7 @@ class StreamingPiCamera2(BaseCamera):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Note "alsc" is the Picamera2 term for "Automatic Lens Shading Correction"
|
# Note "alsc" is the Picamera2 term for "Automatic Lens Shading Correction"
|
||||||
alsc = Picamera2.find_tuning_algo(self.tuning, "rpi.alsc")
|
alsc = self.get_tuning_algo("rpi.alsc")
|
||||||
|
|
||||||
# Check there is exactly 1 correction table for red-difference chroma (Cr)
|
# Check there is exactly 1 correction table for red-difference chroma (Cr)
|
||||||
# and blue-difference chroma (Cb)
|
# and blue-difference chroma (Cb)
|
||||||
|
|
@ -952,7 +966,7 @@ class StreamingPiCamera2(BaseCamera):
|
||||||
colour across the image.
|
colour across the image.
|
||||||
"""
|
"""
|
||||||
with self._streaming_picamera(pause_stream=True):
|
with self._streaming_picamera(pause_stream=True):
|
||||||
alsc = Picamera2.find_tuning_algo(self.tuning, "rpi.alsc")
|
alsc = self.get_tuning_algo("rpi.alsc")
|
||||||
luminance = alsc["luminance_lut"]
|
luminance = alsc["luminance_lut"]
|
||||||
flat = np.ones((12, 16))
|
flat = np.ones((12, 16))
|
||||||
recalibrate_utils.set_static_lst(self.tuning, luminance, flat, flat)
|
recalibrate_utils.set_static_lst(self.tuning, luminance, flat, flat)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue