Skip to content

Commit 0b6d0ba

Browse files
committed
Generalized function
1 parent aa65c99 commit 0b6d0ba

File tree

3 files changed

+44
-37
lines changed

3 files changed

+44
-37
lines changed

behavior_metrics/brains/f1/brain_f1_keras_opencv_dataset.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,23 @@ def __init__(self, sensors, actuators, model=None, handler=None, config=None):
6767
print("- Models path: " + PRETRAINED_MODELS)
6868
print("- Model: " + str(model))
6969

70-
def update_frame(self, frame_id, data):
70+
def update_frame(self, frame_id, data, angular_speed=None):
7171
"""Update the information to be shown in one of the GUI's frames.
7272
7373
Arguments:
7474
frame_id {str} -- Id of the frame that will represent the data
7575
data {*} -- Data to be shown in the frame. Depending on the type of frame (rgbimage, laser, pose3d, etc)
7676
"""
77+
if angular_speed:
78+
import math
79+
x1, y1 = int(data.shape[:2][1] / 2), data.shape[:2][0] # ancho, alto
80+
length = 200
81+
angle = (90 + int(math.degrees(-angular_speed))) * 3.14 / 180.0
82+
x2 = int(x1 - length * math.cos(angle))
83+
y2 = int(y1 - length * math.sin(angle))
84+
85+
line_thickness = 2
86+
cv2.line(data, (x1, y1), (x2, y2), (0, 0, 0), thickness=line_thickness)
7787
self.handler.update_frame(frame_id, data)
7888

7989
def execute(self):
@@ -130,17 +140,7 @@ def execute(self):
130140
self.previous_v = prediction[0][0]
131141
self.previous_w = prediction[0][1]
132142

133-
# show image in gui -> frame_0
134-
import math
135-
x1, y1 = int(base_image.shape[:2][1]/2), base_image.shape[:2][0] # ancho, alto
136-
length = 200
137-
angle = (90 + int(math.degrees(-prediction_w))) * 3.14 / 180.0
138-
x2 = int(x1 - length * math.cos(angle))
139-
y2 = int(y1 - length * math.sin(angle))
140-
141-
line_thickness = 2
142-
cv2.line(base_image, (x1, y1), (x2, y2), (0, 0, 0), thickness=line_thickness)
143-
self.update_frame('frame_0', base_image)
143+
self.update_frame('frame_0', base_image, prediction_w)
144144

145145
# GradCAM from image
146146
i = np.argmax(prediction[0])

behavior_metrics/brains/f1/brain_f1_keras_seq_3_opencv_dataset.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,23 @@ def __init__(self, sensors, actuators, model=None, handler=None, config=None):
7272
print("- Models path: " + PRETRAINED_MODELS)
7373
print("- Model: " + str(model))
7474

75-
def update_frame(self, frame_id, data):
75+
def update_frame(self, frame_id, data, angular_speed=None):
7676
"""Update the information to be shown in one of the GUI's frames.
7777
7878
Arguments:
7979
frame_id {str} -- Id of the frame that will represent the data
8080
data {*} -- Data to be shown in the frame. Depending on the type of frame (rgbimage, laser, pose3d, etc)
8181
"""
82+
if angular_speed:
83+
import math
84+
x1, y1 = int(data.shape[:2][1] / 2), data.shape[:2][0] # ancho, alto
85+
length = 200
86+
angle = (90 + int(math.degrees(-angular_speed))) * 3.14 / 180.0
87+
x2 = int(x1 - length * math.cos(angle))
88+
y2 = int(y1 - length * math.sin(angle))
89+
90+
line_thickness = 2
91+
cv2.line(data, (x1, y1), (x2, y2), (0, 0, 0), thickness=line_thickness)
8292
self.handler.update_frame(frame_id, data)
8393

8494
def check_center(self, position_x):
@@ -181,17 +191,7 @@ def execute(self):
181191
self.motors.sendV(prediction_v)
182192
self.motors.sendW(prediction_w)
183193

184-
# show image in gui -> frame_0
185-
import math
186-
x1, y1 = int(base_image.shape[:2][1] / 2), base_image.shape[:2][0] # ancho, alto
187-
length = 200
188-
angle = (90 + int(math.degrees(-prediction_w))) * 3.14 / 180.0
189-
x2 = int(x1 - length * math.cos(angle))
190-
y2 = int(y1 - length * math.sin(angle))
191-
192-
line_thickness = 2
193-
cv2.line(base_image, (x1, y1), (x2, y2), (0, 0, 0), thickness=line_thickness)
194-
self.update_frame('frame_0', base_image)
194+
self.update_frame('frame_0', base_image, prediction_w)
195195

196196
if self.previous_v != None:
197197
a = np.array((prediction[0][0], prediction[0][1]))

behavior_metrics/brains/f1/brain_f1_opencv.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def __init__(self, sensors, actuators, handler, config=None):
5050
self.cont = 0
5151
self.iteration = 0
5252

53-
#self.previous_timestamp = 0
54-
#self.previous_image = 0
53+
# self.previous_timestamp = 0
54+
# self.previous_image = 0
5555

5656
self.previous_v = None
5757
self.previous_w = None
@@ -66,7 +66,23 @@ def __init__(self, sensors, actuators, handler, config=None):
6666
'''
6767
time.sleep(2)
6868

69-
def update_frame(self, frame_id, data):
69+
def update_frame(self, frame_id, data, angular_speed=None):
70+
"""Update the information to be shown in one of the GUI's frames.
71+
72+
Arguments:
73+
frame_id {str} -- Id of the frame that will represent the data
74+
data {*} -- Data to be shown in the frame. Depending on the type of frame (rgbimage, laser, pose3d, etc)
75+
"""
76+
if angular_speed:
77+
import math
78+
x1, y1 = int(data.shape[:2][1] / 2), data.shape[:2][0] # ancho, alto
79+
length = 200
80+
angle = (90 + int(math.degrees(-angular_speed))) * 3.14 / 180.0
81+
x2 = int(x1 - length * math.cos(angle))
82+
y2 = int(y1 - length * math.sin(angle))
83+
84+
line_thickness = 2
85+
cv2.line(data, (x1, y1), (x2, y2), (0, 0, 0), thickness=line_thickness)
7086
self.handler.update_frame(frame_id, data)
7187

7288
def collinear3(self, x1, y1, x2, y2, x3, y3):
@@ -199,16 +215,7 @@ def execute(self):
199215
self.motors.sendW(w)
200216
self.motors.sendV(v)
201217

202-
# show image in gui -> frame_0
203-
import math
204-
x1, y1 = int(image.shape[:2][1] / 2), image.shape[:2][0] # ancho, alto
205-
length = 200
206-
angle = (90 + int(math.degrees(-w))) * 3.14 / 180.0
207-
x2 = int(x1 - length * math.cos(angle))
208-
y2 = int(y1 - length * math.sin(angle))
209-
line_thickness = 2
210-
cv2.line(image, (x1, y1), (x2, y2), (0, 0, 0), thickness=line_thickness)
211-
self.update_frame('frame_0', image)
218+
self.update_frame('frame_0', image, w)
212219

213220
v = np.interp(np.array([v]), (6.5, 24), (0, 1))[0]
214221
w = np.interp(np.array([w]), (-7.1, 7.1), (0, 1))[0]

0 commit comments

Comments
 (0)