Esempio n. 1
0
    def __init__(self,
                 parent,
                 title='Video page',
                 start_callback=None,
                 cancel_callback=None):
        Page.__init__(self,
                      parent,
                      title=title,
                      desc=_("Put the pattern on the platform as shown in the "
                             "picture and press \"Start\""),
                      left=_("Cancel"),
                      right=_("Start"),
                      button_left_callback=cancel_callback,
                      button_right_callback=start_callback,
                      view_progress=True)

        # Elements
        image_view = ImageView(self.panel, quality=wx.IMAGE_QUALITY_HIGH)
        image_view.set_image(
            wx.Image(resources.get_path_for_image("pattern-position.png")))
        self.video_view = VideoView(self.panel, self.get_image)

        # Layout
        self.panel_box.Add(image_view, 3, wx.ALL | wx.EXPAND, 3)
        self.panel_box.Add(self.video_view, 2, wx.ALL | wx.EXPAND, 3)
        self.Layout()
Esempio n. 2
0
    def __init__(self, parent, callback=None, size=(-1, -1), wxtimer=True):
        ImageView.__init__(self, parent, size=size, black=True)

        self.callback = callback

        self.wxtimer = wxtimer
        self.playing = False

        if self.wxtimer:
            self.timer = wx.Timer(self)
            self.Bind(wx.EVT_TIMER, self.on_timer, self.timer)
Esempio n. 3
0
    def __init__(self,
                 parent,
                 button_prev_callback=None,
                 button_next_callback=None):
        WizardPage.__init__(self,
                            parent,
                            title=_("Calibration"),
                            button_prev_callback=button_prev_callback,
                            button_next_callback=button_next_callback)

        self.parent = parent

        self.pattern_label = wx.StaticText(
            self.panel,
            label=
            _("Put the pattern on the platform as shown in the picture and press \"Calibrate\""
              ))
        self.pattern_label.Wrap(400)
        self.image_view = ImageView(self.panel, quality=wx.IMAGE_QUALITY_HIGH)
        self.image_view.set_image(
            wx.Image(resources.get_path_for_image("pattern-position.png")))
        self.calibrate_button = wx.Button(self.panel, label=_("Calibrate"))
        self.cancel_button = wx.Button(self.panel, label=_("Cancel"))
        self.gauge = wx.Gauge(self.panel, range=100, size=(-1, 30))
        self.result_label = wx.StaticText(self.panel, size=(-1, 30))

        self.cancel_button.Disable()
        self.result_label.Hide()
        self.skip_button.Enable()
        self.next_button.Disable()

        # Layout
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(self.pattern_label, 0, wx.ALL | wx.CENTER, 5)
        vbox.Add(self.image_view, 1, wx.ALL | wx.EXPAND, 5)
        vbox.Add(self.result_label, 0, wx.ALL | wx.CENTER, 5)
        vbox.Add(self.gauge, 0, wx.ALL | wx.EXPAND, 5)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(self.cancel_button, 1, wx.ALL | wx.EXPAND, 5)
        hbox.Add(self.calibrate_button, 1, wx.ALL | wx.EXPAND, 5)
        vbox.Add(hbox, 0, wx.ALL | wx.EXPAND, 2)
        self.panel.SetSizer(vbox)

        self.Layout()

        self.calibrate_button.Bind(wx.EVT_BUTTON,
                                   self.on_calibration_button_clicked)
        self.cancel_button.Bind(wx.EVT_BUTTON, self.on_cancel_button_clicked)
        self.Bind(wx.EVT_SHOW, self.on_show)

        self.video_view.set_callback(self.get_image)
Esempio n. 4
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        # Elements
        logo = ImageView(self)
        logo.set_image(wx.Image(resources.get_path_for_image("logo.png")))
        title_text = wx.StaticText(self, label=_("3D scanning for everyone"))
        title_font = title_text.GetFont()
        title_font.SetPointSize(14)
        title_text.SetFont(title_font)
        separator = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL)

        # Layout
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(logo, 10, wx.ALL ^ wx.BOTTOM | wx.EXPAND, 30)
        vbox.Add(title_text, 0, wx.TOP | wx.CENTER, 20)
        vbox.Add((0, 0), 1, wx.ALL | wx.EXPAND, 0)
        vbox.Add(separator, 0, wx.ALL | wx.EXPAND, 10)
        self.SetSizer(vbox)
        self.Layout()
Esempio n. 5
0
    def __init__(self, parent, start_callback=None):
        Page.__init__(self, parent,
                      title=_("Camera intrinsics (advanced)"),
                      desc=_("Default values are recommended. To perform the calibration, "
                             "click over the video panel and press "
                             "space bar to perform the captures."),
                      left=_("Reset"),
                      right=_("Start"),
                      button_left_callback=self.initialize,
                      button_right_callback=start_callback,
                      view_progress=True)

        self.right_button.Hide()

        # Elements
        self.video_view = VideoView(self.panel, self.get_image)
        self.rows, self.columns = 3, 5
        self.panel_grid = []
        self.current_grid = 0
        self.image_grid_panel = wx.Panel(self.panel)
        self.grid_sizer = wx.GridSizer(self.rows, self.columns, 3, 3)
        for panel in xrange(self.rows * self.columns):
            self.panel_grid.append(ImageView(self.image_grid_panel))
            self.panel_grid[panel].Bind(wx.EVT_KEY_DOWN, self.on_key_press)
            self.grid_sizer.Add(self.panel_grid[panel], 0, wx.ALL | wx.EXPAND)
        self.image_grid_panel.SetSizer(self.grid_sizer)

        # Layout
        self.panel_box.Add(self.video_view, 2, wx.ALL | wx.EXPAND, 2)
        self.panel_box.Add(self.image_grid_panel, 3, wx.ALL | wx.EXPAND, 3)
        self.Layout()

        # Events
        self.Bind(wx.EVT_KEY_DOWN, self.on_key_press)
        self.video_view.Bind(wx.EVT_KEY_DOWN, self.on_key_press)
        self.image_grid_panel.Bind(wx.EVT_KEY_DOWN, self.on_key_press)
Esempio n. 6
0
class ConnectionPage(WizardPage):

    def __init__(self, parent, button_prev_callback=None, button_next_callback=None):
        WizardPage.__init__(self, parent,
                            title=_("Connection"),
                            button_prev_callback=button_prev_callback,
                            button_next_callback=button_next_callback)

        self.parent = parent

        self.connect_button = wx.Button(self.panel, label=_("Connect"))
        self.preferences_button = wx.Button(self.panel, label=_("Preferences"))

        self.pattern_label = wx.StaticText(self.panel, label=_(
            "Put the pattern on the platform as shown in the picture and press \"Auto check\""))
        self.pattern_label.Wrap(400)
        self.image_view = ImageView(self.panel, quality=wx.IMAGE_QUALITY_HIGH)
        self.image_view.set_image(wx.Image(resources.get_path_for_image("pattern-position.png")))
        self.auto_check_button = wx.Button(self.panel, label=_("Auto check"))
        self.gauge = wx.Gauge(self.panel, range=100, size=(-1, 30))
        self.result_label = wx.StaticText(self.panel, size=(-1, 30))

        self.auto_check_button.Disable()
        self.skip_button.Disable()
        self.next_button.Disable()
        self.result_label.Hide()
        self.enable_next = False

        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(self.connect_button, 1, wx.ALL | wx.EXPAND, 5)
        hbox.Add(self.preferences_button, 1, wx.ALL | wx.EXPAND, 5)
        vbox.Add(hbox, 0, wx.ALL | wx.EXPAND, 2)
        vbox.Add(self.pattern_label, 0, wx.ALL | wx.CENTER, 5)
        vbox.Add(self.image_view, 1, wx.ALL | wx.EXPAND, 5)
        vbox.Add(self.result_label, 0, wx.ALL | wx.CENTER, 5)
        vbox.Add(self.gauge, 0, wx.ALL | wx.EXPAND, 5)
        vbox.Add(self.auto_check_button, 0, wx.ALL | wx.EXPAND, 5)
        self.panel.SetSizer(vbox)

        self.Layout()

        self.connect_button.Bind(wx.EVT_BUTTON, self.on_connect_button_clicked)
        self.preferences_button.Bind(wx.EVT_BUTTON, self.on_preferences_button_clicked)
        self.auto_check_button.Bind(wx.EVT_BUTTON, self.on_auto_check_button_clicked)
        self.Bind(wx.EVT_SHOW, self.on_show)

        self.video_view.set_callback(self.get_image)
        self.update_status(driver.is_connected)

    def on_show(self, event):
#old        if event.GetShow():
        if event.IsShown():
            driver.board.lasers_off()
            self.update_status(driver.is_connected)
        else:
            try:
                self.video_view.stop()
            except:
                pass

    def get_image(self):
        if scanner_autocheck.image is not None:
            image = scanner_autocheck.image
        else:
            image = image_capture.capture_pattern()
            image = image_detection.detect_pattern(image)
        return image

    def on_unplugged(self):
        self.video_view.stop()
        scanner_autocheck.cancel()
        driver.disconnect()
        self.parent.on_exit(message=False)

    def on_connect_button_clicked(self, event):
        if driver.is_connected:
            driver.disconnect()
            self.update_status(driver.is_connected)
        else:
            driver.set_callbacks(
                lambda: wx.CallAfter(self.before_connect),
                lambda r: wx.CallAfter(self.after_connect, r))
            driver.connect()

    def on_preferences_button_clicked(self, event):
        self.GetParent().parent.launch_preferences(basic=True)

    def before_connect(self):
        self.Disable()
        self.video_view.stop()
        driver.board.set_unplug_callback(None)
        driver.camera.set_unplug_callback(None)
        self.wait_cursor = wx.BusyCursor()

    def after_connect(self, response):
        ret, result = response

        if not ret:
            if isinstance(result, WrongFirmware):
                dlg = wx.MessageDialog(
                    self,
                    _("The board has the wrong firmware or an invalid baud rate.\n"
                      "Please select your board and press \"Upload firmware\""),
                    str(_(result)), wx.OK | wx.ICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
                self.update_status(False)
                self.GetParent().parent.launch_preferences()
            elif isinstance(result, BoardNotConnected):
                dlg = wx.MessageDialog(
                    self,
                    _("The board is not connected.\n"
                      "Please connect your board and select a valid Serial name"),
                    str(_(result)), wx.OK | wx.ICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
                self.update_status(False)
                self.GetParent().parent.launch_preferences(basic=True)
            elif isinstance(result, OldFirmware):
                dlg = wx.MessageDialog(
                    self,
                    _("The board has and old firmware.\n"
                      "Please select your board and press \"Upload firmware\""),
                    str(_(result)), wx.OK | wx.ICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
                self.update_status(False)
                self.GetParent().parent.launch_preferences()
            elif isinstance(result, WrongCamera):
                dlg = wx.MessageDialog(
                    self,
                    _("You probably have selected the wrong camera.\n"
                      "Please select another Camera ID"),
                    str(_(result)), wx.OK | wx.ICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
                self.update_status(False)
                self.GetParent().parent.launch_preferences(basic=True)
            elif isinstance(result, CameraNotConnected):
                dlg = wx.MessageDialog(
                    self, _("Please plug your camera in and try to connect again"),
                    str(_(result)), wx.OK | wx.ICON_ERROR)
                dlg.ShowModal()
                dlg.Destroy()
            elif isinstance(result, InvalidVideo):
                dlg = wx.MessageDialog(
                    self, _("Unplug and plug your camera USB cable and try to connect again"),
                    str(_(result)), wx.OK | wx.ICON_ERROR)
                dlg.ShowModal()
                dlg.Destroy()
            elif isinstance(result, WrongDriver):
                if system.is_windows():
                    dlg = wx.MessageDialog(
                        self, _("Please, download and install the camera driver: \n"
                                "http://support.logitech.com/en_us/product/hd-webcam-c270"),
                        str(_(result)), wx.OK | wx.ICON_ERROR)
                    dlg.ShowModal()
                    dlg.Destroy()

        self.update_status(driver.is_connected)
        self.Enable()
        del self.wait_cursor

    def on_auto_check_button_clicked(self, event):
        if profile.settings['adjust_laser']:
            profile.settings['adjust_laser'] = False
            dlg = wx.MessageDialog(
                self,
                _("It is recommended to adjust the line lasers vertically.\n"
                  "You will need to use the allen key.\n"
                  "Do you want to adjust it now?"),
                _("Manual laser adjustment"), wx.YES_NO | wx.ICON_QUESTION)
            result = dlg.ShowModal() == wx.ID_YES
            dlg.Destroy()
            if result:
                driver.board.lasers_on()
        else:
            # Perform auto check
            scanner_autocheck.set_callbacks(lambda: wx.CallAfter(self.before_auto_check),
                                            lambda p: wx.CallAfter(self.progress_auto_check, p),
                                            lambda r: wx.CallAfter(self.after_auto_check, r))
            scanner_autocheck.start()

    def before_auto_check(self):
        self.Disable()
        self.enable_next = False
        self.gauge.SetValue(0)
        self.result_label.Hide()
        self.gauge.Show()
        self.wait_cursor = wx.BusyCursor()
        self.Layout()

    def progress_auto_check(self, progress):
        self.gauge.SetValue(progress)

    def after_auto_check(self, response):
        ret, result = response

        if ret:
            self.result_label.SetLabel(_("Success. Please press \"Next\" to continue"))
            dlg = wx.MessageDialog(
                self, _("Scanner configured correctly"),
                _("Success"), wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        else:
            self.result_label.SetLabel(str(_(result)))
            if isinstance(result, PatternNotDetected):
                dlg = wx.MessageDialog(
                    self, _("Please, put the pattern on the platform. "
                            "Also you can set up the calibration's capture "
                            "settings in the \"Adjustment workbench\" "
                            "until the pattern is detected correctly"),
                    str(_(result)), wx.OK | wx.ICON_ERROR)
                dlg.ShowModal()
                dlg.Destroy()
            elif isinstance(result, WrongMotorDirection):
                dlg = wx.MessageDialog(
                    self, _(
                        "Please, select \"Invert the motor direction\" in the preferences"),
                    str(_(result)), wx.OK | wx.ICON_ERROR)
                dlg.ShowModal()
                dlg.Destroy()
                self.GetParent().parent.launch_preferences(basic=True)
            elif isinstance(result, LaserNotDetected):
                dlg = wx.MessageDialog(
                    self, _("Please, check the lasers connection. "
                            "Also you can set up the calibration's capture and "
                            "segmentation settings in the \"Adjustment workbench\" "
                            "until the lasers are detected correctly"),
                    str(_(result)), wx.OK | wx.ICON_ERROR)
                dlg.ShowModal()
                dlg.Destroy()

        if ret:
            self.skip_button.Disable()
            self.next_button.Enable()
        else:
            self.skip_button.Enable()
            self.next_button.Disable()

        self.Enable()
        self.enable_next = True
        self.result_label.Show()
        self.gauge.Hide()
        if hasattr(self, 'wait_cursor'):
            del self.wait_cursor
        self.panel.Fit()
        self.panel.Layout()
        self.Layout()

    def update_status(self, status):
        if status:
            driver.board.set_unplug_callback(
                lambda: wx.CallAfter(self.parent.on_board_unplugged))
            driver.camera.set_unplug_callback(
                lambda: wx.CallAfter(self.parent.on_camera_unplugged))
            self.GetParent().parent.workbench['calibration'].setup_engine()
            self.video_view.play()
            self.connect_button.SetLabel(_("Disconnect"))
            self.skip_button.Enable()
            self.enable_next = True
            self.auto_check_button.Enable()
        else:
            self.video_view.stop()
            self.video_view.reset()
            self.gauge.SetValue(0)
            self.gauge.Show()
            self.result_label.Hide()
            self.result_label.SetLabel("")
            self.connect_button.SetLabel(_("Connect"))
            self.skip_button.Disable()
            self.next_button.Disable()
            self.enable_next = False
            self.auto_check_button.Disable()
        self.Layout()
Esempio n. 7
0
class CalibrationPage(WizardPage):
    def __init__(self,
                 parent,
                 button_prev_callback=None,
                 button_next_callback=None):
        WizardPage.__init__(self,
                            parent,
                            title=_("Calibration"),
                            button_prev_callback=button_prev_callback,
                            button_next_callback=button_next_callback)

        self.parent = parent

        self.pattern_label = wx.StaticText(
            self.panel,
            label=
            _("Put the pattern on the platform as shown in the picture and press \"Calibrate\""
              ))
        self.pattern_label.Wrap(400)
        self.image_view = ImageView(self.panel, quality=wx.IMAGE_QUALITY_HIGH)
        self.image_view.set_image(
            wx.Image(resources.get_path_for_image("pattern-position.png")))
        self.calibrate_button = wx.Button(self.panel, label=_("Calibrate"))
        self.cancel_button = wx.Button(self.panel, label=_("Cancel"))
        self.gauge = wx.Gauge(self.panel, range=100, size=(-1, 30))
        self.result_label = wx.StaticText(self.panel, size=(-1, 30))

        self.cancel_button.Disable()
        self.result_label.Hide()
        self.skip_button.Enable()
        self.next_button.Disable()

        # Layout
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(self.pattern_label, 0, wx.ALL | wx.CENTER, 5)
        vbox.Add(self.image_view, 1, wx.ALL | wx.EXPAND, 5)
        vbox.Add(self.result_label, 0, wx.ALL | wx.CENTER, 5)
        vbox.Add(self.gauge, 0, wx.ALL | wx.EXPAND, 5)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(self.cancel_button, 1, wx.ALL | wx.EXPAND, 5)
        hbox.Add(self.calibrate_button, 1, wx.ALL | wx.EXPAND, 5)
        vbox.Add(hbox, 0, wx.ALL | wx.EXPAND, 2)
        self.panel.SetSizer(vbox)

        self.Layout()

        self.calibrate_button.Bind(wx.EVT_BUTTON,
                                   self.on_calibration_button_clicked)
        self.cancel_button.Bind(wx.EVT_BUTTON, self.on_cancel_button_clicked)
        self.Bind(wx.EVT_SHOW, self.on_show)

        self.video_view.set_callback(self.get_image)

    def on_show(self, event):
        if event.GetShow():
            driver.board.lasers_off()
            self.update_status(driver.is_connected)
        else:
            try:
                self.video_view.stop()
            except:
                pass

    def get_image(self):
        if combo_calibration.image is not None:
            image = combo_calibration.image
        else:
            image = image_capture.capture_pattern()
            image = image_detection.detect_pattern(image)
        return image

    def on_unplugged(self):
        self.video_view.stop()
        combo_calibration.cancel()
        self.enable_next = True
        driver.disconnect()
        self.parent.on_exit(message=False)

    def on_calibration_button_clicked(self, event):
        combo_calibration.set_callbacks(
            lambda: wx.CallAfter(self.before_calibration),
            lambda p: wx.CallAfter(self.progress_calibration, p),
            lambda r: wx.CallAfter(self.after_calibration, r))
        if profile.settings['pattern_origin_distance'] == 0.0:
            PatternDistanceWindow(self)
        else:
            combo_calibration.start()

    def on_cancel_button_clicked(self, event):
        board_unplug_callback = driver.board.unplug_callback
        camera_unplug_callback = driver.camera.unplug_callback
        driver.board.set_unplug_callback(None)
        driver.camera.set_unplug_callback(None)
        self.result_label.SetLabel(
            _("Calibration canceled. To try again press \"Calibrate\""))
        combo_calibration.cancel()
        self.skip_button.Enable()
        self.on_finish_calibration()
        driver.board.set_unplug_callback(board_unplug_callback)
        driver.camera.set_unplug_callback(camera_unplug_callback)

    def before_calibration(self):
        self.breadcrumbs.Disable()
        self.calibrate_button.Disable()
        self.cancel_button.Enable()
        self.prev_button.Disable()
        self.skip_button.Disable()
        self.next_button.Disable()
        self.enable_next = False
        self.gauge.SetValue(0)
        self.result_label.Hide()
        self.gauge.Show()
        self.Layout()
        self.wait_cursor = wx.BusyCursor()

    def progress_calibration(self, progress):
        self.gauge.SetValue(progress)

    def after_calibration(self, response):
        ret, result = response

        if ret:
            response_platform_extrinsics = result[0]
            response_laser_triangulation = result[1]

            profile.settings['distance_left'] = response_laser_triangulation[
                0][0]
            profile.settings['normal_left'] = response_laser_triangulation[0][
                1]
            profile.settings['distance_right'] = response_laser_triangulation[
                1][0]
            profile.settings['normal_right'] = response_laser_triangulation[1][
                1]

            profile.settings['rotation_matrix'] = response_platform_extrinsics[
                0]
            profile.settings[
                'translation_vector'] = response_platform_extrinsics[1]

            profile.settings[
                'laser_triangulation_hash'] = calibration_data.md5_hash()
            profile.settings[
                'platform_extrinsics_hash'] = calibration_data.md5_hash()

            combo_calibration.accept()
        else:
            if isinstance(result, ComboCalibrationError):
                self.result_label.SetLabel(
                    _("Check the pattern and the lasers and try again"))
                dlg = wx.MessageDialog(
                    self,
                    _("Scanner calibration has failed. "
                      "Please check the pattern and the lasers and try again. "
                      "Also you can set up the calibration's settings "
                      "in the \"Adjustment workbench\" until the pattern "
                      "and the lasers are detected correctly"),
                    _("Calibration failed"), wx.OK | wx.ICON_ERROR)
                dlg.ShowModal()
                dlg.Destroy()
            self.skip_button.Enable()
            self.on_finish_calibration()

        self.gauge.SetValue(100)

        if ret:
            self.skip_button.Disable()
            self.next_button.Enable()
            self.result_label.SetLabel(
                _("Success. Please press \"Next\" to continue"))
            dlg = wx.MessageDialog(self, _("Scanner calibrated correctly"),
                                   _("Success"), wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        else:
            self.skip_button.Enable()
            self.next_button.Disable()

        self.on_finish_calibration()

    def on_finish_calibration(self):
        self.breadcrumbs.Enable()
        self.enable_next = True
        self.gauge.Hide()
        self.result_label.Show()
        self.calibrate_button.Enable()
        self.cancel_button.Disable()
        self.prev_button.Enable()
        self.panel.Fit()
        self.panel.Layout()
        self.Layout()
        if hasattr(self, 'wait_cursor'):
            del self.wait_cursor

    def update_status(self, status):
        if status:
            self.GetParent().parent.workbench['calibration'].setup_engine()
            self.video_view.play()
            self.calibrate_button.Enable()
            self.skip_button.Enable()
            driver.board.lasers_off()
        else:
            self.video_view.stop()
            self.gauge.SetValue(0)
            self.gauge.Show()
            self.prev_button.Enable()
            self.skip_button.Disable()
            self.next_button.Disable()
            self.calibrate_button.Disable()
            self.cancel_button.Disable()