Skip to content

Commit 2841c92

Browse files
committed
Merge branch 'main' of github.com:luxonis/depthai into main
2 parents 5067163 + ed0695b commit 2841c92

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

calibrate.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ def parse_args():
3939
4040
Image capture requires the use of a printed OpenCV charuco calibration target applied to a flat surface(ex: sturdy cardboard).
4141
Default board size used in this script is 22x16. However you can send a customized one too.
42-
When taking photos, ensure enough amount of markers are visible and images are crisp.
42+
When taking photos, ensure enough amount of markers are visible and images are crisp.
4343
The board does not need to fit within each drawn red polygon shape, but it should mimic the display of the polygon.
4444
4545
If the calibration checkerboard corners cannot be found, the user will be prompted to try that calibration pose again.
4646
4747
The script requires a RMS error < 1.0 to generate a calibration file. If RMS exceeds this threshold, an error is displayed.
48-
An average epipolar error of <1.5 is considered to be good, but not required.
48+
An average epipolar error of <1.5 is considered to be good, but not required.
4949
5050
Example usage:
5151
@@ -54,7 +54,7 @@ def parse_args():
5454
5555
Only run image processing only with same board setup. Requires a set of saved capture images:
5656
python3 calibrate.py -s 3.0 -ms 2.5 -brd DM2CAM -m process
57-
57+
5858
Delete all existing images before starting image capture:
5959
python3 calibrate.py -i delete
6060
'''
@@ -100,7 +100,7 @@ def parse_args():
100100
parser.add_argument("-d", "--debug", default=False, action="store_true", help="Enable debug logs.")
101101
parser.add_argument("-fac", "--factoryCalibration", default=False, action="store_true",
102102
help="Enable writing to Factory Calibration.")
103-
103+
104104
options = parser.parse_args()
105105

106106
# Set some extra defaults, `-brd` would override them
@@ -111,7 +111,7 @@ def parse_args():
111111
raise argparse.ArgumentError(options.markerSizeCm, "-ms / --markerSizeCm needs to be provided (you can use -db / --defaultBoard if using calibration board from this repository or calib.io to calculate -ms automatically)")
112112
if options.squareSizeCm < 2.2:
113113
raise argparse.ArgumentTypeError("-s / --squareSizeCm needs to be greater than 2.2 cm")
114-
114+
115115
return options
116116

117117

@@ -156,7 +156,7 @@ def __init__(self):
156156
for properties in cameraProperties:
157157
if properties.sensorName == 'OV7251':
158158
raise Exception(
159-
"OAK-D-Lite Calibration is not supported on main yet. Please use `lite_calibration` branch to calibrate your OAK-D-Lite!!")
159+
"OAK-D-Lite Calibration is not supported on main yet. Please use `lite_calibration` branch to calibrate your OAK-D-Lite!!")
160160
161161
self.device.startPipeline(pipeline)"""
162162
self.left_camera_queue = self.device.getOutputQueue("left", 30, True)
@@ -201,7 +201,7 @@ def create_pipeline(self):
201201
else:
202202
cam_left.setBoardSocket(dai.CameraBoardSocket.LEFT)
203203
cam_right.setBoardSocket(dai.CameraBoardSocket.RIGHT)
204-
204+
205205
cam_left.setResolution(
206206
dai.MonoCameraProperties.SensorResolution.THE_800_P)
207207
cam_left.setFps(self.args.fps)
@@ -228,7 +228,7 @@ def create_pipeline(self):
228228

229229
xout_rgb_isp = pipeline.createXLinkOut()
230230
xout_rgb_isp.setStreamName("rgb")
231-
rgb_cam.isp.link(xout_rgb_isp.input)
231+
rgb_cam.isp.link(xout_rgb_isp.input)
232232

233233
return pipeline
234234

@@ -338,6 +338,7 @@ def capture_images(self):
338338
prev_time = None
339339
curr_time = None
340340
self.display_name = "left + right + rgb"
341+
last_frame_time = time.time()
341342
# with self.get_pipeline() as pipeline:
342343
while not finished:
343344
current_left = self.left_camera_queue.tryGet()
@@ -356,9 +357,17 @@ def capture_images(self):
356357
recent_color = current_color
357358

358359
if recent_left is None or recent_right is None or (recent_color is None and not self.args.disableRgb):
359-
print("Continuing...")
360+
if time.time() - last_frame_time > 5:
361+
if self.args.disableRgb:
362+
print("Error: Couldn't retrieve left and right frames for more than 5 seconds. Exiting...")
363+
else:
364+
print("Error: Couldn't retrieve left, rigth and color frames for more than 5 seconds. Exiting...")
365+
raise SystemExit(1)
366+
cv2.waitKey(1)
360367
continue
361368

369+
last_frame_time = time.time()
370+
362371
recent_frames = [('left', recent_left), ('right', recent_right)]
363372
if not self.args.disableRgb:
364373
recent_frames.append(('rgb', recent_color))
@@ -485,7 +494,7 @@ def capture_images(self):
485494
finished = True
486495
cv2.destroyAllWindows()
487496
break
488-
497+
489498
if not self.args.disableRgb:
490499
frame_list[2] = np.pad(frame_list[2], ((40, 0), (0,0)), 'constant', constant_values=0)
491500
combine_img = np.hstack((frame_list[0], frame_list[1], frame_list[2]))
@@ -502,7 +511,7 @@ def capture_images(self):
502511
start_timer = False
503512
capturing = True
504513
print('Statrt capturing...')
505-
514+
506515
image_shape = combine_img.shape
507516
cv2.putText(combine_img, str(timer),
508517
(image_shape[1]//2, image_shape[0]//2), font,
@@ -583,14 +592,14 @@ def calibrate(self):
583592
self.board_config['board_config']['left_to_right_distance_cm'] - self.board_config['board_config']['left_to_rgb_distance_cm'], 0.0, 0.0]
584593
calibration_handler.setCameraExtrinsics(
585594
right, dai.CameraBoardSocket.RGB, calibData[7], calibData[8], measuredTranslation)
586-
595+
587596
resImage = None
588597
if not self.device.isClosed():
589598
mx_serial_id = self.device.getDeviceInfo().getMxId()
590599
calib_dest_path = dest_path + '/' + mx_serial_id + '.json'
591600
calibration_handler.eepromToJsonFile(calib_dest_path)
592601
is_write_succesful = False
593-
602+
594603
try:
595604
if self.args.factoryCalibration:
596605
self.device.flashFactoryCalibration(calibration_handler)

0 commit comments

Comments
 (0)