diff --git a/scripts/planktoscope/imager.py b/scripts/planktoscope/imager.py index 81e4628..580a8dd 100644 --- a/scripts/planktoscope/imager.py +++ b/scripts/planktoscope/imager.py @@ -126,7 +126,7 @@ class ImagerProcess(multiprocessing.Process): """This class contains the main definitions for the imager of the PlanktoScope""" @logger.catch - def __init__(self, stop_event, iso=100, shutter_speed=500): + def __init__(self, stop_event, iso=200, shutter_speed=20): """Initialize the Imager class Args: @@ -188,6 +188,12 @@ class ImagerProcess(multiprocessing.Process): self.__iso = iso self.__shutter_speed = shutter_speed self.__exposure_mode = "fixedfps" + self.__white_balance = "off" + self.__white_balance_gain = ( + 200, + 140, + ) # Those values were tested on a HQ camera to give a whitish background + self.__base_path = "/home/pi/data/img" # Let's make sure the base path exists if not os.path.exists(self.__base_path): @@ -231,6 +237,24 @@ class ImagerProcess(multiprocessing.Process): "A timeout has occured when setting the exposure mode, trying again" ) self.__camera.exposure_mode = self.__exposure_mode + time.sleep(0.1) + + try: + self.__camera.white_balance = self.__white_balance + except TimeoutError as e: + logger.error( + "A timeout has occured when setting the white balance mode, trying again" + ) + self.__camera.white_balance = self.__white_balance + time.sleep(0.1) + + try: + self.__camera.white_balance_gain = self.__white_balance_gain + except TimeoutError as e: + logger.error( + "A timeout has occured when setting the white balance gain, trying again" + ) + self.__camera.white_balance_gain = self.__white_balance_gain logger.success("planktoscope.imager is initialised and ready to go!") @@ -324,6 +348,9 @@ class ImagerProcess(multiprocessing.Process): "acq_camera_iso": self.__iso, "acq_camera_shutter_speed": self.__shutter_speed, } + # TODO add here the field size metadata + # For cam HQ 4,15mm x 3,14mm, résolution 1µm/px + # For cam 2.1 2.31mm x 1,74mm, résolution 0.7µm/px # Concat the local metadata and the metadata from Node-RED self.__global_metadata = {**local_metadata, **nodered_metadata} diff --git a/scripts/planktoscope/light.py b/scripts/planktoscope/light.py index d4852e0..8ae0af4 100644 --- a/scripts/planktoscope/light.py +++ b/scripts/planktoscope/light.py @@ -8,7 +8,7 @@ # Library to send command over I2C for the light module on the fan import smbus import RPi.GPIO -import subprocess +import subprocess # nosec # define the bus used to actuate the light module on the fan bus = smbus.SMBus(1) @@ -22,25 +22,26 @@ rgb_off_reg = 0x07 ################################################################################ # LEDs functions ################################################################################ + + +def i2c_update(): + # Update the I2C Bus in order to really update the LEDs new values + subprocess.Popen("i2cdetect -y 1".split(), stdout=subprocess.PIPE) # nosec + + def setRGB(R, G, B): """Update all LED at the same time""" bus.write_byte_data(DEVICE_ADDRESS, 0x00, 0xFF) bus.write_byte_data(DEVICE_ADDRESS, 0x01, R & 0xFF) bus.write_byte_data(DEVICE_ADDRESS, 0x02, G & 0xFF) bus.write_byte_data(DEVICE_ADDRESS, 0x03, B & 0xFF) - - # Update the I2C Bus in order to really update the LEDs new values - cmd = "i2cdetect -y 1" - subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) + i2c_update() def setRGBOff(): """Turn off the RGB LED""" bus.write_byte_data(DEVICE_ADDRESS, 0x07, 0x00) - - # Update the I2C Bus in order to really update the LEDs new values - cmd = "i2cdetect -y 1" - subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) + i2c_update() def setRGBEffect(effect): @@ -88,6 +89,10 @@ def light(state): RPi.GPIO.output(21, RPi.GPIO.LOW) +## Wait message: Green +## Actuate message: White +## Pumping message: Blue + # This is called if this script is launched directly if __name__ == "__main__": # TODO This should be a test suite for this library diff --git a/scripts/planktoscope/raspimjpeg.py b/scripts/planktoscope/raspimjpeg.py index 1095a3b..06b3c38 100644 --- a/scripts/planktoscope/raspimjpeg.py +++ b/scripts/planktoscope/raspimjpeg.py @@ -25,6 +25,7 @@ class raspimjpeg(object): self.__binary = "/home/pi/PlanktonScope/scripts/raspimjpeg/bin/raspimjpeg" self.__statusfile = "/dev/shm/mjpeg/status_mjpeg.txt" self.__pipe = "/home/pi/PlanktonScope/scripts/raspimjpeg/FIFO" + self.__sensor_name = "" # make sure the status file exists and is empty if not os.path.exists(self.__statusfile): @@ -374,6 +375,32 @@ class raspimjpeg(object): ) raise ValueError + @property + def white_balance_gain(self): + return self.__white_balance_gain + + @white_balance_gain.setter + def white_balance_gain(self, gain): + """Change the camera white balance gain + + The gain value should be a int between 0 and 300. By default the camera + is set to use 150 both for the red and the blue gain. + + Args: + gain (tuple of int): Red gain and blue gain to use + """ + logger.debug(f"Setting the white balance mode to {gain}") + if (0 < gain[0] < 300) and (0 < gain[1] < 300): + self.__white_balance_gain = gain + self.__send_command( + f"ag {self.__white_balance_gain[0]} {self.__white_balance_gain[1]}" + ) + else: + logger.error( + f"The camera white balance gain specified ({gain}) is not valid" + ) + raise ValueError + @property def image_quality(self): return self.__image_quality diff --git a/scripts/raspimjpeg/bin/raspimjpeg b/scripts/raspimjpeg/bin/raspimjpeg index 24d3f8c..9c197a9 100755 Binary files a/scripts/raspimjpeg/bin/raspimjpeg and b/scripts/raspimjpeg/bin/raspimjpeg differ diff --git a/scripts/raspimjpeg/raspimjpeg.conf b/scripts/raspimjpeg/raspimjpeg.conf index 5e8673c..3a3c162 100644 --- a/scripts/raspimjpeg/raspimjpeg.conf +++ b/scripts/raspimjpeg/raspimjpeg.conf @@ -89,7 +89,7 @@ MP4Box_cmd (set -e;MP4Box -fps %i -add %s %s > /dev/null 2>&1;rm "%s";) & # image_width 3280 image_height 2464 -image_quality 25 +image_quality 80 #time lapse interval 0.1 sec units tl_interval 30