Skip to content

Commit d7e93b8

Browse files
committed
add: include sr3_ir_32 model files and update main logic for model switching
1 parent d240d0e commit d7e93b8

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

projects/app_thermal_tiny1c/app.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ files:
1414
- main_espcn.py
1515
- main_x3c.py
1616
- main.py
17+
- sr3_ir_32_int8.axmodel
18+
- sr3_ir_32.mud
1719
- x3c_192x256.axmodel
1820
- x3c_192x256.mud

projects/app_thermal_tiny1c/main_x3c.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ def scale_to_range(arr, target_min, target_max):
247247
need_exit = 0
248248
hide_hud = False
249249
enable_x3 = True
250+
switch_x3 = False
250251
ts = touchscreen.TouchScreen()
251252

252253
disp = display.Display()
@@ -258,14 +259,17 @@ def scale_to_range(arr, target_min, target_max):
258259
img = cam.read()
259260
disp.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

264266
x3model = nn.NN(x3model_name)
265267
if x3model_name == './espcn_x3.mud':
266268
output_layer_name = '19'
267269
elif x3model_name == './x3c_192x256.mud':
268270
output_layer_name = 'image_output'
271+
elif x3model_name == './sr3_ir_32.mud':
272+
output_layer_name = 'output'
269273
else:
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)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[basic]
2+
type = axmodel
3+
model_npu = sr3_ir_32_int8.axmodel
4+
model_vnpu = sr3_ir_32_int8.axmodel
5+
6+
[extra]
7+
mean = 0
8+
scale = 0
303 KB
Binary file not shown.

0 commit comments

Comments
 (0)