def test_widgets_with_arucos():
    from sandbox.sensor import Sensor
    from sandbox.markers import MarkerDetection
    from sandbox import _calibration_dir, _test_data
    sensor = Sensor(calibsensor=_calibration_dir + 'sensorcalib.json',
                    name='kinect_v2')
    aruco = MarkerDetection(sensor=sensor)
    color = np.load(_test_data['test'] + 'frame1.npz')['arr_1']
    geo_model = create_example_model(name='Anticline')
    module = GemPyModule(geo_model=geo_model,
                         extent=sensor.extent,
                         box=[1000, 800],
                         load_examples=True,
                         name_example=['Horizontal_layers'])
    module.setup(sensor.get_frame())
    pytest.sb_params['marker'] = aruco.update(frame=color)
    sb_params = module.update(pytest.sb_params)
    sb_params['fig'].show()
    module.set_section_dict((10, 10), (500, 500), "Section1")
    module.set_section_dict((100, 100), (500, 10), "Section2")

    module.set_borehole_dict((500, 500), "borehole3")
    module.set_borehole_dict((900, 500), "borehole4")
    module._get_polygon_data()
    aruco.plot_aruco(sb_params['ax'], sb_params['marker'])
    sb_params['fig'].show()
    widgets = module.show_widgets()
    widgets.show()
def test_check_frame():
    from sandbox import _calibration_dir
    _calibprojector = _calibration_dir + "my_projector_calibration.json"
    _calibsensor = _calibration_dir + "my_sensor_calibration.json"
    from sandbox.sensor import Sensor
    sensor = Sensor(calibsensor=_calibsensor, name="dummy")
    frame1 = sensor.get_frame()
    frame2 = sensor.get_frame()
    _rtol = 0.2
    _atol = 5
    cl = np.isclose(frame1, frame2,_rtol, _atol)
    frame1[np.logical_not(cl)] = frame2[np.logical_not(cl)]
    def __init__(self,
                 calibprojector: str = None,
                 name: str = 'kinectv2',
                 **kwargs):
        # color map setup
        self.c_under = '#DBD053'
        self.c_over = '#DB3A34'
        # margin patches setup
        self.c_margin = '#084C61'
        self.margin_alpha = 0.5
        self.calibprojector = calibprojector
        self.sensor = Sensor(name=name,
                             invert=False,
                             clip_values=False,
                             gauss_filter=False,
                             **kwargs)
        self.projector = Projector(calibprojector=self.calibprojector,
                                   **kwargs)
        import copy
        self.cmap = copy.copy(mpl.cm.get_cmap("Greys_r"))
        self.cmap.set_over(self.c_over)
        self.cmap.set_under(self.c_under)
        self.cmap.set_bad('k')

        self._refresh_panel_frame()

        # fig = plt.figure()
        self.figure = Figure()
        self.ax_notebook_frame = plt.Axes(self.figure, [0., 0., 1., 1.])
        self.figure.add_axes(self.ax_notebook_frame)

        self.calib_notebook_frame = pn.pane.Matplotlib(self.figure,
                                                       tight=False,
                                                       height=300)
        plt.close()  # close figure to prevent inline display

        pn.state.add_periodic_callback(self.update_panel_frame, 5)
        # self.projector.panel.add_periodic_callback(self.update_panel_frame, 5)

        self.frame_raw = self.sensor.get_raw_frame()
        self.ax_notebook_frame.imshow(self.frame_raw,
                                      vmin=self.sensor.s_min,
                                      vmax=self.sensor.s_max,
                                      cmap=self.cmap,
                                      origin="lower",
                                      aspect="auto")
        self.calib_notebook_frame.param.trigger('object')
        self._create_widgets()
def test_topo_module():
    from sandbox import _calibration_dir, _test_data
    file = np.load(_test_data['topo'] + "DEM1.npz")
    frame = file['arr_0']
    frame = frame + np.abs(frame.min())

    _calibprojector = _calibration_dir + "my_projector_calibration.json"
    _calibsensor = _calibration_dir + "my_sensor_calibration.json"
    from sandbox.sensor import Sensor
    sensor = Sensor(calibsensor=_calibsensor, name="dummy")
    from sandbox.projector import Projector
    projector = Projector(calibprojector=_calibprojector)
    # Initialize the aruco detection
    from sandbox.main_thread import MainThread
    mainT = MainThread(sensor=sensor, projector=projector)
    mainT.load_frame(frame)

    # Start the thread
    #mainT.run()
    from sandbox.modules import TopoModule
    module = TopoModule(extent = extent)
    mainT.add_module(name='Topo', module=module)
    module.sea = True
    module.sea_contour = True
    mainT.update()
def test_with_gempy():
    from sandbox import _calibration_dir, _test_data
    file = np.load(_test_data['topo'] + "DEM1.npz")
    frame = file['arr_0']
    frame = frame + np.abs(frame.min())

    _calibprojector = _calibration_dir + "my_projector_calibration.json"
    _calibsensor = _calibration_dir + "my_sensor_calibration.json"
    from sandbox.sensor import Sensor
    sensor = Sensor(calibsensor=_calibsensor, name="dummy")
    from sandbox.projector import Projector
    projector = Projector(calibprojector=_calibprojector)
    # Initialize the aruco detection
    from sandbox.main_thread import MainThread
    mainT = MainThread(sensor=sensor, projector=projector)
    mainT.load_frame(frame)
    # Start the thread
    #mainT.run()
    from sandbox.modules.gempy import GemPyModule
    gpsb = GemPyModule(geo_model=None,
                       extent=sensor.extent,
                       box=sensor.physical_dimensions,
                       load_examples=True,
                       name_example=['Fault'])
    mainT.add_module(name='gempy', module=gpsb)
    mainT.update()
def test_compute_model_space_arucos():
    from sandbox.sensor import Sensor
    from sandbox.markers import MarkerDetection
    from sandbox import _calibration_dir, _test_data
    sensor = Sensor(calibsensor=_calibration_dir + 'sensorcalib.json',
                    name='kinect_v2')
    aruco = MarkerDetection(sensor=sensor)
    color = np.load(_test_data['test'] + 'frame1.npz')['arr_1']
    module = GemPyModule(geo_model=None,
                         extent=sensor.extent,
                         box=[1000, 800],
                         load_examples=True,
                         name_example=['Horizontal_layers'])
    module.setup(sensor.get_frame())
    df = aruco.update(frame=color)
    df_new = module._compute_modelspace_arucos(df)
    print(df_new)
示例#7
0
def start_server(filename_projector: str = _calibration_dir +
                 "my_projector_calibration.json",
                 filename_sensor: str = _calibration_dir +
                 "my_sensor_calibration.json",
                 sensor_name='kinect_v2',
                 aruco_marker=True,
                 gempy_module=False,
                 **kwargs):
    #**projector_kwargs,
    #**sensor_kwargs,
    #**gempy_kwargs):

    from sandbox.projector import Projector
    from sandbox.sensor import Sensor
    from sandbox.markers import MarkerDetection

    if filename_projector is None:
        projector = Projector(use_panel=True, **kwargs)
    else:
        projector = Projector(calibprojector=filename_projector,
                              use_panel=True,
                              **kwargs)

    if filename_sensor is None:
        sensor = Sensor(name=sensor_name, **kwargs)
    else:
        sensor = Sensor(calibsensor=filename_sensor,
                        name=sensor_name,
                        **kwargs)

    if aruco_marker:
        aruco = MarkerDetection(sensor=sensor)
    else:
        aruco = None

    module = Sandbox(sensor=sensor,
                     projector=projector,
                     aruco=aruco,
                     gempy_module=gempy_module,
                     **kwargs)

    module.start()

    return module
def test_thread_kinectv2():
    from sandbox import _calibration_dir
    from sandbox.markers import MarkerDetection
    projector_2 = Projector(use_panel=True)
    sensor_2 = Sensor(name='kinect_v2', calibsensor=_calibration_dir+'my_sensor_calibration.json')
    aruco = MarkerDetection(sensor=sensor_2)
    smain = MainThread(sensor_2, projector_2, aruco)
    smain.sb_params['active_contours'] = True
    smain.sb_params['active_cmap'] = True
    smain.run()
def test_thread_module():
    from sandbox.modules import TopoModule, GradientModule
    proj = Projector(use_panel=True)
    sens = Sensor(name='kinect_v2', invert=True)
    smain = MainThread(sens, proj)

    topo = TopoModule(extent=sens.extent)
    grad = GradientModule(extent=sens.extent)

    smain.modules = [topo]
    smain.run()
示例#10
0
def test_update_arucos():
    from sandbox.sensor import Sensor
    from sandbox.markers import MarkerDetection
    from sandbox import _calibration_dir, _test_data
    sensor = Sensor(calibsensor=_calibration_dir + 'sensorcalib.json',
                    name='kinect_v2',
                    invert=False)
    aruco = MarkerDetection(sensor=sensor)
    color = np.load(_test_data['test'] + 'frame1.npz')['arr_1']
    module = GemPyModule(geo_model=None,
                         extent=sensor.extent,
                         box=[1000, 800],
                         load_examples=True,
                         name_example=['Horizontal_layers'])
    sb_params = pytest.sb_params
    sb_params['frame'] = sensor.get_frame()
    module.setup(sb_params['frame'])
    sb_params['marker'] = aruco.update(frame=color)

    sb_params = module.update(sb_params)
    sb_params['fig'].show()
    aruco.plot_aruco(sb_params['ax'], sb_params['marker'])
    fig.show()
def test_bug_no_dpi():
    from sandbox import _calibration_dir
    _calibprojector = _calibration_dir + "my_projector_calibration.json"
    _calibsensor = _calibration_dir + "my_sensor_calibration.json"
    from sandbox.sensor import Sensor
    sensor = Sensor(calibsensor=_calibsensor, name="kinect_v2")
    from sandbox.projector import Projector
    projector = Projector(calibprojector=_calibprojector)
    # Initialize the aruco detection
    from sandbox.markers import MarkerDetection
    aruco = MarkerDetection(sensor=sensor)
    from sandbox.main_thread import MainThread
    main = MainThread(sensor=sensor, projector=projector, aruco=aruco)
    # Start the thread
    main.run()
def test_bug_no_dpi_no_aruco():
    #import matplotlib.text
    from sandbox import _calibration_dir
    _calibprojector = _calibration_dir + "my_projector_calibration.json"
    _calibsensor = _calibration_dir + "my_sensor_calibration.json"
    from sandbox.sensor import Sensor
    sensor = Sensor(calibsensor=_calibsensor, name="dummy")
    from sandbox.projector import Projector
    projector = Projector(calibprojector=_calibprojector, use_panel = False)
    # Initialize the aruco detection
    from sandbox.main_thread import MainThread
    main = MainThread(sensor=sensor, projector=projector)
    # Start the thread
    main.update()
    projector.trigger()
示例#13
0
def start_server(calibprojector: str = None,  # _calibration_dir + "my_projector_calibration.json",
                 calibsensor: str = None,  # _calibration_dir + "my_sensor_calibration.json",
                 sensor_name: str = None,
                 aruco_marker: bool = True,
                 kwargs_external_modules: dict = {},
                 kwargs_gempy_module: dict = {},
                 kwargs_projector: dict = {},
                 kwargs_sensor: dict = {},
                 kwargs_aruco: dict = {},
                 ):
    global name_sensor, p_width, p_height
    if sensor_name is None:
        sensor_name = name_sensor
    else:
        name_sensor = sensor_name

    from sandbox.projector import Projector
    if kwargs_projector.get("p_width") is not None:
        p_width = kwargs_projector.get("p_width")
    if kwargs_projector.get("p_height") is not None:
        p_height = kwargs_projector.get("p_height")
    projector = Projector(calibprojector=calibprojector, use_panel=True, **kwargs_projector)

    from sandbox.sensor import Sensor
    sensor = Sensor(calibsensor=calibsensor, name=sensor_name, **kwargs_sensor)

    if aruco_marker:
        from sandbox.markers import MarkerDetection
        aruco = MarkerDetection(sensor=sensor, **kwargs_aruco)
    else:
        aruco = None

    module = Sandbox(sensor=sensor,
                     projector=projector,
                     aruco=aruco,
                     kwargs_gempy_module=kwargs_gempy_module,
                     kwargs_external_modules=kwargs_external_modules)

    module.start()

    return module
示例#14
0
def test_init_kinect_v1():
    """ Test if detects the kinect 1"""

    sensor = Sensor(name='kinect_v1')
    print(sensor.get_frame(), sensor.get_frame().shape)
    assert sensor.get_frame().shape == (240, 320)
示例#15
0
def test_init_dummy():
    sensor = Sensor(name='dummy', random_seed=1234)
    print(sensor.depth[0, 0], sensor.depth[0, 0], sensor.depth[0, 0])
示例#16
0
from sandbox.markers import ArucoMarkers, MarkerDetection
from sandbox.sensor import Sensor
from sandbox import _test_data, _calibration_dir
im_folder = _test_data['test']
import numpy as np
import matplotlib.pyplot as plt
frame = np.load(im_folder + 'frame1.npz')
depth = frame['arr_0']
color = frame['arr_1']
try:
    sensor = Sensor(calibsensor=_calibration_dir + "sensorcalib.json",
                    name='kinect_v2')
except:
    import warnings as warn
    warn("Testing will be performed without the sensor")
    sensor = None


def test_plot_image():
    depth = frame['arr_0']
    col = frame['arr_1']
    plt.imshow(depth)
    plt.show()
    plt.imshow(col)
    plt.show()


def test_aruco_detect():
    aruco = ArucoMarkers()
    corners, ids, rejected = aruco.aruco_detect(color)
    print(corners, ids, rejected)
示例#17
0
# sandbox_server.py
from bokeh.plotting import curdoc
from sandbox import _calibration_dir

_calibprojector = _calibration_dir + "my_projector_calibration.json"
_calibsensor = _calibration_dir + "my_sensor_calibration.json"

from sandbox.projector import Projector
from sandbox.sensor import Sensor
from sandbox.markers import MarkerDetection

projector = Projector(calibprojector=_calibprojector, use_panel=True)
sensor = Sensor(calibsensor=_calibsensor, name="kinect_v2")
aruco = MarkerDetection(sensor=sensor)

external_modules = dict(gempy_module=True,
                        gimli_module=True,
                        torch_module=True,
                        devito_module=True)

from sandbox.sandbox_api import Sandbox
module = Sandbox(sensor=sensor,
                 projector=projector,
                 aruco=aruco,
                 kwargs_external_modules=external_modules)

main_widget = module.show_widgets()

current = main_widget.get_root()
curdoc().add_root(current)
示例#18
0
def test_get_frame_croped_clipped():
    sensor = Sensor(name='dummy', crop_values=True, clip_values=True)
    frame = sensor.get_frame()
    print(frame.shape, frame)
    assert frame.shape == (404, 492)
from sandbox import _test_data as test_data
from sandbox.main_thread import MainThread
from sandbox.projector import Projector
from sandbox.sensor import Sensor
import matplotlib.pyplot as plt
import numpy as np

file = np.load(test_data['topo'] + "DEM1.npz")
frame = file['arr_0']
frame = frame + np.abs(frame.min())
extent = np.asarray([0, frame.shape[1], 0, frame.shape[0], frame.min(), frame.max()])

projector = Projector(use_panel=False)
sensor = Sensor(name='dummy')

def test_init():
    smain = MainThread(sensor, projector)
    print(smain)

def test_update():
    projector_2 = Projector(use_panel=True)
    sensor_2 = Sensor(name='dummy')
    smain = MainThread(sensor_2, projector_2)
    smain.update()

def test_run(): #TODO: runs but does not show contour lines
    projector_2 = Projector(use_panel=True)
    sensor_2 = Sensor(name='dummy')
    smain = MainThread(sensor_2, projector_2)
    smain.run()
示例#20
0
def test_save_load_calibration_projector():
    sensor = Sensor(name='dummy')
    file = calib_dir + 'test_sensor_calibration.json'
    sensor.save_json(file=file)
    # now to test if it loads correctly the saved one
    sensor2 = Sensor(name='dummy', calibsensor=file)
示例#21
0
def test_get_frame():
    sensor = Sensor(name='kinect_v2', invert=False)
    print(sensor.get_frame())
    plt.imshow(sensor.depth, cmap='viridis', origin="lower")
    plt.show()
class CalibSensor:  #TODO: include automatic
    """Module to calibrate the sensor"""
    def __init__(self,
                 calibprojector: str = None,
                 name: str = 'kinectv2',
                 **kwargs):
        # color map setup
        self.c_under = '#DBD053'
        self.c_over = '#DB3A34'
        # margin patches setup
        self.c_margin = '#084C61'
        self.margin_alpha = 0.5
        self.calibprojector = calibprojector
        self.sensor = Sensor(name=name, invert=False, **kwargs)
        self.projector = Projector(calibprojector=self.calibprojector,
                                   **kwargs)
        self.cmap = plt.cm.get_cmap('Greys_r')
        self.cmap.set_over(self.c_over)
        self.cmap.set_under(self.c_under)
        self.cmap.set_bad('k')

        self._refresh_panel_frame()

        #fig = plt.figure()
        self.figure = Figure()
        self.ax_notebook_frame = plt.Axes(self.figure, [0., 0., 1., 1.])
        self.figure.add_axes(self.ax_notebook_frame)

        self.calib_notebook_frame = pn.pane.Matplotlib(self.figure,
                                                       tight=False,
                                                       height=300)
        plt.close()  # close figure to prevent inline display

        self.projector.panel.add_periodic_callback(self.update_panel_frame, 5)

        self.frame_raw = self.sensor.get_raw_frame()
        self.ax_notebook_frame.imshow(self.frame_raw,
                                      vmin=self.sensor.s_min,
                                      vmax=self.sensor.s_max,
                                      cmap=self.cmap,
                                      origin="lower",
                                      aspect="auto")
        self.calib_notebook_frame.param.trigger('object')
        self._create_widgets()

        #self._lock = threading.Lock()
        #self._thread = None
        #self._thread_status = 'stopped'
        #self.run()

    def _refresh_panel_frame(self):
        self.projector.ax.cla()
        self.fig_frame = self.projector.ax.imshow(self.sensor.get_frame(),
                                                  vmin=self.sensor.s_min,
                                                  vmax=self.sensor.s_max,
                                                  cmap=self.cmap,
                                                  origin="lower",
                                                  aspect="auto")

    def update(self):
        self.update_panel_frame(self.projector.ax)
        self.update_notebook_frame(self.ax_panel_frame)

    def update_panel_frame(self):
        frame = self.sensor.get_frame()
        self.projector.ax.set_xlim(0, self.sensor.s_frame_width)
        self.projector.ax.set_ylim(0, self.sensor.s_frame_height)
        self.fig_frame.set_data(frame)

    def update_notebook_frame(self):
        """ Adds margin patches to the current plot object.
        This is only useful when an uncropped dataframe is passed.
        """

        self.ax_notebook_frame.cla()
        self.ax_notebook_frame.imshow(self.frame_raw,
                                      vmin=self.sensor.s_min,
                                      vmax=self.sensor.s_max,
                                      cmap=self.cmap,
                                      origin="lower",
                                      aspect="auto")

        rec_t = plt.Rectangle((0, self.sensor.s_height - self.sensor.s_top),
                              self.sensor.s_width,
                              self.sensor.s_top,
                              fc=self.c_margin,
                              alpha=self.margin_alpha)
        rec_r = plt.Rectangle((self.sensor.s_width - self.sensor.s_right, 0),
                              self.sensor.s_right,
                              self.sensor.s_height,
                              fc=self.c_margin,
                              alpha=self.margin_alpha)
        rec_b = plt.Rectangle((0, 0),
                              self.sensor.s_width,
                              self.sensor.s_bottom,
                              fc=self.c_margin,
                              alpha=self.margin_alpha)
        rec_l = plt.Rectangle((0, 0),
                              self.sensor.s_left,
                              self.sensor.s_height,
                              fc=self.c_margin,
                              alpha=self.margin_alpha)
        self.ax_notebook_frame.add_patch(rec_t)
        self.ax_notebook_frame.add_patch(rec_r)
        self.ax_notebook_frame.add_patch(rec_b)
        self.ax_notebook_frame.add_patch(rec_l)
        self.calib_notebook_frame.param.trigger('object')

    def calibrate_sensor(self):
        widgets = pn.WidgetBox(
            '<b>Load a projector calibration file</b>',
            self._widget_json_filename_load_projector,
            self._widget_json_load_projector,
            '<b>Distance from edges (pixel)</b>',
            self._widget_s_top,
            self._widget_s_right,
            self._widget_s_bottom,
            self._widget_s_left,
            #self._widget_s_enable_auto_cropping,
            #self._widget_s_automatic_cropping,
            pn.layout.VSpacer(height=5),
            '<b>Distance from sensor (mm)</b>',
            self._widget_s_min,
            self._widget_s_max,
            self._widget_refresh_frame)
        box = pn.Column(
            '<b>Physical dimensions of the sandbox</b>',
            self._widget_box_width,
            self._widget_box_height,
        )
        save = pn.Column('<b>Save file</b>', self._widget_json_filename,
                         self._widget_json_save)

        rows = pn.Row(widgets, self.calib_notebook_frame)
        panel = pn.Column('## Sensor calibration', rows)
        tabs = pn.Tabs(('Calibration', panel), ("Box dimensions", box),
                       ("Save files", save))
        return tabs

    def _create_widgets(self):
        # sensor widgets and links

        self._widget_s_top = pn.widgets.IntSlider(name='Sensor top margin',
                                                  bar_color=self.c_margin,
                                                  value=self.sensor.s_top,
                                                  start=1,
                                                  end=self.sensor.s_height)
        self._widget_s_top.param.watch(self._callback_s_top,
                                       'value',
                                       onlychanged=False)

        self._widget_s_right = pn.widgets.IntSlider(name='Sensor right margin',
                                                    bar_color=self.c_margin,
                                                    value=self.sensor.s_right,
                                                    start=1,
                                                    end=self.sensor.s_width)
        self._widget_s_right.param.watch(self._callback_s_right,
                                         'value',
                                         onlychanged=False)

        self._widget_s_bottom = pn.widgets.IntSlider(
            name='Sensor bottom margin',
            bar_color=self.c_margin,
            value=self.sensor.s_bottom,
            start=1,
            end=self.sensor.s_height)
        self._widget_s_bottom.param.watch(self._callback_s_bottom,
                                          'value',
                                          onlychanged=False)

        self._widget_s_left = pn.widgets.IntSlider(name='Sensor left margin',
                                                   bar_color=self.c_margin,
                                                   value=self.sensor.s_left,
                                                   start=1,
                                                   end=self.sensor.s_width)
        self._widget_s_left.param.watch(self._callback_s_left,
                                        'value',
                                        onlychanged=False)

        self._widget_s_min = pn.widgets.IntSlider(name='Vertical minimum',
                                                  bar_color=self.c_under,
                                                  value=self.sensor.s_min,
                                                  start=0,
                                                  end=2000)
        self._widget_s_min.param.watch(self._callback_s_min,
                                       'value',
                                       onlychanged=False)

        self._widget_s_max = pn.widgets.IntSlider(name='Vertical maximum',
                                                  bar_color=self.c_over,
                                                  value=self.sensor.s_max,
                                                  start=0,
                                                  end=2000)
        self._widget_s_max.param.watch(self._callback_s_max,
                                       'value',
                                       onlychanged=False)

        # Auto cropping widgets:

        #self._widget_s_enable_auto_cropping = pn.widgets.Checkbox(name='Enable Automatic Cropping', value=False)
        #self._widget_s_enable_auto_cropping.param.watch(self._callback_enable_auto_cropping, 'value',
        #                                                onlychanged=False)

        #self._widget_s_automatic_cropping = pn.widgets.Button(name="Crop", button_type="success")
        #self._widget_s_automatic_cropping.param.watch(self._callback_automatic_cropping, 'clicks',
        #                                              onlychanged=False)

        # box widgets:

        # self._widget_s_enable_auto_calibration = CheckboxGroup(labels=["Enable Automatic Sensor Calibration"],
        #                                                                  active=[1])
        self._widget_box_width = pn.widgets.IntSlider(
            name='width of sandbox in mm',
            bar_color=self.c_margin,
            value=int(self.sensor.box_width),
            start=1,
            end=2000)
        self._widget_box_width.param.watch(self._callback_box_width,
                                           'value',
                                           onlychanged=False)

        # self._widget_s_automatic_calibration = pn.widgets.Toggle(name="Run", button_type="success")
        self._widget_box_height = pn.widgets.IntSlider(
            name='height of sandbox in mm',
            bar_color=self.c_margin,
            value=int(self.sensor.box_height),
            start=1,
            end=2000)
        self._widget_box_height.param.watch(self._callback_box_height,
                                            'value',
                                            onlychanged=False)

        # refresh button

        self._widget_refresh_frame = pn.widgets.Button(
            name='Refresh sensor frame\n(3 sec. delay)!')
        self._widget_refresh_frame.param.watch(self._callback_refresh_frame,
                                               'clicks',
                                               onlychanged=False)

        # save selection

        # Only for reading files --> Is there no location picker in panel widgets???
        # self._widget_json_location = pn.widgets.FileInput(name='JSON location')
        self._widget_json_filename = pn.widgets.TextInput(
            name='Choose a calibration filename:')
        self._widget_json_filename.param.watch(self._callback_json_filename,
                                               'value',
                                               onlychanged=False)
        self._widget_json_filename.value = _calibration_dir + 'my_sensor_calibration.json'

        self._widget_json_save = pn.widgets.Button(name='Save calibration')
        self._widget_json_save.param.watch(self._callback_json_save,
                                           'clicks',
                                           onlychanged=False)

        self._widget_json_filename_load_projector = pn.widgets.TextInput(
            name='Choose the projector calibration filename:')
        self._widget_json_filename_load_projector.param.watch(
            self._callback_json_filename_load_projector,
            'value',
            onlychanged=False)
        self._widget_json_filename_load_projector.value = _calibration_dir + 'my_projector_calibration.json'

        self._widget_json_load_projector = pn.widgets.Button(
            name='Load calibration')
        self._widget_json_load_projector.param.watch(
            self._callback_json_load_projector, 'clicks', onlychanged=False)

        return True

        # sensor callbacks
    def _callback_s_top(self, event):
        self.sensor.s_top = event.new
        # change plot and trigger panel update
        self.update_notebook_frame()

    def _callback_s_right(self, event):
        self.sensor.s_right = event.new
        #self._refresh_panel_frame() #TODO: dirty workaround
        self.update_notebook_frame()

    def _callback_s_bottom(self, event):
        self.sensor.s_bottom = event.new
        self.update_notebook_frame()

    def _callback_s_left(self, event):
        self.sensor.s_left = event.new
        #self._refresh_panel_frame()  # TODO: dirty workaround
        self.update_notebook_frame()

    def _callback_s_min(self, event):
        self.sensor.s_min = event.new
        #self._refresh_panel_frame()  # TODO: dirty workaround
        self.update_notebook_frame()

    def _callback_s_max(self, event):
        self.sensor.s_max = event.new
        #self._refresh_panel_frame()  # TODO: dirty workaround
        self.update_notebook_frame()

    def _callback_refresh_frame(self, event):
        plt.pause(3)
        # only here, get a new frame before updating the plot
        self.frame_raw = self.sensor.get_raw_frame()
        self.update_notebook_frame()

    def _callback_json_filename(self, event):
        self.sensor.json_filename = event.new

    def _callback_json_save(self, event):
        if self.sensor.json_filename is not None:
            self.sensor.save_json(file=self.sensor.json_filename)

    def _callback_json_filename_load_projector(self, event):
        self.calibprojector = event.new

    def _callback_json_load_projector(self, event):
        if self.calibprojector is not None:
            self.projector = Projector(self.calibprojector)

    def _callback_box_width(self, event):
        self.sensor.box_width = float(event.new)

    def _callback_box_height(self, event):
        self.sensor.box_height = float(event.new)

    """def _callback_enable_auto_calibration(self, event):
def test_run(): #TODO: runs but does not show contour lines
    projector_2 = Projector(use_panel=True)
    sensor_2 = Sensor(name='dummy')
    smain = MainThread(sensor_2, projector_2)
    smain.run()
示例#24
0
def test_extent_property():
    sensor = Sensor(name='dummy')
    print(sensor.extent)
    assert np.allclose(np.asarray([0, 492, 0, 404, 0, 800]), sensor.extent)
def test_update():
    projector_2 = Projector(use_panel=True)
    sensor_2 = Sensor(name='dummy')
    smain = MainThread(sensor_2, projector_2)
    smain.update()
示例#26
0
def test_init_kinect_v2():
    """Test if detects the kinect 2"""
    sensor = Sensor(name='kinect_v2', crop_values=False)
    # print(sensor.get_frame(), sensor.get_frame().shape)
    assert sensor.get_frame().shape == (424, 512)