Skip to content

Commit

Permalink
Merge pull request #245 from JdeRobot/issue-244
Browse files Browse the repository at this point in the history
Removed camera deviation calculation
  • Loading branch information
sergiopaniego authored Oct 18, 2021
2 parents 6d0fae0 + 75e0620 commit 3df5362
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 44 deletions.
3 changes: 0 additions & 3 deletions behavior_metrics/brains/f1/brain_f1_explicit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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][
Expand Down
35 changes: 0 additions & 35 deletions behavior_metrics/brains/f1/brain_f1_keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)"""

Expand All @@ -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([
Expand Down
2 changes: 0 additions & 2 deletions behavior_metrics/ui/gui/views/stats_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 0 additions & 4 deletions behavior_metrics/utils/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 3df5362

Please sign in to comment.