コード例 #1
0
def main(args=None):
    """Entry point for simple video calibration application. """

    parser = argparse.ArgumentParser(description='videocalibration')

    parser.add_argument("-c", "--config",
                        required=True,
                        type=str,
                        help="Configuration file containing the parameters "
                             "(see config/video_chessboard_conf.json "
                             "for example).")

    parser.add_argument("-s", "--save",
                        required=False,
                        type=str,
                        help="Directory to save to.")

    parser.add_argument("-p", "--prefix",
                        required=False,
                        type=str,
                        help="Filename prefix to save to.")

    version_string = __version__
    friendly_version_string = version_string if version_string else 'unknown'
    parser.add_argument(
        "-v", "--version",
        action='version',
        version='sksurgerycalibration version ' + friendly_version_string)

    args = parser.parse_args(args)

    configurer = ConfigurationManager(args.config)
    configuration = configurer.get_copy()

    run_video_calibration(configuration, args.save, args.prefix)
コード例 #2
0
def test_surface_model_loader_2_surface_no_assembly():
    config = ConfigurationManager('tests/data/config/surface_model_two.json')
    config_data = config.get_copy()
    loader = SurfaceModelLoader(config_data)
    assert loader is not None
    assert len(loader.get_assembly_names()) == 0
    assert len(loader.get_surface_model_names()) == 2
コード例 #3
0
def test_surface_model_loader_2_surface_no_prefix():
    config_with_no_prefix_in_json = ConfigurationManager('tests/data/config/surface_model_two_no_prefix.json')
    config_with_no_prefix_in_json_data = config_with_no_prefix_in_json.get_copy()
    loader_no_prefix = SurfaceModelLoader(config_with_no_prefix_in_json_data, directory_prefix="tests/data/models/Liver/")
    assert loader_no_prefix is not None
    assert len(loader_no_prefix.get_assembly_names()) == 0
    assert len(loader_no_prefix.get_surface_model_names()) == 2
コード例 #4
0
def test_surface_model_loader_2_in_assembly_on_its_own(setup_vtk_overlay_window):
    config = ConfigurationManager('tests/data/config/surface_model_two_assemblies.json')
    config_data = config.get_copy()
    loader = SurfaceModelLoader(config_data)
    assert loader is not None
    assert len(loader.get_assembly_names()) == 2
    assert len(loader.get_surface_model_names()) == 3
    widget, _, _, app = setup_vtk_overlay_window
    widget.add_vtk_models(loader.get_surface_models())
    widget.show()
コード例 #5
0
def test_two_surfaces_no_assembly():
    config = ConfigurationManager('tests/data/config/surface_model_two.json')
    data = config.get_copy()
    surfaces = data['surfaces']
    assert len(surfaces.keys()) == 2
    assert len(surfaces.values()) == 2
    for name in surfaces:
        assert isinstance(name, str)
        surface = surfaces[name]
        check_surface_properties(surface)
def main(args=None):
    """ Entry point for sksurgeryvideocalibrationchecker. """

    parser = argparse.ArgumentParser(
        description='sksurgeryvideocalibrationchecker')

    parser.add_argument("-c",
                        "--config",
                        required=True,
                        type=str,
                        help="Configuration file containing the parameters "
                        "(see config/video_chessboard_conf.json "
                        "for example).")

    parser.add_argument(
        "-s",
        "--source",
        required=False,
        type=str,
        default="0",
        help="OpenCV source. (USB camera number, or filename).")

    parser.add_argument("-d",
                        "--calib_dir",
                        required=True,
                        type=str,
                        help="Directory containing calibration data.")

    parser.add_argument("-p",
                        "--prefix",
                        required=False,
                        type=str,
                        help="Prefix for calibration data.")

    parser.add_argument("-ni",
                        "--noninteractive",
                        required=False,
                        action='store_true',
                        help="If specified, runs noninteractive mode.")

    version_string = __version__
    friendly_version_string = version_string if version_string else 'unknown'
    parser.add_argument(
        "--version",
        action='version',
        version='scikit-sksurgeryvideocalibrationchecker version ' +
        friendly_version_string)

    args = parser.parse_args(args)

    configurer = ConfigurationManager(args.config)
    configuration = configurer.get_copy()

    run_video_calibration_checker(configuration, args.source, args.calib_dir,
                                  args.prefix, args.noninteractive)
コード例 #7
0
def test_one_surface_no_assembly():
    config = ConfigurationManager('tests/data/config/surface_model_one.json')
    data = config.get_copy()
    assert isinstance(data, dict)

    surfaces = data['surfaces']
    assert isinstance(surfaces, dict)
    assert len(surfaces.keys()) == 1
    assert len(surfaces.values()) == 1

    name = next(iter(surfaces))
    assert name == 'liver'
    check_surface_properties(surfaces[name])
コード例 #8
0
def test_surface_model_loader_2_surface_with_assembly():
    config = ConfigurationManager('tests/data/config/surface_model_two_in_assembly.json')
    config_data = config.get_copy()
    loader = SurfaceModelLoader(config_data)
    assert loader is not None
    assert len(loader.get_assembly_names()) == 1
    assert len(loader.get_surface_model_names()) == 2

    # Call these functions for coverage purposes
    loader.get_assembly("veins")
    model = loader.get_surface_model("portal veins")

    # Check, the name should come from json file.
    assert model.get_name() == "portal veins"
コード例 #9
0
ファイル: snappysonic_demo.py プロジェクト: UCL/snappysonic
def run_demo(configfile):
    """ Run the application """

    configurer = ConfigurationManager(configfile)

    app = QApplication([])

    configuration = configurer.get_copy()

    viewer = OverlayApp(configuration)

    viewer.start()

    #start the application
    sys.exit(app.exec_())
def run_demo(model_file_name, output="", configfile=False):
    """ Run the application """
    model = VTKSurfaceModel(model_file_name, [1., 0., 0.])
    x_values = model.get_points_as_numpy()[:, 0]
    y_values = model.get_points_as_numpy()[:, 1]
    z_values = model.get_points_as_numpy()[:, 2]

    initial_parameters = [
        mean(x_values),
        mean(y_values),
        mean(z_values),
        std(x_values)
    ]
    bounds = ((-inf, -inf, -inf, -inf), (inf, inf, inf, inf))

    if configfile:
        configurer = ConfigurationManager(configfile)
        configuration = configurer.get_copy()
        if "initial values" in configuration:
            initial_parameters = configuration.get("initial values")
        if "bounds" in configuration:
            bounds = configuration.get("bounds")
        if "fixed radius" in configuration:
            radius = configuration.get("fixed radius")
            bounds = ((-inf, -inf, -inf, radius - 1e-6), (inf, inf, inf,
                                                          radius + 1e-6))

    result = sphere_fitting.fit_sphere_least_squares(x_values,
                                                     y_values,
                                                     z_values,
                                                     initial_parameters,
                                                     bounds=bounds)

    print("Result is {}".format(result))

    if output != "":

        sphere = vtk.vtkSphereSource()
        sphere.SetCenter(result.x[0], result.x[1], result.x[2])
        sphere.SetRadius(result.x[3])
        sphere.SetThetaResolution(60)
        sphere.SetPhiResolution(60)

        writer = vtk.vtkXMLPolyDataWriter()
        writer.SetFileName(output)
        writer.SetInputData(sphere.GetOutput())
        sphere.Update()
        writer.Write()
コード例 #11
0
def run_demo(configfile, verbose):
    """ Run the application """

    configurer = ConfigurationManager(configfile)

    app = QApplication([])

    configuration = configurer.get_copy()

    if verbose:
        print("Starting overlay app")

    overlay = OverlayApp(configuration)
    overlay.start()

    sys.exit(app.exec_())
コード例 #12
0
def test_two_surface_in_assembly():
    config = ConfigurationManager('tests/data/config/surface_model_two_in_assembly.json')
    data = config.get_copy()
    surfaces = data['surfaces']
    assert len(surfaces.keys()) == 2
    assert len(surfaces.values()) == 2

    for name in surfaces:
        assert isinstance(name, str)
        surface = surfaces[name]
        check_surface_properties(surface)

    assemblies = data['assemblies']
    assert len(assemblies.keys()) == 1

    assembly = next(iter(assemblies))
    for surface in assemblies[assembly]:
        assert surface in surfaces.keys()
コード例 #13
0
    def __init__(self, config_file):
        """
        Constructor.
        """
        super().__init__()

        #  set up the logger
        voice_recognition_logger = logging.getLogger("voice_recognition_logger")
        voice_recognition_logger.setLevel(logging.INFO)
        console_handler = logging.StreamHandler()
        console_handler.setLevel(logging.INFO)
        file_handler = logging.FileHandler('voice_recognition_log.log')
        file_handler.setLevel(logging.INFO)
        voice_recognition_logger.addHandler(console_handler)
        voice_recognition_logger.addHandler(file_handler)

        #  create VoiceRecognitionService()

        configurer = ConfigurationManager(config_file)
        config = configurer.get_copy()
        self.voice_recognition = speech_api.VoiceRecognitionService(config)
        #  create VoiceListener() which in this example has all the slots to
        #  react to the signals from the VoiceRecognitionService()
        self.listener = VoiceListener()

        #  Move the VoiceRecognitionService() to a separate thread so it doesn't
        #  block the main thread
        self.listener_thread = PySide2.QtCore.QThread(self)
        self.voice_recognition.moveToThread(self.listener_thread)
        self.listener_thread.started.connect(self.voice_recognition.run)

        #  connect the Signals emitted by the VoiceRecognitionService()
        #  with the Slots of the VoiceListener
        self.voice_recognition.start_listen\
            .connect(self.listener.on_start_listen)
        self.voice_recognition.google_api_not_understand\
            .connect(self.listener.on_google_api_not_understand)
        self.voice_recognition.google_api_request_failure\
            .connect(self.listener.on_google_api_request_failure)
        self.voice_recognition.start_processing_request\
            .connect(self.listener.on_start_processing_request)
        #connect this to our own slot
        self.voice_recognition.voice_command.connect(self.on_voice_signal)
def main(args=None):
    """ Entry point for bardVideoCalibrationChecker application. """

    parser = argparse.ArgumentParser(description='SciKit-Surgery Calibration '
                                     'Video Calibration Checker')

    parser.add_argument("-c",
                        "--config",
                        required=True,
                        type=str,
                        help="Configuration file containing the parameters.")

    parser.add_argument("-d",
                        "--calib_dir",
                        required=True,
                        type=str,
                        help="Directory containing calibration data.")

    parser.add_argument("-p",
                        "--prefix",
                        required=True,
                        type=str,
                        help="Prefix for calibration data.")

    version_string = __version__
    friendly_version_string = version_string if version_string else 'unknown'
    parser.add_argument("--version",
                        action='version',
                        version='scikit-surgerycalibration version ' +
                        friendly_version_string)

    args = parser.parse_args(args)

    configurer = ConfigurationManager(args.config)
    configuration = configurer.get_copy()

    run_video_calibration_checker(configuration, args.calib_dir, args.prefix)
コード例 #15
0
def run_chessboard_overlay(config_file, calib_dir, overlay_offset):
    """
    Simple app that detects a calibration pattern, runs
    solvePnP, and overlays VTK models.

    :param config_file: mandatory location of config file, containing params.
    """

    if config_file is None or len(config_file) == 0:
        raise ValueError("Config file must be provided.")
    if calib_dir is None or len(calib_dir) == 0:
        raise ValueError("Calibration directory must be specified")

    # Need this for all the Qt magic.
    app = QtWidgets.QApplication([])

    configurer = ConfigurationManager(config_file)
    configuration = configurer.get_copy()

    window = ChessboardOverlay(configuration, calib_dir, overlay_offset)
    window.start()

    # Start event loop.
    return sys.exit(app.exec_())
コード例 #16
0
def test_assembly_surface_doesnt_exist_raises_error():
    config = ConfigurationManager('tests/data/config/invalid_surface_in_assembly.json')
    config_data = config.get_copy()
    with pytest.raises(KeyError):
        SurfaceModelLoader(config_data)
コード例 #17
0
def test_empty_surface_config():
    config = ConfigurationManager('tests/data/config/invalid_config.json')
    data = config.get_copy()
    assert isinstance(data, dict)
    assert 'surfaces' not in data.keys()
コード例 #18
0
def test_surface_model_loader_with_no_shading():
    config_with_no_shading = ConfigurationManager('tests/data/config/surface_model_no_shading.json')
    config = config_with_no_shading.get_copy()
    loader = SurfaceModelLoader(config)
    assert len(loader.get_surface_models()) == 1
    assert loader.get_surface_model('liver').get_no_shading()
コード例 #19
0
def test_no_surfaces_raises_error():
    config = ConfigurationManager('tests/data/config/invalid_config.json')
    config_data = config.get_copy()
    with pytest.raises(KeyError):
        SurfaceModelLoader(config_data)
コード例 #20
0
def test_duplicate_surface_in_assembly_raises_error():
    config = ConfigurationManager('tests/data/config/surface_model_duplicates_in_assembly.json')
    config_data = config.get_copy()
    with pytest.raises(ValueError):
        SurfaceModelLoader(config_data)