Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion python-api/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path
import shutil
import consts.resource_paths
import json

use_cv = True
try:
Expand Down Expand Up @@ -45,6 +46,9 @@ def parse_args():

Capture 3 images per polygon:
python calibrate.py -c 3

Pass thru pipeline config options:
python calibrate.py -co '{"board_config": {"swap_left_and_right_cameras": true, "left_to_right_distance_cm": 9.0}}'
'''
parser = ArgumentParser(epilog=epilog_text,formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("-p", "--polygons", default=list(np.arange(len(setPolygonCoordinates(1000,600)))), nargs='*',
Expand All @@ -62,11 +66,19 @@ def parse_args():
parser.add_argument("-m", "--mode", default=['capture','process'], nargs='*',
type=str, required=False,
help="Space-separated list of calibration options to run. By default, executes the full 'capture process' pipeline. To execute a single step, enter just that step (ex: 'process').")
parser.add_argument("-co", "--config_overwrite", default=None,
type=str, required=False,
help="JSON-formatted pipeline config object. This will be override defaults used in this script.")

options = parser.parse_args()

return options

args = vars(parse_args())

if args['config_overwrite']:
args['config_overwrite'] = json.loads(args['config_overwrite'])

print("Using Arguments=",args)

if 'capture' in args['mode']:
Expand Down Expand Up @@ -94,7 +106,7 @@ def parse_args():
print("[ERROR] Unable to initialize device. Try to reset it. Exiting.")
exit(1)

config = configs = {
config = {
'streams': ['left', 'right'],
'depth':
{
Expand All @@ -115,6 +127,10 @@ def parse_args():
}
}

if args['config_overwrite'] is not None:
config = merge(args['config_overwrite'],config)
print("Merged Pipeline config with overwrite",config)

pipeline = depthai.create_pipeline(config)

if pipeline is None:
Expand Down
19 changes: 19 additions & 0 deletions python-api/calibration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@
import re
import time

# https://stackoverflow.com/questions/20656135/python-deep-merge-dictionary-data#20666342
def merge(source, destination):
"""
run me with nosetests --with-doctest file.py

>>> a = { 'first' : { 'all_rows' : { 'pass' : 'dog', 'number' : '1' } } }
>>> b = { 'first' : { 'all_rows' : { 'fail' : 'cat', 'number' : '5' } } }
>>> merge(b, a) == { 'first' : { 'all_rows' : { 'pass' : 'dog', 'fail' : 'cat', 'number' : '5' } } }
True
"""
for key, value in source.items():
if isinstance(value, dict):
# get node or create one
node = destination.setdefault(key, {})
merge(value, node)
else:
destination[key] = value

return destination
def mkdir_overwrite(dir):
if not os.path.exists(dir):
os.makedirs(dir)
Expand Down