@@ -247,6 +247,7 @@ def scale_to_range(arr, target_min, target_max):
247247need_exit = 0
248248hide_hud = False
249249enable_x3 = True
250+ switch_x3 = False
250251ts = touchscreen .TouchScreen ()
251252
252253disp = display .Display ()
@@ -258,14 +259,17 @@ def scale_to_range(arr, target_min, target_max):
258259img = cam .read ()
259260disp .show (img )
260261
261- x3model_name = './x3c_192x256.mud'
262+ # x3model_name = './x3c_192x256.mud'
262263# x3model_name = './espcn_x3.mud'
264+ x3model_name = './sr3_ir_32.mud'
263265
264266x3model = nn .NN (x3model_name )
265267if x3model_name == './espcn_x3.mud' :
266268 output_layer_name = '19'
267269elif x3model_name == './x3c_192x256.mud' :
268270 output_layer_name = 'image_output'
271+ elif x3model_name == './sr3_ir_32.mud' :
272+ output_layer_name = 'output'
269273else :
270274 raise RuntimeError ("Unsupported x3 model" )
271275
@@ -299,10 +303,27 @@ def scale_to_range(arr, target_min, target_max):
299303 x3grayimg_np = tensor .tensor_to_numpy_float32 (x3graytensor , copy = False ).reshape ((576 , 768 ))
300304 elif x3model_name == './x3c_192x256.mud' :
301305 x3grayimg_np = tensor .tensor_to_numpy_uint8 (x3graytensor , copy = False ).reshape ((576 , 768 ))
306+ elif x3model_name [2 :5 ] == './sr3_ir.mud' [2 :5 ]:
307+ x3grayimg_np = tensor .tensor_to_numpy_uint8 (x3graytensor , copy = False ).reshape ((576 , 768 ))
302308 else :
303309 raise RuntimeError ("Unsupported x3 model" )
304310 x3grayimg_np = x3grayimg_np .astype (np .uint8 )
305311
312+ if switch_x3 :
313+ switch_x3 = False
314+ if x3model_name == './espcn_x3.mud' :
315+ x3model_name = './x3c_192x256.mud'
316+ output_layer_name = 'image_output'
317+ elif x3model_name == './x3c_192x256.mud' :
318+ x3model_name = './sr3_ir_32.mud'
319+ output_layer_name = 'output'
320+ elif x3model_name == './sr3_ir_32.mud' :
321+ x3model_name = './espcn_x3.mud'
322+ output_layer_name = '19'
323+ else :
324+ raise RuntimeError ("Unsupported x3 model" )
325+ x3model = nn .NN (x3model_name )
326+
306327
307328 img_8bit = cv2 .resize (x3grayimg_np , (disp .width (), disp .height ()))
308329
@@ -391,10 +412,20 @@ def scale_to_range(arr, target_min, target_max):
391412 targetfile = os .path .join (filepath , filename )
392413 np .save (targetfile , gray )
393414 os .fsync (os .open (targetfile , os .O_RDWR ))
415+
416+ filename = f"gray_{ datetime .now ().strftime ("%Y%m%d_%H%M%S" )} _{ FRAME_NUM } .npy"
417+ targetfile = os .path .join (filepath , filename )
418+ np .save (targetfile , gray )
419+ os .fsync (os .open (targetfile , os .O_RDWR ))
420+ filename = f"x3gray_{ datetime .now ().strftime ("%Y%m%d_%H%M%S" )} _{ FRAME_NUM } .npy"
421+ targetfile = os .path .join (filepath , filename )
422+ np .save (targetfile , x3grayimg_np )
423+ os .fsync (os .open (targetfile , os .O_RDWR ))
394424 elif x >= 0 and x <= 120 and y >= img .height ()- 40 and y <= img .height (): # Lo-Res
395425 enable_x3 = False
396426 elif x >= img .width ()- 120 and x <= img .width () and y >= img .height ()- 40 and y <= img .height (): # Hi-Res
397427 enable_x3 = True
428+ switch_x3 = True
398429 elif x >= img .width ()// 2 - 60 and x <= img .width ()// 2 + 60 and y >= 0 and y <= 40 : # Hide HUD
399430 hide_hud = True
400431 elif x >= img .width ()// 2 - 60 and x <= img .width ()// 2 + 60 and y >= img .height ()- 40 and y <= img .height (): # Show HUD
@@ -408,6 +439,7 @@ def scale_to_range(arr, target_min, target_max):
408439 if not hide_hud :
409440 img .draw_string ( 10 , 10 , "Quit(Holding)" , image .Color .from_rgb (255 , 0 if need_exit == 0 else 255 , 0 ), scale = 2 , thickness = 2 )
410441 img .draw_string ( img .width ()- 140 , 10 , "Capture" , image .Color .from_rgb (255 , 0 , 0 ), scale = 2 , thickness = 2 )
442+ img .draw_string ( img .width ()- 140 , 60 ,x3model_name [2 :], image .Color .from_rgb (255 , 0 , 0 ), scale = 2 , thickness = 2 )
411443 img .draw_string ( 10 , img .height ()- 20 , "Lo-Res" , image .Color .from_rgb (255 , 0 , 0 ), scale = 2 , thickness = 2 )
412444 img .draw_string ( img .width ()- 120 , img .height ()- 20 , "Hi-Res" , image .Color .from_rgb (255 , 0 , 0 ), scale = 2 , thickness = 2 )
413445 img .draw_string (img .width ()// 2 - 60 , 10 , "Hide HUD" , image .Color .from_rgb (255 , 0 , 0 ), scale = 2 , thickness = 2 )
0 commit comments