From 75e062005958fe655459dbdd119a3abd480c9f0f Mon Sep 17 00:00:00 2001 From: sergiopaniego Date: Mon, 18 Oct 2021 11:07:33 +0000 Subject: [PATCH] Removed camera deviation calculation --- .../brains/f1/brain_f1_explicit.py | 3 -- behavior_metrics/brains/f1/brain_f1_keras.py | 35 ------------------- behavior_metrics/ui/gui/views/stats_window.py | 2 -- behavior_metrics/utils/controller.py | 4 --- 4 files changed, 44 deletions(-) diff --git a/behavior_metrics/brains/f1/brain_f1_explicit.py b/behavior_metrics/brains/f1/brain_f1_explicit.py index cc1d5e62..5e35e3a0 100644 --- a/behavior_metrics/brains/f1/brain_f1_explicit.py +++ b/behavior_metrics/brains/f1/brain_f1_explicit.py @@ -15,7 +15,6 @@ def __init__(self, sensors, actuators, handler, config=None): self.x_middle_left_above = 0 self.deviation_left = 0 - self.camera_deviation_error = [] # self.iteration = 0 # self.json_data = [] self.lock = threading.Lock() @@ -142,8 +141,6 @@ def execute(self): x_middle_left_down, not_found_down = self.check_center(position_x_down) x_middle_left_middle, not_found_middle = self.check_center(position_x_middle) - self.camera_deviation_error.append(abs(326 - x_middle_left_down) if not_found_down is False else 500) - # We look if white pixels of the row above are located if (len(position_x_above[0]) > 1): self.x_middle_left_above = (position_x_above[0][0] + position_x_above[0][ diff --git a/behavior_metrics/brains/f1/brain_f1_keras.py b/behavior_metrics/brains/f1/brain_f1_keras.py index 50c842ed..28c2e033 100644 --- a/behavior_metrics/brains/f1/brain_f1_keras.py +++ b/behavior_metrics/brains/f1/brain_f1_keras.py @@ -44,7 +44,6 @@ def __init__(self, sensors, actuators, model=None, handler=None, config=None): self.cont = 0 self.inference_times = [] self.config = config - self.camera_deviation_error = [] if self.config['GPU'] is False: os.environ["CUDA_VISIBLE_DEVICES"]="-1" @@ -89,38 +88,6 @@ def get_point(self, index, img): mid = np.abs(left - right) / 2 + left return int(mid) - def get_camera_deviation_error(self, image_cropped): - image_hsv = cv2.cvtColor(image_cropped, cv2.COLOR_RGB2HSV) - lower_red = np.array([0, 50, 50]) - upper_red = np.array([180, 255, 255]) - image_mask = cv2.inRange(image_hsv, lower_red, upper_red) - - rows, cols = image_mask.shape - rows = rows - 1 # para evitar desbordamiento - - alt = 0 - ff = cv2.reduce(image_mask, 1, cv2.REDUCE_SUM, dtype=cv2.CV_32S) - if np.count_nonzero(ff[:, 0]) > 0: - alt = np.min(np.nonzero(ff[:, 0])) - - points = [] - for i in range(3): - if i == 0: - index = alt - else: - index = rows // (2 * i) - points.append((self.get_point(index, image_mask), index)) - - points.append((self.get_point(rows, image_mask), rows)) - - position_x_down = np.where(image_mask[points[3][1], :]) - - # We see that white pixels have been located and we look if the center is located - # In this way we can know if the car has left the circuit - x_middle_left_down, not_found_down = self.check_center(position_x_down) - - return abs(326 - x_middle_left_down) if not_found_down is False else 500 - def execute(self): """Main loop of the brain. This will be called iteratively each TIME_CYCLE (see pilot.py)""" @@ -142,8 +109,6 @@ def execute(self): else: img = image - camera_deviation_error = self.get_devcamera_deviation_error(image) - self.camera_deviation_error.append(camera_deviation_error) if self.config['ImageNormalized']: AUGMENTATIONS_TEST = Compose([ diff --git a/behavior_metrics/ui/gui/views/stats_window.py b/behavior_metrics/ui/gui/views/stats_window.py index 0340604c..af90c6d2 100644 --- a/behavior_metrics/ui/gui/views/stats_window.py +++ b/behavior_metrics/ui/gui/views/stats_window.py @@ -15,8 +15,6 @@ def __init__(self, parent=None, controller=None): self.layout.addWidget(self.percentage_completed_label) self.completed_distance_label = QLabel("Completed distance -> " + str(self.controller.lap_statistics['completed_distance']) + "m") self.layout.addWidget(self.completed_distance_label) - self.camera_deviation_error_label = QLabel("Mean camera deviation -> " + str(sum(self.controller.metrics['camera_deviation_error'])/len(self.controller.metrics['camera_deviation_error']))) - self.layout.addWidget(self.camera_deviation_error_label) # If lap is completed, extend information if 'lap_seconds' in self.controller.lap_statistics: diff --git a/behavior_metrics/utils/controller.py b/behavior_metrics/utils/controller.py index 49635577..196bab51 100644 --- a/behavior_metrics/utils/controller.py +++ b/behavior_metrics/utils/controller.py @@ -206,7 +206,6 @@ def record_stats(self, perfect_lap_filename, stats_record_dir_path, world_counte self.stats_record_dir_path = stats_record_dir_path timestr = time.strftime("%Y%m%d-%H%M%S") self.stats_filename = timestr + '.bag' - self.pilot.brains.active_brain.camera_deviation_error = [] topics = ['/F1ROS/odom', '/clock'] command = "rosbag record -O " + self.stats_filename + " " + " ".join(topics) + " __name:=behav_stats_bag" command = shlex.split(command) @@ -225,9 +224,6 @@ def stop_record_stats(self): # Wait for rosbag file to be closed. Otherwise it causes error while os.path.isfile(self.stats_filename + '.active'): pass - - self.metrics['camera_deviation_error'] = self.pilot.brains.active_brain.camera_deviation_error - self.pilot.brains.active_brain.camera_deviation_error = [] checkpoints = [] metrics_str = json.dumps(self.metrics)