From e276e4f06bc49106a05f9ae46649b419e1ab6f36 Mon Sep 17 00:00:00 2001 From: - <-> Date: Fri, 22 Dec 2023 00:58:28 +0100 Subject: [PATCH 1/2] added commands for - shutter close/open - shutter auto mode disable/enable - gain select - triggering NUC calibration - getting shutter state --- P2Pro/P2Pro_cmd.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/P2Pro/P2Pro_cmd.py b/P2Pro/P2Pro_cmd.py index 12fc2eb..0286e40 100644 --- a/P2Pro/P2Pro_cmd.py +++ b/P2Pro/P2Pro_cmd.py @@ -34,6 +34,19 @@ class PseudoColorTypes(enum.IntEnum): # RED_HOT_MODE = 26 +class ShutterStaTypes(enum.IntEnum): + SHUTTER_CTL_DIS = 0 + SHUTTER_CTL_EN = 1 + +class ShutterManualTypes(enum.IntEnum): + SHUTTER_OPEN = 0 + SHUTTER_CLOSE = 1 + +class OocBUpdateTypes(enum.IntEnum): + B_UPDATE = 0 # update B value + OOC_UPDATE = 1 # update OOC value + OOC_B_UPDATE = 2 # update both B and OOC value + class PropTpdParams(enum.IntEnum): TPD_PROP_DISTANCE = 0 # 1/163.835 m, 0-32767, Distance TPD_PROP_TU = 1 # 1 K, 0-1024, Reflection temperature @@ -66,7 +79,11 @@ class CmdCode(enum.IntEnum): spi_transfer = 0x8201 get_device_info = 0x8405 pseudo_color = 0x8409 + shutter_sta_set = 0x410c + shutter_sta_get = 0x830c + shutter_switch = 0x420c shutter_vtemp = 0x840c + ooc_b_update = 0xc10d prop_tpd_params = 0x8514 cur_vtemp = 0x8b0d preview_start = 0xc10f @@ -242,6 +259,51 @@ def pseudo_color_get(self, preview_path: int = 0) -> PseudoColorTypes: res = self._standard_cmd_read(CmdCode.pseudo_color, preview_path, 1) return PseudoColorTypes(int.from_bytes(res, 'little')) + def shutter_sta_set(self, sta_type: ShutterStaTypes): + self._standard_cmd_write(CmdCode.shutter_sta_set, sta_type) + + def shutter_sta_get(self): + res = self._standard_cmd_read(CmdCode.shutter_sta_get, 0, 2) + return res[0], res[1] + + def shutter_switch(self, manual_type: ShutterManualTypes): + self._standard_cmd_write(CmdCode.shutter_switch, manual_type) + + def ooc_b_update(self, update_type: OocBUpdateTypes): + self._standard_cmd_write(CmdCode.ooc_b_update, update_type) + + def shutter_actuate(self): + log.info("Shutter") + self.shutter_sta_set(ShutterStaTypes.SHUTTER_CTL_EN) + self.ooc_b_update(OocBUpdateTypes.B_UPDATE) + + def shutter_background(self): + log.info("Shutter background") + self.shutter_sta_set(ShutterStaTypes.SHUTTER_CTL_DIS) + self.shutter_switch(ShutterManualTypes.SHUTTER_OPEN) + self.ooc_b_update(OocBUpdateTypes.B_UPDATE) + self.shutter_sta_set(ShutterStaTypes.SHUTTER_CTL_EN) + + def get_shutter_state(self): + sta_type, smt_type = self.shutter_sta_get() + if (smt_type == 0): # 0 = closed, 1 = open + log.info("Shutter state: closed") + else: + log.info("Shutter state: open") + if (sta_type == ShutterStaTypes.SHUTTER_CTL_DIS): + log.info("Shutter control: disabled") + else: + log.info("Shutter control: enabled") + return smt_type, sta_type + + def gain_set_low(self): + log.info("low gain") + self.set_prop_tpd_params(PropTpdParams.TPD_PROP_GAIN_SEL, 0) + + def gain_set_high(self): + log.info("high gain") + self.set_prop_tpd_params(PropTpdParams.TPD_PROP_GAIN_SEL, 1) + def set_prop_tpd_params(self, tpd_param: PropTpdParams, value: int): self._long_cmd_write(CmdCode.prop_tpd_params | CmdDir.SET, tpd_param, value) From 163860a8e5e0a3ad7fdee761bd65e0f1a60fc50d Mon Sep 17 00:00:00 2001 From: - <-> Date: Fri, 22 Dec 2023 01:02:11 +0100 Subject: [PATCH 2/2] color coding fix that applies when internal camera palettes are set --- P2Pro/video.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/P2Pro/video.py b/P2Pro/video.py index 9f95860..84c6087 100644 --- a/P2Pro/video.py +++ b/P2Pro/video.py @@ -114,7 +114,7 @@ def open(self, camera_id: Union[int, str] = -1): # convert buffers to numpy arrays yuv_picture = np.frombuffer(picture_data, dtype=np.uint8).reshape((P2Pro_resolution[1] // 2, P2Pro_resolution[0], 2)) - rgb_picture = cv2.cvtColor(yuv_picture, cv2.COLOR_YUV2RGB_YUY2) + rgb_picture = cv2.cvtColor(yuv_picture, cv2.COLOR_YUV2BGR_YUY2) thermal_picture_16 = np.frombuffer(thermal_data, dtype=np.uint16).reshape((P2Pro_resolution[1] // 2, P2Pro_resolution[0])) # pack parsed frame data into object