@@ -57,7 +57,7 @@ def __init__(self, sensors, actuators, model=None, handler=None, config=None):
5757 self .third_image = []
5858
5959 if self .config ['GPU' ] is False :
60- os .environ ["CUDA_VISIBLE_DEVICES" ]= "-1"
60+ os .environ ["CUDA_VISIBLE_DEVICES" ] = "-1"
6161
6262 self .gpu_inference = True if tf .test .gpu_device_name () else False
6363
@@ -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 ):
@@ -115,17 +125,18 @@ def execute(self):
115125 '''
116126
117127 image = self .camera .getImage ().data
128+ base_image = image
118129 if self .cont == 1 :
119130 self .first_image = image
120- image = self .handler .transform_image (image ,self .config ['ImageTranform' ])
131+ image = self .handler .transform_image (image , self .config ['ImageTranform' ])
121132 try :
122133 if self .config ['ImageCropped' ]:
123134 image = image [240 :480 , 0 :640 ]
124135 if 'ImageSize' in self .config :
125136 img = cv2 .resize (image , (self .config ['ImageSize' ][0 ], self .config ['ImageSize' ][1 ]))
126137 else :
127138 img = image
128- self .update_frame ('frame_0' , img )
139+ # sself .update_frame('frame_0', img)
129140 if self .config ['ImageNormalized' ]:
130141 AUGMENTATIONS_TEST = Compose ([
131142 Normalize ()
@@ -170,21 +181,22 @@ def execute(self):
170181 start_time = time .time ()
171182 prediction = self .net .predict (img )
172183 self .inference_times .append (time .time () - start_time )
173- #prediction = prediction[0]
174184 if self .config ['PredictionsNormalized' ]:
175- prediction_v = prediction [0 ][0 ]* (24 - (6.5 )) + (6.5 )
176- prediction_w = prediction [0 ][1 ]* (7.1 - (- 7.1 )) + (- 7.1 )
185+ prediction_v = prediction [0 ][0 ] * (24 - (6.5 )) + (6.5 )
186+ prediction_w = prediction [0 ][1 ] * (7.1 - (- 7.1 )) + (- 7.1 )
177187 else :
178188 prediction_v = prediction [0 ][0 ]
179189 prediction_w = prediction [0 ][1 ]
180190 if prediction_w != '' and prediction_w != '' :
181191 self .motors .sendV (prediction_v )
182192 self .motors .sendW (prediction_w )
183193
194+ self .update_frame ('frame_0' , base_image , prediction_w )
195+
184196 if self .previous_v != None :
185197 a = np .array ((prediction [0 ][0 ], prediction [0 ][1 ]))
186198 b = np .array ((self .previous_v , self .previous_w ))
187- distance = np .linalg .norm (a - b )
199+ distance = np .linalg .norm (a - b )
188200 self .suddenness_distance .append (distance )
189201 self .previous_v = prediction [0 ][0 ]
190202 self .previous_w = prediction [0 ][1 ]
0 commit comments