@@ -164,6 +164,8 @@ def parse_args():
164
164
help = "Number of pictures taken." )
165
165
parser .add_argument ('-ebp' , '--enablePolygonsDisplay' , default = False , action = "store_true" ,
166
166
help = "Enable the display of polynoms." )
167
+ parser .add_argument ('-dbg' , '--debugProcessingMode' , default = False , action = "store_true" ,
168
+ help = "Enable processing of images without using the camera." )
167
169
options = parser .parse_args ()
168
170
# Set some extra defaults, `-brd` would override them
169
171
if options .defaultBoard is not None :
@@ -185,7 +187,10 @@ def parse_args():
185
187
raise argparse .ArgumentTypeError ("-s / --squareSizeCm needs to be greater than 2.2 cm" )
186
188
if options .traceLevel == 1 :
187
189
print (f"Charuco board selected is: board_name = { board_name } , numX = { numX } , numY = { numY } , squareSize { options .squareSizeCm } cm, markerSize { options .markerSizeCm } cm" )
188
-
190
+ if options .debugProcessingMode :
191
+ options .mode = "process"
192
+ if options .board is None :
193
+ raise argparse .ArgumentError (options .board , "Board name (-brd) of camera must be specified in case of using debug mode (-dbg)." )
189
194
return options
190
195
191
196
class HostSync :
@@ -350,31 +355,33 @@ def __init__(self):
350
355
self .output_scale_factor = self .args .outputScaleFactor
351
356
self .aruco_dictionary = cv2 .aruco .Dictionary_get (
352
357
cv2 .aruco .DICT_4X4_1000 )
353
- self .device = dai .Device ()
354
358
self .enablePolygonsDisplay = self .args .enablePolygonsDisplay
355
359
self .board_name = None
356
- calibData = self .device .readCalibration ()
357
- eeprom = calibData .getEepromData ()
360
+ if not self .args .debugProcessingMode :
361
+ self .device = dai .Device ()
362
+ cameraProperties = self .device .getConnectedCameraFeatures ()
363
+ calibData = self .device .readCalibration ()
364
+ eeprom = calibData .getEepromData ()
358
365
#TODO Change only in getDeviceName in next revision.
359
366
if self .args .board :
360
367
self .board_name = self .args .board
361
- board_path = Path (self .args .board )
368
+ board_path = Path (Path ( __file__ ). parent / self .args .board )
362
369
if not board_path .exists ():
363
370
board_path = (Path (__file__ ).parent / 'resources/depthai_boards/boards' / self .args .board .upper ()).with_suffix ('.json' ).resolve ()
364
371
if not board_path .exists ():
365
372
raise ValueError (
366
- 'Board config not found: {}' .format (board_path ))
373
+ 'Board config not found: {}' .format (Path ( Path ( __file__ ). parent / self . args . board ) ))
367
374
with open (board_path ) as fp :
368
375
self .board_config = json .load (fp )
369
376
self .board_config = self .board_config ['board_config' ]
370
377
self .board_config_backup = self .board_config
371
- else :
378
+ elif not self . args . debugProcessingMode :
372
379
try :
373
380
detection = self .device .getDeviceName ()
374
381
print (f"Device name: { detection } " )
375
382
detection = detection .split ("-" )
376
383
except :
377
- self . cameraProperties = self .device .getConnectedCameraFeatures ()
384
+ cameraProperties = self .device .getConnectedCameraFeatures ()
378
385
calibData = self .device .readCalibration ()
379
386
eeprom = calibData .getEepromData ()
380
387
eeprom .productName = eeprom .productName .replace (" " , "-" ).upper ()
@@ -393,7 +400,7 @@ def __init__(self):
393
400
if "9782" in detection :
394
401
detection .remove ("9782" )
395
402
self .board_name = '-' .join (detection )
396
- board_path = Path (self .board_name )
403
+ board_path = Path (Path ( __file__ ). parent / self .board_name )
397
404
if self .traceLevel == 1 :
398
405
print (f"Board path specified as { board_path } " )
399
406
if not board_path .exists ():
@@ -430,23 +437,18 @@ def __init__(self):
430
437
for cam_id in self .board_config ['cameras' ]:
431
438
name = self .board_config ['cameras' ][cam_id ]['name' ]
432
439
self .coverageImages [name ] = None
433
-
434
- if (self ._set_camera_features ()):
435
- print ("Camera features set using board config." )
436
- print (f"self.cameraProperties: { self .cameraProperties } " )
437
- else :
438
- self .cameraProperties = self .device .getConnectedCameraFeatures ()
439
-
440
- for properties in self .cameraProperties :
441
- for in_cam in self .board_config ['cameras' ].keys ():
442
- cam_info = self .board_config ['cameras' ][in_cam ]
443
- if cam_info ["name" ] not in self .args .disableCamera :
444
- if properties .socket == stringToCam [in_cam ]:
445
- self .board_config ['cameras' ][in_cam ]['sensorName' ] = properties .sensorName
446
- print ('Cam: {} and focus: {}' .format (cam_info ['name' ], properties .hasAutofocus ))
447
- self .board_config ['cameras' ][in_cam ]['hasAutofocus' ] = properties .hasAutofocus
448
- # self.auto_checkbox_dict[cam_info['name'] + '-Camera-connected'].check()
449
- break
440
+ if not self .args .debugProcessingMode :
441
+ cameraProperties = self .device .getConnectedCameraFeatures ()
442
+ for properties in cameraProperties :
443
+ for in_cam in self .board_config ['cameras' ].keys ():
444
+ cam_info = self .board_config ['cameras' ][in_cam ]
445
+ if cam_info ["name" ] not in self .args .disableCamera :
446
+ if properties .socket == stringToCam [in_cam ]:
447
+ self .board_config ['cameras' ][in_cam ]['sensorName' ] = properties .sensorName
448
+ print ('Cam: {} and focus: {}' .format (cam_info ['name' ], properties .hasAutofocus ))
449
+ self .board_config ['cameras' ][in_cam ]['hasAutofocus' ] = properties .hasAutofocus
450
+ # self.auto_checkbox_dict[cam_info['name'] + '-Camera-connected'].check()
451
+ break
450
452
451
453
self .charuco_board = cv2 .aruco .CharucoBoard_create (
452
454
self .args .squaresX , self .args .squaresY ,
@@ -459,39 +461,6 @@ def mouse_event_callback(self, event, x, y, flags, param):
459
461
if event == cv2 .EVENT_LBUTTONDOWN :
460
462
self .mouseTrigger = True
461
463
462
- def _set_camera_features (self ):
463
- """
464
- Create mock camera properties using manually specified board config
465
- """
466
-
467
- self .cameraProperties = self .device .getConnectedCameraFeatures ()
468
-
469
- for cam_id in self .board_config ['cameras' ]:
470
- try :
471
- sensor_model = self .board_config ['cameras' ][cam_id ]["model" ]
472
- config_type = self .board_config ['cameras' ][cam_id ]["type" ]
473
- except KeyError :
474
- print (f"Model not found for { cam_id } , skipping..." )
475
- return False
476
-
477
- if sensor_model in camToRgbRes :
478
- supportedTypes = [dai .CameraSensorType .COLOR ]
479
- elif sensor_model in camToMonoRes :
480
- supportedTypes = [dai .CameraSensorType .MONO ]
481
- else :
482
- print (f"Model { sensor_model } not supported" )
483
- return False
484
-
485
- if supportedTypes [0 ].name != config_type .upper ():
486
- raise ValueError (f"Mismatch in camera type for { cam_id } with model { sensor_model } and type { config_type } , please fix the board config." )
487
-
488
- for cam in self .cameraProperties :
489
- if stringToCam [cam_id ] == cam .socket :
490
- cam .sensorName = sensor_model
491
- cam .supportedTypes = supportedTypes
492
-
493
- return True
494
-
495
464
def startPipeline (self ):
496
465
pipeline = self .create_pipeline ()
497
466
self .device .startPipeline (pipeline )
@@ -1006,7 +975,7 @@ def calibrate(self):
1006
975
self .args .cameraMode ,
1007
976
self .args .rectifiedDisp ) # Turn off enable disp rectify
1008
977
1009
- if self .args .noInitCalibration :
978
+ if self .args .noInitCalibration or self . args . debugProcessingMode :
1010
979
calibration_handler = dai .CalibrationHandler ()
1011
980
else :
1012
981
calibration_handler = self .device .readCalibration ()
@@ -1019,7 +988,8 @@ def calibrate(self):
1019
988
calibration_handler .setBoardInfo (str (self .device .getDeviceName ()), str (self .args .revision ))
1020
989
except Exception as e :
1021
990
print ('Device closed in exception..' )
1022
- self .device .close ()
991
+ if not self .args .debugProcessingMode :
992
+ self .device .close ()
1023
993
print (e )
1024
994
print (traceback .format_exc ())
1025
995
raise SystemExit (1 )
@@ -1104,7 +1074,7 @@ def calibrate(self):
1104
1074
calibration_handler .setStereoLeft (stringToCam [cam_info ['extrinsics' ]['to_cam' ]], result_config ['stereo_config' ]['rectification_left' ])
1105
1075
target_file .close ()
1106
1076
1107
- if len (error_text ) == 0 :
1077
+ if len (error_text ) == 0 and not self . args . debugProcessingMode :
1108
1078
print ('Flashing Calibration data into ' )
1109
1079
# print(calib_dest_path)
1110
1080
@@ -1138,15 +1108,17 @@ def calibrate(self):
1138
1108
is_write_factory_sucessful = False
1139
1109
1140
1110
if is_write_succesful :
1141
- self .device .close ()
1111
+ if not self .args .debugProcessingMode :
1112
+ self .device .close ()
1142
1113
text = "EEPROM written succesfully"
1143
1114
resImage = create_blank (900 , 512 , rgb_color = green )
1144
1115
cv2 .putText (resImage , text , (10 , 250 ), font , 2 , (0 , 0 , 0 ), 2 )
1145
1116
cv2 .imshow ("Result Image" , resImage )
1146
1117
cv2 .waitKey (0 )
1147
1118
1148
1119
else :
1149
- self .device .close ()
1120
+ if not self .args .debugProcessingMode :
1121
+ self .device .close ()
1150
1122
text = "EEPROM write Failed!!"
1151
1123
resImage = create_blank (900 , 512 , rgb_color = red )
1152
1124
cv2 .putText (resImage , text , (10 , 250 ), font , 2 , (0 , 0 , 0 ), 2 )
@@ -1155,7 +1127,8 @@ def calibrate(self):
1155
1127
# return (False, "EEPROM write Failed!!")
1156
1128
1157
1129
else :
1158
- self .device .close ()
1130
+ if not self .args .debugProcessingMode :
1131
+ self .device .close ()
1159
1132
print (error_text )
1160
1133
for text in error_text :
1161
1134
# text = error_text[0]
@@ -1164,7 +1137,8 @@ def calibrate(self):
1164
1137
cv2 .imshow ("Result Image" , resImage )
1165
1138
cv2 .waitKey (0 )
1166
1139
except Exception as e :
1167
- self .device .close ()
1140
+ if not self .args .debugProcessingMode :
1141
+ self .device .close ()
1168
1142
print ('Device closed in exception..' )
1169
1143
print (e )
1170
1144
print (traceback .format_exc ())
0 commit comments