From a8799d322a97ad9f881eb32bc1fd8145db78b1ac Mon Sep 17 00:00:00 2001 From: danielbrownmsm Date: Sun, 2 Jun 2024 20:13:43 -0500 Subject: [PATCH] change from using separate IDs to using just whether to include or exclude it from the mask, as we only have one mask, and don't need separate colors for everything --- autonav_ws/src/autonav_display/src/display.py | 2 +- .../autonav_msgs/msg/CameraCalibration.msg | 4 +-- .../src/autonav_vision/src/transformations.py | 27 ++++++++++++------- display/scripts/main.js | 4 +-- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/autonav_ws/src/autonav_display/src/display.py b/autonav_ws/src/autonav_display/src/display.py index 5e885b2..5535673 100644 --- a/autonav_ws/src/autonav_display/src/display.py +++ b/autonav_ws/src/autonav_display/src/display.py @@ -232,7 +232,7 @@ async def consumer(self, websocket): if obj["op"] == "calibrate": msg = CameraCalibration() # there's calibrate ramp, calibrate ground, and maybe a calibrate barrel and/or calibrate line and maybe a calibrate white balance or something (calibrat paper?) - msg.id = int(obj["id"]) # and I guess each will have it's own id or something + msg.include_in_mask = int(obj["include"]) # and I guess each will have it's own id or something self.calibration_p.publish(msg) if obj["op"] == "get_presets": diff --git a/autonav_ws/src/autonav_msgs/msg/CameraCalibration.msg b/autonav_ws/src/autonav_msgs/msg/CameraCalibration.msg index 9881324..1261f08 100644 --- a/autonav_ws/src/autonav_msgs/msg/CameraCalibration.msg +++ b/autonav_ws/src/autonav_msgs/msg/CameraCalibration.msg @@ -1,2 +1,2 @@ -#TODO include a list of which ids mean which thing -int id \ No newline at end of file +# whether to include the colors in the mask or not +bool include_in_mask \ No newline at end of file diff --git a/autonav_ws/src/autonav_vision/src/transformations.py b/autonav_ws/src/autonav_vision/src/transformations.py index 9c84c41..5794d38 100644 --- a/autonav_ws/src/autonav_vision/src/transformations.py +++ b/autonav_ws/src/autonav_vision/src/transformations.py @@ -94,20 +94,27 @@ def system_state_transition(self, old: SystemState, updated: SystemState): def onCalibrate(self, msg: CameraCalibration): # only allow calibration if it's safe to do so, don't want to accidentally ruin a run or kill a person - if self.system_state is not AUTONOMOUS and self.system_state.mobility is False: + if self.system_state.state is not AUTONOMOUS and self.system_state.mobility is False: # remember that the mask is reversed though, we filter OUT the ground # so ground needs to be in the threshold range, but not obstacles # include in the mask, so it gets filtered out - if msg.id is RAMP or msg.id is GROUND: - pass #TODO ensure it's part of the mask - # to exclude from the mask, so it shows up for expandification - elif msg.id == BARREL or msg.id is LINE or msg.id is PAPER: - pass + if msg.include_in_mask: + pixels = [] #TODO + avgHue, avgSat, avgVal = getAverageVal(pixels) #TODO + + # take the lower of the current and calibrated values, so that as much as possible is included in the mask + self.config.lower_hue = min(self.config.lower_hue, avgHue) + self.config.lower_sat = min(self.config.lower_sat, avgSat) + self.config.lower_val = min(self.config.lower_val, avgVal) + + # take the upper of the current and calibrated values, so that as much as possible is included in the mask + self.config.upper_hue = max(self.config.upper_hue, avgHue) + self.config.upper_sat = max(self.config.upper_sat, avgSat) + self.config.upper_val = max(self.config.upper_val, avgVal) + + # exclude from the mask, so it shows up for expandification else: - #TODO probably throw an error here or something, we should never reach this spot of code - pass - else: - return + pass #TODO def config_updated(self, jsonObject): self.config = json.loads(self.jdump(jsonObject), object_hook=lambda d: SimpleNamespace(**d)) diff --git a/display/scripts/main.js b/display/scripts/main.js index ff4dc10..07d0fd5 100644 --- a/display/scripts/main.js +++ b/display/scripts/main.js @@ -558,14 +558,14 @@ $(document).ready(function () { $("#calibrate_include").on("click", function () { send({ op: "calibrate", - id: 0 + include: true }); }); $("#calibrate_exclude").on("click", function () { send({ op: "calibrate", - id: 1 + include: false }); });