Commit 52de983e authored by Stephen Thompson's avatar Stephen Thompson

Merge branch '26-bardCameraCalibration-input-via-json' into 'master'

Resolve "bardCameraCalibration also needs to get input via a json file"

Closes #26

See merge request WEISS/SoftwareRepositories/SNAPPY/scikit-surgerybard!7
parents 9efccf7c 55e23e6b
{
"input_dir" : "tests/data/Calibration/",
"output_dir" : "tests/data/",
"width" : "14",
"height" : "10",
"grid_size_mm" : "3",
"verbose": "False"
}
{
"input_dir" : "tests/data/Calibration_test_case/",
"output_dir" : "tests/data/",
"width" : "14",
"height" : "10",
"grid_size_mm" : "3",
"verbose": "False"
}
\ No newline at end of file
......@@ -35,10 +35,9 @@ the application.
BARD provides a camera calibration program. Try it out.
::
python bardCameraCalibration.py -help
python bardCameraCalibration.py --xcorners 14 --ycorners 10 --size 24 -i <output_dir> --verbose
python bardCameraCalibration.py --config config/calibration_input.json
(filling in appropriate parameters: so -x gives the number of chessboard squares in the x direction, -y the number of chessboard squares in the y direction and -s gives the size of each chessboard square in millimetres)
(Default values in `config/calibration_input.json` should be find for most cases but if needed the default values can be changed in config/calibration_input.json file: so -x gives the number of chessboard squares in the x direction, -y the number of chessboard squares in the y direction and -s gives the size of each chessboard square in millimetres)
This will find all file named .png in <output_dir>, attempt to detect chessboard corners from them,
and if successful use the corners to calibrate the camera.
......
......@@ -3,16 +3,29 @@
"""Basic Augmented Reality Demo BARD Application"""
import glob
import json
import numpy as np
import sksurgerybard.algorithms.bard_calibration_algorithms as bca
def run_demo(input_dir, output_dir, width, height, grid_size_mm, verbose):
def run_demo(config_file):
""" Demo app, to perform camera calibration """
# Calibration code added from the following link
# https://opencv-python-tutroals.readthedocs.io/en/
# latest/py_tutorials/py_calib3d/py_calibration/py_calibration.html
json_file = open(config_file)
json_data = json.load(json_file)
json_file.close()
input_dir = json_data["input_dir"]
output_dir = json_data["output_dir"]
width = int(json_data["width"])
height = int(json_data["height"])
grid_size_mm = float(json_data["grid_size_mm"])
verbose = json_data["verbose"]
# *.png is appended to the supplied path to read all the png files in it.
input_dir = input_dir + '*.png'
......
......@@ -13,54 +13,15 @@ def main(args=None):
"""Entry point for scikit-surgerybard application"""
parser = argparse.ArgumentParser(
description='Basic Augmented Reality Demo - '
'Camera Calibration, 0.1')
description='Bard Camera Calibration entry point')
# ADD POSITIONAL ARGUMENTS
parser.add_argument("-i", "--input",
required=True,
help="Directory containing png images of "
"chessboard."
)
parser.add_argument("-o",
"--output",
required=False,
default='./',
help="Output text file for intrinsic and "
"distortion params"
)
parser.add_argument("-x", "--xcorners",
required=False,
default=14,
help="Number of internal corners "
"along the width (x)",
type=int
)
parser.add_argument("-y", "--ycorners",
parser.add_argument("-c", "--config",
required=False,
default=10,
help="Number of internal corners "
"along the height (y)",
type=int
)
parser.add_argument("-s", "--size",
required=False,
default=3,
help="Square size in millimetres",
type=float
)
# ADD OPTINAL ARGUMENTS
parser.add_argument("-v", "--verbose",
action="store_true",
help="Enable verbose output",
)
default='config/calibration_input.json',
type=str,
help="Configuration file containing the parameters")
version_string = __version__
friendly_version_string = version_string if version_string else 'unknown'
......@@ -71,12 +32,4 @@ def main(args=None):
args = parser.parse_args(args)
# Gets the directory containing images.
input_dir = args.input
output_dir = args.output
width = args.xcorners
height = args.ycorners
size = args.size
verbose = args.verbose
run_demo(input_dir, output_dir, width, height, size, verbose)
run_demo(args.config)
......@@ -45,7 +45,6 @@ def run_demo(config_file):
viewer.vtk_overlay_window.add_vtk_actor(pointer_tip_sphere.actor)
viewer.pointer_models = viewer.pointer_models + 1
viewer.start()
sys.exit(app.exec_())
......@@ -8,9 +8,9 @@ from sksurgerybard.ui.sksurgerybard_command_app import run_demo
def main(args=None):
"""Entry point for sksurgeryvideolag application"""
"""Entry point for sksurgerybard application"""
parser = argparse.ArgumentParser(description='sksurgeryvideolag')
parser = argparse.ArgumentParser(description='sksurgerybard')
parser.add_argument("-c", "--config",
required=False,
......
......@@ -43,11 +43,7 @@ def test_return_value():
def test_fewer_images():
input_dir = 'tests/data/Calibration_test_case/'
output_dir = 'tests/data/'
width = 14
height = 10
size = 3
verbose = False
config_data = 'config/calibration_input_test.json'
with pytest.raises(RuntimeError):
p.run_demo(input_dir, output_dir, width, height, size, verbose)
p.run_demo(config_data)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment