Esempio n. 1
0
	def __init__(self, parent, afterCancelCallback=None, afterCalibrationCallback=None):
		Page.__init__(self, parent,
							title=_("Simple Laser Triangulation"),
							subTitle=_("Put the pattern on the platform as shown in the picture and press Calibrate to continue"),
							left=_("Cancel"),
							right=_("Calibrate"),
							buttonLeftCallback=self.onCancel,
							buttonRightCallback=self.onCalibrate,
							panelOrientation=wx.HORIZONTAL,
							viewProgress=True)

		self.driver = Driver.Instance()
		self.cameraIntrinsics = calibration.CameraIntrinsics.Instance()
		self.laserTriangulation = calibration.LaserTriangulation.Instance()

		self.afterCancelCallback = afterCancelCallback
		self.afterCalibrationCallback = afterCalibrationCallback

		#-- Image View
		imageView = ImageView(self._panel)
		imageView.setImage(wx.Image(resources.getPathForImage("pattern-position-right.jpg")))

		#-- Video View
		self.videoView = VideoView(self._panel, self.getFrame, 50)
		self.videoView.SetBackgroundColour(wx.BLACK)

		#-- Layout
		self.addToPanel(imageView, 3)
		self.addToPanel(self.videoView, 2)

		#-- Events
		self.Bind(wx.EVT_SHOW, self.onShow)

		self.Layout()
Esempio n. 2
0
	def __init__(self, parent, afterCancelCallback=None, afterCalibrationCallback=None):
		Page.__init__(self, parent,
							title=_("Simple Laser Triangulation"),
							subTitle=_("Put the pattern on the platform as shown in the picture and press Calibrate to continue"),
							left=_("Cancel"),
							right=_("Calibrate"),
							buttonLeftCallback=self.onCancel,
							buttonRightCallback=self.onCalibrate,
							panelOrientation=wx.HORIZONTAL,
							viewProgress=True)

		self.driver = Driver.Instance()
		self.cameraIntrinsics = calibration.CameraIntrinsics.Instance()
		self.laserTriangulation = calibration.LaserTriangulation.Instance()

		self.afterCancelCallback = afterCancelCallback
		self.afterCalibrationCallback = afterCalibrationCallback

		#-- Image View
		imageView = ImageView(self._panel)
		imageView.setImage(wx.Image(resources.getPathForImage("pattern-position-right.jpg")))

		#-- Video View
		self.videoView = VideoView(self._panel, self.getFrame, 50)
		self.videoView.SetBackgroundColour(wx.BLACK)

		#-- Layout
		self.addToPanel(imageView, 3)
		self.addToPanel(self.videoView, 2)

		#-- Events
		self.Bind(wx.EVT_SHOW, self.onShow)

		self.Layout()
Esempio n. 3
0
class SimpleLaserTriangulationImageSequence(wx.Panel):
    def __init__(self, parent, title="Title"):
        wx.Panel.__init__(self, parent)

        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        titleText = wx.StaticText(self, label=title)
        titleText.SetFont((wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.NORMAL,
                                   wx.FONTWEIGHT_BOLD)))

        panel = wx.Panel(self)
        self.imageLas = ImageView(panel)
        self.imageGray = ImageView(panel)
        self.imageBin = ImageView(panel)
        self.imageLine = ImageView(panel)

        self.imageLas.SetBackgroundColour('#AAAAAA')
        self.imageGray.SetBackgroundColour('#AAAAAA')
        self.imageBin.SetBackgroundColour('#AAAAAA')
        self.imageLine.SetBackgroundColour('#AAAAAA')

        #-- Layout
        vbox.Add(titleText, 0, wx.ALL | wx.EXPAND, 5)
        hbox.Add(self.imageLas, 1, wx.ALL | wx.EXPAND, 3)
        hbox.Add(self.imageGray, 1, wx.ALL | wx.EXPAND, 3)
        hbox.Add(self.imageBin, 1, wx.ALL | wx.EXPAND, 3)
        hbox.Add(self.imageLine, 1, wx.ALL | wx.EXPAND, 3)
        panel.SetSizer(hbox)
        vbox.Add(panel, 1, wx.ALL | wx.EXPAND, 3)

        self.SetSizer(vbox)
        self.Layout()
Esempio n. 4
0
    def __init__(self,
                 parent,
                 buttonPrevCallback=None,
                 buttonNextCallback=None):
        WizardPage.__init__(self,
                            parent,
                            title=_("Calibration"),
                            buttonPrevCallback=buttonPrevCallback,
                            buttonNextCallback=buttonNextCallback)

        self.driver = Driver.Instance()
        self.cameraIntrinsics = calibration.CameraIntrinsics.Instance()
        self.laserTriangulation = calibration.LaserTriangulation.Instance()
        self.platformExtrinsics = calibration.PlatformExtrinsics.Instance()
        self.phase = 'none'

        self.patternLabel = wx.StaticText(
            self.panel,
            label=
            _("Put the pattern on the platform as shown in the picture and press \"Calibrate\""
              ))
        self.patternLabel.Wrap(400)
        self.imageView = ImageView(self.panel)
        self.imageView.setImage(
            wx.Image(resources.getPathForImage("pattern-position-right.jpg")))
        self.calibrateButton = wx.Button(self.panel, label=_("Calibrate"))
        self.cancelButton = wx.Button(self.panel, label=_("Cancel"))
        self.gauge = wx.Gauge(self.panel, range=100, size=(-1, 30))
        self.resultLabel = wx.StaticText(self.panel, size=(-1, 30))

        self.cancelButton.Disable()
        self.resultLabel.Hide()
        self.skipButton.Enable()
        self.nextButton.Disable()

        #-- Layout
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(self.patternLabel, 0, wx.ALL | wx.CENTER, 5)
        vbox.Add(self.imageView, 1, wx.ALL | wx.EXPAND, 5)
        vbox.Add(self.resultLabel, 0, wx.ALL | wx.CENTER, 5)
        vbox.Add(self.gauge, 0, wx.ALL | wx.EXPAND, 5)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(self.cancelButton, 1, wx.ALL | wx.EXPAND, 5)
        hbox.Add(self.calibrateButton, 1, wx.ALL | wx.EXPAND, 5)
        vbox.Add(hbox, 0, wx.ALL | wx.EXPAND, 2)
        self.panel.SetSizer(vbox)

        self.Layout()

        self.calibrateButton.Bind(wx.EVT_BUTTON,
                                  self.onCalibrationButtonClicked)
        self.cancelButton.Bind(wx.EVT_BUTTON, self.onCancelButtonClicked)
        self.Bind(wx.EVT_SHOW, self.onShow)

        self.videoView.setMilliseconds(20)
        self.videoView.setCallback(self.getFrame)
Esempio n. 5
0
    def __init__(self, parent, buttonPrevCallback=None, buttonNextCallback=None):
        WizardPage.__init__(self, parent,
                            title=_("Connection"),
                            buttonPrevCallback=buttonPrevCallback,
                            buttonNextCallback=buttonNextCallback)

        self.parent = parent
        self.driver = Driver.Instance()
        self.cameraIntrinsics = calibration.CameraIntrinsics.Instance()
        self.autoCheck = calibration.SimpleLaserTriangulation.Instance()

        self.connectButton = wx.Button(self.panel, label=_("Connect"))
        self.settingsButton = wx.Button(self.panel, label=_("Edit settings"))


        self.patternLabel = wx.StaticText(self.panel, label=_("Put the pattern on the platform as shown in the picture and press \"Auto check\""))
        self.patternLabel.Wrap(400)
        self.imageView = ImageView(self.panel)
        self.imageView.setImage(wx.Image(resources.getPathForImage("pattern-position-right.jpg")))
        self.autoCheckButton = wx.Button(self.panel, label=_("Auto check"))
        self.gauge = wx.Gauge(self.panel, range=100, size=(-1, 30))
        self.resultLabel = wx.StaticText(self.panel, size=(-1, 30))

        self.connectButton.Enable()
        self.settingsButton.Enable()
        self.patternLabel.Disable()
        self.imageView.Disable()
        self.autoCheckButton.Disable()
        self.skipButton.Disable()
        self.nextButton.Disable()
        self.resultLabel.Hide()
        self.enableNext = False

        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(self.connectButton, 1, wx.ALL|wx.EXPAND, 5)
        hbox.Add(self.settingsButton, 1, wx.ALL|wx.EXPAND, 5)
        vbox.Add(hbox, 0, wx.ALL|wx.EXPAND, 2)
        vbox.Add(self.patternLabel, 0, wx.ALL|wx.CENTER, 5)
        vbox.Add(self.imageView, 1, wx.ALL|wx.EXPAND, 5)
        vbox.Add(self.resultLabel, 0, wx.ALL|wx.CENTER, 5)
        vbox.Add(self.gauge, 0, wx.ALL|wx.EXPAND, 5)
        vbox.Add(self.autoCheckButton, 0, wx.ALL|wx.EXPAND, 5)
        self.panel.SetSizer(vbox)

        self.Layout()

        self.connectButton.Bind(wx.EVT_BUTTON, self.onConnectButtonClicked)
        self.settingsButton.Bind(wx.EVT_BUTTON, self.onSettingsButtonClicked)
        self.autoCheckButton.Bind(wx.EVT_BUTTON, self.onAutoCheckButtonClicked)
        self.Bind(wx.EVT_SHOW, self.onShow)

        self.videoView.setMilliseconds(50)
        self.videoView.setCallback(self.getDetectChessboardFrame)
        self.updateStatus(self.driver.isConnected)
Esempio n. 6
0
	def __init__(self, parent, buttonPrevCallback=None, buttonNextCallback=None):
		WizardPage.__init__(self, parent,
							title=_("Connection"),
							buttonPrevCallback=buttonPrevCallback,
							buttonNextCallback=buttonNextCallback)

		self.parent = parent
		self.driver = Driver.Instance()
		self.cameraIntrinsics = calibration.CameraIntrinsics.Instance()
		self.autoCheck = calibration.SimpleLaserTriangulation.Instance()

		self.connectButton = wx.Button(self.panel, label=_("Connect"))
		luminosity=profile.getProfileSettingObject('luminosity').getType()
		self.luminosityComboBox = wx.ComboBox(self.panel, wx.ID_ANY,
											  value=profile.getProfileSetting('luminosity'),
											  choices=[_(luminosity[0]), _(luminosity[1]), _(luminosity[2])],
											  style=wx.CB_READONLY)
		self.patternLabel = wx.StaticText(self.panel, label=_("Put the pattern on the platform and press \"Auto check\""))
		self.imageView = ImageView(self.panel)
		self.imageView.setImage(wx.Image(resources.getPathForImage("pattern-position-right.jpg")))
		self.autoCheckButton = wx.Button(self.panel, label=_("Auto check"))
		self.gauge = wx.Gauge(self.panel, range=100, size=(-1, 30))
		self.resultLabel = wx.StaticText(self.panel, size=(-1, 30))

		self.connectButton.Enable()
		self.patternLabel.Disable()
		self.imageView.Disable()
		self.autoCheckButton.Disable()
		self.skipButton.Disable()
		self.nextButton.Disable()
		self.resultLabel.Hide()
		self.enableNext = False

		vbox = wx.BoxSizer(wx.VERTICAL)
		hbox = wx.BoxSizer(wx.HORIZONTAL)
		hbox.Add(self.connectButton, 1, wx.ALL|wx.EXPAND, 5)
		hbox.Add(self.luminosityComboBox, 0, wx.ALL|wx.EXPAND, 5)
		vbox.Add(hbox, 0, wx.ALL|wx.EXPAND, 2)
		vbox.Add(self.patternLabel, 0, wx.ALL|wx.CENTER, 5)
		vbox.Add(self.imageView, 1, wx.ALL|wx.EXPAND, 5)
		vbox.Add(self.resultLabel, 0, wx.ALL|wx.CENTER, 5)
		vbox.Add(self.gauge, 0, wx.ALL|wx.EXPAND, 5)
		vbox.Add(self.autoCheckButton, 0, wx.ALL|wx.EXPAND, 5)
		self.panel.SetSizer(vbox)

		self.Layout()

		self.connectButton.Bind(wx.EVT_BUTTON, self.onConnectButtonClicked)
		self.luminosityComboBox.Bind(wx.EVT_COMBOBOX, self.onLuminosityComboBoxChanged)
		self.autoCheckButton.Bind(wx.EVT_BUTTON, self.onAutoCheckButtonClicked)
		self.Bind(wx.EVT_SHOW, self.onShow)

		self.videoView.setMilliseconds(50)
		self.videoView.setCallback(self.getDetectChessboardFrame)
		self.updateStatus(self.driver.isConnected)
Esempio n. 7
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        logo = ImageView(self)
        logo.setImage(wx.Image(resources.getPathForImage("logo.png")))
        titleText = wx.StaticText(self, label=_("3D Scanning for everyone"))
        titleText.SetFont((wx.Font(13, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_NORMAL)))
        separator = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL)

        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(logo, 10, wx.ALL^wx.BOTTOM|wx.EXPAND, 30)
        vbox.Add(titleText, 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. 8
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        logo = ImageView(self)
        logo.setImage(wx.Image(resources.getPathForImage("logo.png")))
        titleText = wx.StaticText(self, label=_("3D Scanning for everyone"))
        titleText.SetFont((wx.Font(13, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_NORMAL)))
        separator = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL)

        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(logo, 10, wx.ALL^wx.BOTTOM|wx.EXPAND, 30)
        vbox.Add(titleText, 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. 9
0
    def __init__(self, parent, buttonPrevCallback=None, buttonNextCallback=None):
        WizardPage.__init__(self, parent,
                            title=_("Connection"),
                            buttonPrevCallback=buttonPrevCallback,
                            buttonNextCallback=buttonNextCallback)

        self.parent = parent
        self.driver = Driver.Instance()
        self.cameraIntrinsics = calibration.CameraIntrinsics.Instance()
        self.autoCheck = calibration.SimpleLaserTriangulation.Instance()

        self.connectButton = wx.Button(self.panel, label=_("Connect"))
        self.settingsButton = wx.Button(self.panel, label=_("Edit settings"))


        self.patternLabel = wx.StaticText(self.panel, label=_("Put the pattern on the platform as shown in the picture and press \"Auto check\""))
        self.patternLabel.Wrap(400)
        self.imageView = ImageView(self.panel)
        self.imageView.setImage(wx.Image(resources.getPathForImage("pattern-position-right.jpg")))
        self.autoCheckButton = wx.Button(self.panel, label=_("Auto check"))
        self.gauge = wx.Gauge(self.panel, range=100, size=(-1, 30))
        self.resultLabel = wx.StaticText(self.panel, size=(-1, 30))

        self.connectButton.Enable()
        self.settingsButton.Enable()
        self.patternLabel.Disable()
        self.imageView.Disable()
        self.autoCheckButton.Disable()
        self.skipButton.Disable()
        self.nextButton.Disable()
        self.resultLabel.Hide()
        self.enableNext = False

        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(self.connectButton, 1, wx.ALL|wx.EXPAND, 5)
        hbox.Add(self.settingsButton, 1, wx.ALL|wx.EXPAND, 5)
        vbox.Add(hbox, 0, wx.ALL|wx.EXPAND, 2)
        vbox.Add(self.patternLabel, 0, wx.ALL|wx.CENTER, 5)
        vbox.Add(self.imageView, 1, wx.ALL|wx.EXPAND, 5)
        vbox.Add(self.resultLabel, 0, wx.ALL|wx.CENTER, 5)
        vbox.Add(self.gauge, 0, wx.ALL|wx.EXPAND, 5)
        vbox.Add(self.autoCheckButton, 0, wx.ALL|wx.EXPAND, 5)
        self.panel.SetSizer(vbox)

        self.Layout()

        self.connectButton.Bind(wx.EVT_BUTTON, self.onConnectButtonClicked)
        self.settingsButton.Bind(wx.EVT_BUTTON, self.onSettingsButtonClicked)
        self.autoCheckButton.Bind(wx.EVT_BUTTON, self.onAutoCheckButtonClicked)
        self.Bind(wx.EVT_SHOW, self.onShow)

        self.videoView.setMilliseconds(50)
        self.videoView.setCallback(self.getDetectChessboardFrame)
        self.updateStatus(self.driver.isConnected)
Esempio n. 10
0
    def __init__(self,
                 parent,
                 afterCancelCallback=None,
                 afterCalibrationCallback=None):
        Page.__init__(self,
                      parent,
                      title=_("Camera Intrinsics"),
                      subTitle=_("Press space bar to perform captures"),
                      left=_("Cancel"),
                      right=_("Calibrate"),
                      buttonLeftCallback=self.onCancel,
                      buttonRightCallback=self.onCalibrate,
                      panelOrientation=wx.HORIZONTAL,
                      viewProgress=True)

        self.driver = Driver.Instance()
        self.cameraIntrinsics = calibration.CameraIntrinsics.Instance()

        self.afterCancelCallback = afterCancelCallback
        self.afterCalibrationCallback = afterCalibrationCallback

        #-- Video View
        self.videoView = VideoView(self._panel, self.getFrame, 50)
        self.videoView.SetBackgroundColour(wx.BLACK)

        #-- Image Grid Panel
        self.imageGridPanel = wx.Panel(self._panel)
        self.rows, self.columns = 2, 6
        self.panelGrid = []
        self.gridSizer = wx.GridSizer(self.rows, self.columns, 3, 3)
        for panel in xrange(self.rows * self.columns):
            self.panelGrid.append(ImageView(self.imageGridPanel))
            self.panelGrid[panel].Bind(wx.EVT_KEY_DOWN, self.onKeyPress)
            self.panelGrid[panel].SetBackgroundColour((221, 221, 221))
            self.panelGrid[panel].setImage(
                wx.Image(resources.getPathForImage("void.png")))
            self.gridSizer.Add(self.panelGrid[panel], 0, wx.ALL | wx.EXPAND)
        self.imageGridPanel.SetSizer(self.gridSizer)

        #-- Layout
        self.addToPanel(self.videoView, 1)
        self.addToPanel(self.imageGridPanel, 3)

        #-- Events
        self.Bind(wx.EVT_SHOW, self.onShow)
        self.videoView.Bind(wx.EVT_KEY_DOWN, self.onKeyPress)
        self.imageGridPanel.Bind(wx.EVT_KEY_DOWN, self.onKeyPress)

        self.videoView.SetFocus()
        self.Layout()
Esempio n. 11
0
	def __init__(self, parent, buttonPrevCallback=None, buttonNextCallback=None):
		WizardPage.__init__(self, parent,
							title=_("Calibration"),
							buttonPrevCallback=buttonPrevCallback,
							buttonNextCallback=buttonNextCallback)

		self.driver = Driver.Instance()
		self.cameraIntrinsics = calibration.CameraIntrinsics.Instance()
		self.laserTriangulation = calibration.LaserTriangulation.Instance()
		self.platformExtrinsics = calibration.PlatformExtrinsics.Instance()
		self.phase = 'none'

		self.patternLabel = wx.StaticText(self.panel, label=_("Put the pattern on the platform as shown in the picture and press \"Calibrate\""))
		self.patternLabel.Wrap(400)
		self.imageView = ImageView(self.panel)
		self.imageView.setImage(wx.Image(resources.getPathForImage("pattern-position-right.jpg")))
		self.calibrateButton = wx.Button(self.panel, label=_("Calibrate"))
		self.cancelButton = wx.Button(self.panel, label=_("Cancel"))
		self.gauge = wx.Gauge(self.panel, range=100, size=(-1, 30))
		self.resultLabel = wx.StaticText(self.panel, size=(-1, 30))

		self.cancelButton.Disable()
		self.resultLabel.Hide()
		self.skipButton.Enable()
		self.nextButton.Disable()

		#-- Layout
		vbox = wx.BoxSizer(wx.VERTICAL)
		vbox.Add(self.patternLabel, 0, wx.ALL|wx.CENTER, 5)
		vbox.Add(self.imageView, 1, wx.ALL|wx.EXPAND, 5)
		vbox.Add(self.resultLabel, 0, wx.ALL|wx.CENTER, 5)
		vbox.Add(self.gauge, 0, wx.ALL|wx.EXPAND, 5)
		hbox = wx.BoxSizer(wx.HORIZONTAL)
		hbox.Add(self.cancelButton, 1, wx.ALL|wx.EXPAND, 5)
		hbox.Add(self.calibrateButton, 1, wx.ALL|wx.EXPAND, 5)
		vbox.Add(hbox, 0, wx.ALL|wx.EXPAND, 2)
		self.panel.SetSizer(vbox)

		self.Layout()

		self.calibrateButton.Bind(wx.EVT_BUTTON, self.onCalibrationButtonClicked)
		self.cancelButton.Bind(wx.EVT_BUTTON, self.onCancelButtonClicked)
		self.Bind(wx.EVT_SHOW, self.onShow)

		self.videoView.setMilliseconds(20)
		self.videoView.setCallback(self.getFrame)
Esempio n. 12
0
class ConnectionPage(WizardPage):
    def __init__(self, parent, buttonPrevCallback=None, buttonNextCallback=None):
        WizardPage.__init__(self, parent,
                            title=_("Connection"),
                            buttonPrevCallback=buttonPrevCallback,
                            buttonNextCallback=buttonNextCallback)

        self.parent = parent
        self.driver = Driver.Instance()
        self.cameraIntrinsics = calibration.CameraIntrinsics.Instance()
        self.autoCheck = calibration.SimpleLaserTriangulation.Instance()

        self.connectButton = wx.Button(self.panel, label=_("Connect"))
        self.settingsButton = wx.Button(self.panel, label=_("Edit settings"))


        self.patternLabel = wx.StaticText(self.panel, label=_("Put the pattern on the platform as shown in the picture and press \"Auto check\""))
        self.patternLabel.Wrap(400)
        self.imageView = ImageView(self.panel)
        self.imageView.setImage(wx.Image(resources.getPathForImage("pattern-position-right.jpg")))
        self.autoCheckButton = wx.Button(self.panel, label=_("Auto check"))
        self.gauge = wx.Gauge(self.panel, range=100, size=(-1, 30))
        self.resultLabel = wx.StaticText(self.panel, size=(-1, 30))

        self.connectButton.Enable()
        self.settingsButton.Enable()
        self.patternLabel.Disable()
        self.imageView.Disable()
        self.autoCheckButton.Disable()
        self.skipButton.Disable()
        self.nextButton.Disable()
        self.resultLabel.Hide()
        self.enableNext = False

        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(self.connectButton, 1, wx.ALL|wx.EXPAND, 5)
        hbox.Add(self.settingsButton, 1, wx.ALL|wx.EXPAND, 5)
        vbox.Add(hbox, 0, wx.ALL|wx.EXPAND, 2)
        vbox.Add(self.patternLabel, 0, wx.ALL|wx.CENTER, 5)
        vbox.Add(self.imageView, 1, wx.ALL|wx.EXPAND, 5)
        vbox.Add(self.resultLabel, 0, wx.ALL|wx.CENTER, 5)
        vbox.Add(self.gauge, 0, wx.ALL|wx.EXPAND, 5)
        vbox.Add(self.autoCheckButton, 0, wx.ALL|wx.EXPAND, 5)
        self.panel.SetSizer(vbox)

        self.Layout()

        self.connectButton.Bind(wx.EVT_BUTTON, self.onConnectButtonClicked)
        self.settingsButton.Bind(wx.EVT_BUTTON, self.onSettingsButtonClicked)
        self.autoCheckButton.Bind(wx.EVT_BUTTON, self.onAutoCheckButtonClicked)
        self.Bind(wx.EVT_SHOW, self.onShow)

        self.videoView.setMilliseconds(50)
        self.videoView.setCallback(self.getDetectChessboardFrame)
        self.updateStatus(self.driver.isConnected)

    def onShow(self, event):
        if event.GetShow():
            self.updateStatus(self.driver.isConnected)
        else:
            try:
                self.videoView.stop()
            except:
                pass

    def getFrame(self):
        return self.driver.camera.captureImage()

    def getDetectChessboardFrame(self):
        frame = self.getFrame()
        if frame is not None:
            retval, frame = self.cameraIntrinsics.detectChessboard(frame)
        return frame

    def onUnplugged(self):
        self.videoView.stop()
        self.autoCheck.cancel()
        self.afterMoveMotor()

    def onConnectButtonClicked(self, event):
        self.driver.setCallbacks(self.beforeConnect, lambda r: wx.CallAfter(self.afterConnect,r))
        self.driver.connect()

    def onSettingsButtonClicked(self, event):
        SettingsWindow(self)

    def beforeConnect(self):
        self.settingsButton.Disable()
        self.breadcrumbs.Disable()
        self.connectButton.Disable()
        self.prevButton.Disable()
        self.videoView.stop()
        self.driver.board.setUnplugCallback(None)
        self.driver.camera.setUnplugCallback(None)
        self.waitCursor = wx.BusyCursor()

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

        if not ret:
            if result is Error.WrongFirmware:
                dlg = wx.MessageDialog(self, _("Board has a wrong firmware.\nPlease select your Board\nand press Upload Firmware"), _(result), wx.OK|wx.ICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
                self.updateStatus(False)
                self.GetParent().parent.onPreferences(None)
            elif result is Error.BoardNotConnected:
                dlg = wx.MessageDialog(self, _("Board is not connected.\nPlease connect your board\nand select a valid Serial Name"), _(result), wx.OK|wx.ICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
                self.updateStatus(False)
                self.GetParent().parent.onPreferences(None)
            elif result is Error.CameraNotConnected:
                dlg = wx.MessageDialog(self, _("Please plug your camera and try to connect again"), _(result), wx.OK|wx.ICON_ERROR)
                dlg.ShowModal()
                dlg.Destroy()
            elif result is Error.WrongCamera:
                dlg = wx.MessageDialog(self, _("You probably have selected a wrong camera.\nPlease select other Camera Id"), _(result), wx.OK|wx.ICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
                self.updateStatus(False)
                self.GetParent().parent.onPreferences(None)
            elif result is Error.InvalidVideo:
                dlg = wx.MessageDialog(self, _("Unplug and plug your camera USB cable and try to connect again."), _(result), wx.OK|wx.ICON_ERROR)
                dlg.ShowModal()
                dlg.Destroy()

        self.updateStatus(self.driver.isConnected)
        self.settingsButton.Enable()
        self.breadcrumbs.Enable()
        self.prevButton.Enable()
        del self.waitCursor

    def onAutoCheckButtonClicked(self, event):
        if profile.getProfileSettingBool('adjust_laser'):
            profile.putProfileSetting('adjust_laser', False)
            dlg = wx.MessageDialog(self, _("It is recomended to adjust line lasers vertically.\nYou need to use the allen wrench.\nDo 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:
                self.driver.board.setLeftLaserOn()
                self.driver.board.setRightLaserOn()
        else:
            self.beforeAutoCheck()

            #-- Perform auto check
            self.autoCheck.setCallbacks(None,
                                        lambda p: wx.CallAfter(self.progressAutoCheck,p),
                                        lambda r: wx.CallAfter(self.afterAutoCheck,r))
            self.autoCheck.start()

    def beforeAutoCheck(self):
        self.settingsButton.Disable()
        self.breadcrumbs.Disable()
        self.autoCheckButton.Disable()
        self.prevButton.Disable()
        self.skipButton.Disable()
        self.nextButton.Disable()
        self.enableNext = False
        self.gauge.SetValue(0)
        self.resultLabel.Hide()
        self.gauge.Show()
        self.waitCursor = wx.BusyCursor()
        self.Layout()

    def progressAutoCheck(self, progress):
        self.gauge.SetValue(0.9*progress)

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

        if ret:
            self.resultLabel.SetLabel(_("All OK. Please press next to continue"))
        else:
            self.resultLabel.SetLabel(_("Please check motor direction and pattern position and try again"))

        if ret:
            self.skipButton.Disable()
            self.nextButton.Enable()
        else:
            self.skipButton.Enable()
            self.nextButton.Disable()

        self.videoView.setMilliseconds(20)
        self.videoView.setCallback(self.getFrame)

        self.driver.board.setSpeedMotor(150)
        self.driver.board.setRelativePosition(-90)
        self.driver.board.enableMotor()
        self.driver.board.moveMotor(nonblocking=True, callback=(lambda r: wx.CallAfter(self.afterMoveMotor)))

    def afterMoveMotor(self):
        self.videoView.setMilliseconds(50)
        self.videoView.setCallback(self.getDetectChessboardFrame)
        self.settingsButton.Enable()
        self.breadcrumbs.Enable()
        self.gauge.SetValue(100)
        self.enableNext = True
        self.resultLabel.Show()
        self.autoCheckButton.Enable()
        self.prevButton.Enable()
        self.driver.board.disableMotor()
        self.gauge.Hide()
        if hasattr(self, 'waitCursor'):
            del self.waitCursor
        self.panel.Fit()
        self.panel.Layout()
        self.Layout()

    def updateStatus(self, status):
        if status:
            self.driver.board.setUnplugCallback(lambda: wx.CallAfter(self.parent.onBoardUnplugged))
            self.driver.camera.setUnplugCallback(lambda: wx.CallAfter(self.parent.onCameraUnplugged))
            #if profile.getPreference('workbench') != 'Calibration workbench':
            profile.putPreference('workbench', 'Calibration workbench')
            self.GetParent().parent.workbenchUpdate(False)
            self.videoView.play()
            self.connectButton.Disable()
            self.autoCheckButton.Enable()
            self.patternLabel.Enable()
            self.imageView.Enable()
            self.skipButton.Enable()
            self.enableNext = True
            self.driver.board.setLeftLaserOff()
            self.driver.board.setRightLaserOff()
        else:
            self.videoView.stop()
            self.gauge.SetValue(0)
            self.gauge.Show()
            self.resultLabel.Hide()
            self.resultLabel.SetLabel("")
            self.connectButton.Enable()
            self.skipButton.Disable()
            self.nextButton.Disable()
            self.enableNext = False
            self.autoCheckButton.Disable()
        self.Layout()
Esempio n. 13
0
class CalibrationPage(WizardPage):
    def __init__(self,
                 parent,
                 buttonPrevCallback=None,
                 buttonNextCallback=None):
        WizardPage.__init__(self,
                            parent,
                            title=_("Calibration"),
                            buttonPrevCallback=buttonPrevCallback,
                            buttonNextCallback=buttonNextCallback)

        self.driver = Driver.Instance()
        self.cameraIntrinsics = calibration.CameraIntrinsics.Instance()
        self.laserTriangulation = calibration.LaserTriangulation.Instance()
        self.platformExtrinsics = calibration.PlatformExtrinsics.Instance()
        self.phase = 'none'

        self.patternLabel = wx.StaticText(
            self.panel,
            label=
            _("Put the pattern on the platform as shown in the picture and press \"Calibrate\""
              ))
        self.patternLabel.Wrap(400)
        self.imageView = ImageView(self.panel)
        self.imageView.setImage(
            wx.Image(resources.getPathForImage("pattern-position-right.jpg")))
        self.calibrateButton = wx.Button(self.panel, label=_("Calibrate"))
        self.cancelButton = wx.Button(self.panel, label=_("Cancel"))
        self.gauge = wx.Gauge(self.panel, range=100, size=(-1, 30))
        self.resultLabel = wx.StaticText(self.panel, size=(-1, 30))

        self.cancelButton.Disable()
        self.resultLabel.Hide()
        self.skipButton.Enable()
        self.nextButton.Disable()

        #-- Layout
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(self.patternLabel, 0, wx.ALL | wx.CENTER, 5)
        vbox.Add(self.imageView, 1, wx.ALL | wx.EXPAND, 5)
        vbox.Add(self.resultLabel, 0, wx.ALL | wx.CENTER, 5)
        vbox.Add(self.gauge, 0, wx.ALL | wx.EXPAND, 5)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(self.cancelButton, 1, wx.ALL | wx.EXPAND, 5)
        hbox.Add(self.calibrateButton, 1, wx.ALL | wx.EXPAND, 5)
        vbox.Add(hbox, 0, wx.ALL | wx.EXPAND, 2)
        self.panel.SetSizer(vbox)

        self.Layout()

        self.calibrateButton.Bind(wx.EVT_BUTTON,
                                  self.onCalibrationButtonClicked)
        self.cancelButton.Bind(wx.EVT_BUTTON, self.onCancelButtonClicked)
        self.Bind(wx.EVT_SHOW, self.onShow)

        self.videoView.setMilliseconds(20)
        self.videoView.setCallback(self.getFrame)

    def onShow(self, event):
        if event.GetShow():
            self.updateStatus(self.driver.isConnected)
        else:
            try:
                self.videoView.stop()
            except:
                pass

    def getFrame(self):
        if self.phase is 'platformCalibration':
            frame = self.platformExtrinsics.getImage()
        elif self.phase is 'laserTriangulation':
            frame = self.laserTriangulation.getImage()
        else:  # 'none'
            frame = self.driver.camera.captureImage()

        if frame is not None and self.phase is not 'laserTriangulation':
            retval, frame = self.cameraIntrinsics.detectChessboard(frame)

        return frame

    def onUnplugged(self):
        self.videoView.stop()
        self.laserTriangulation.cancel()
        self.platformExtrinsics.cancel()
        self.enableNext = True

    def onCalibrationButtonClicked(self, event):
        self.phase = 'laserTriangulation'
        self.laserTriangulation.setCallbacks(
            self.beforeCalibration,
            lambda p: wx.CallAfter(self.progressLaserCalibration, p),
            lambda r: wx.CallAfter(self.afterLaserCalibration, r))
        if profile.getProfileSettingFloat('pattern_distance') == 0:
            PatternDistanceWindow(self)
        else:
            self.laserTriangulation.start()

    def onCancelButtonClicked(self, event):
        boardUnplugCallback = self.driver.board.unplugCallback
        cameraUnplugCallback = self.driver.camera.unplugCallback
        self.driver.board.setUnplugCallback(None)
        self.driver.camera.setUnplugCallback(None)
        self.phase = 'none'
        self.resultLabel.SetLabel(
            _("Calibration canceled. To try again press \"Calibrate\""))
        self.platformExtrinsics.cancel()
        self.laserTriangulation.cancel()
        self.skipButton.Enable()
        self.onFinishCalibration()
        self.driver.board.setUnplugCallback(boardUnplugCallback)
        self.driver.camera.setUnplugCallback(cameraUnplugCallback)

    def beforeCalibration(self):
        self.calibrateButton.Disable()
        self.cancelButton.Enable()
        self.prevButton.Disable()
        self.skipButton.Disable()
        self.nextButton.Disable()
        self.enableNext = False
        self.gauge.SetValue(0)
        self.resultLabel.Hide()
        self.gauge.Show()
        self.Layout()
        self.waitCursor = wx.BusyCursor()

    def progressLaserCalibration(self, progress):
        self.gauge.SetValue(progress * 0.6)

    def afterLaserCalibration(self, response):
        self.phase = 'platformCalibration'
        ret, result = response

        if ret:
            profile.putProfileSetting('distance_left', result[0][0])
            profile.putProfileSettingNumpy('normal_left', result[0][1])
            profile.putProfileSetting('distance_right', result[1][0])
            profile.putProfileSettingNumpy('normal_right', result[1][1])
            self.platformExtrinsics.setCallbacks(
                None,
                lambda p: wx.CallAfter(self.progressPlatformCalibration, p),
                lambda r: wx.CallAfter(self.afterPlatformCalibration, r))
            self.platformExtrinsics.start()
        else:
            if result == Error.CalibrationError:
                self.resultLabel.SetLabel(
                    _("Error in lasers: please connect the lasers and try again"
                      ))
                dlg = wx.MessageDialog(
                    self, _("Laser Calibration failed. Please try again"),
                    _(result), wx.OK | wx.ICON_ERROR)
                dlg.ShowModal()
                dlg.Destroy()
                self.skipButton.Enable()
                self.onFinishCalibration()

    def progressPlatformCalibration(self, progress):
        self.gauge.SetValue(60 + progress * 0.4)

    def afterPlatformCalibration(self, response):
        self.phase = 'none'
        ret, result = response

        if ret:
            profile.putProfileSettingNumpy('rotation_matrix', result[0])
            profile.putProfileSettingNumpy('translation_vector', result[1])
        else:
            if result == Error.CalibrationError:
                self.resultLabel.SetLabel(
                    _("Error in pattern: please check the pattern and try again"
                      ))
                dlg = wx.MessageDialog(
                    self, _("Platform Calibration failed. Please try again"),
                    _(result), wx.OK | wx.ICON_ERROR)
                dlg.ShowModal()
                dlg.Destroy()

        if ret:
            self.skipButton.Disable()
            self.nextButton.Enable()
            self.resultLabel.SetLabel(
                _("All OK. Please press next to continue"))
        else:
            self.skipButton.Enable()
            self.nextButton.Disable()

        self.onFinishCalibration()

    def onFinishCalibration(self):
        self.enableNext = True
        self.gauge.Hide()
        self.resultLabel.Show()
        self.calibrateButton.Enable()
        self.cancelButton.Disable()
        self.prevButton.Enable()
        self.panel.Fit()
        self.panel.Layout()
        self.Layout()
        if hasattr(self, 'waitCursor'):
            del self.waitCursor

    def updateStatus(self, status):
        if status:
            if profile.getPreference('workbench') != 'Calibration workbench':
                profile.putPreference('workbench', 'Calibration workbench')
                self.GetParent().parent.workbenchUpdate(False)
            self.videoView.play()
            self.calibrateButton.Enable()
            self.skipButton.Enable()
            self.driver.board.setLeftLaserOff()
            self.driver.board.setRightLaserOff()
        else:
            self.videoView.stop()
            self.gauge.SetValue(0)
            self.gauge.Show()
            self.prevButton.Enable()
            self.skipButton.Disable()
            self.nextButton.Disable()
            self.calibrateButton.Disable()
            self.cancelButton.Disable()
Esempio n. 14
0
class ConnectionPage(WizardPage):
    def __init__(self,
                 parent,
                 buttonPrevCallback=None,
                 buttonNextCallback=None):
        WizardPage.__init__(self,
                            parent,
                            title=_("Connection"),
                            buttonPrevCallback=buttonPrevCallback,
                            buttonNextCallback=buttonNextCallback)

        self.parent = parent
        self.driver = Driver.Instance()
        self.cameraIntrinsics = calibration.CameraIntrinsics.Instance()
        self.autoCheck = calibration.SimpleLaserTriangulation.Instance()

        self.connectButton = wx.Button(self.panel, label=_("Connect"))
        self.settingsButton = wx.Button(self.panel, label=_("Edit settings"))

        self.patternLabel = wx.StaticText(
            self.panel,
            label=
            _("Put the pattern on the platform as shown in the picture and press \"Auto check\""
              ))
        self.patternLabel.Wrap(400)
        self.imageView = ImageView(self.panel)
        self.imageView.setImage(
            wx.Image(resources.getPathForImage("pattern-position-right.jpg")))
        self.autoCheckButton = wx.Button(self.panel, label=_("Auto check"))
        self.gauge = wx.Gauge(self.panel, range=100, size=(-1, 30))
        self.resultLabel = wx.StaticText(self.panel, size=(-1, 30))

        self.connectButton.Enable()
        self.settingsButton.Enable()
        self.patternLabel.Disable()
        self.imageView.Disable()
        self.autoCheckButton.Disable()
        self.skipButton.Disable()
        self.nextButton.Disable()
        self.resultLabel.Hide()
        self.enableNext = False

        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(self.connectButton, 1, wx.ALL | wx.EXPAND, 5)
        hbox.Add(self.settingsButton, 1, wx.ALL | wx.EXPAND, 5)
        vbox.Add(hbox, 0, wx.ALL | wx.EXPAND, 2)
        vbox.Add(self.patternLabel, 0, wx.ALL | wx.CENTER, 5)
        vbox.Add(self.imageView, 1, wx.ALL | wx.EXPAND, 5)
        vbox.Add(self.resultLabel, 0, wx.ALL | wx.CENTER, 5)
        vbox.Add(self.gauge, 0, wx.ALL | wx.EXPAND, 5)
        vbox.Add(self.autoCheckButton, 0, wx.ALL | wx.EXPAND, 5)
        self.panel.SetSizer(vbox)

        self.Layout()

        self.connectButton.Bind(wx.EVT_BUTTON, self.onConnectButtonClicked)
        self.settingsButton.Bind(wx.EVT_BUTTON, self.onSettingsButtonClicked)
        self.autoCheckButton.Bind(wx.EVT_BUTTON, self.onAutoCheckButtonClicked)
        self.Bind(wx.EVT_SHOW, self.onShow)

        self.videoView.setMilliseconds(50)
        self.videoView.setCallback(self.getDetectChessboardFrame)
        self.updateStatus(self.driver.isConnected)

    def onShow(self, event):
        if event.GetShow():
            self.updateStatus(self.driver.isConnected)
        else:
            try:
                self.videoView.stop()
            except:
                pass

    def getFrame(self):
        return self.driver.camera.captureImage()

    def getDetectChessboardFrame(self):
        frame = self.getFrame()
        if frame is not None:
            retval, frame = self.cameraIntrinsics.detectChessboard(frame)
        return frame

    def onUnplugged(self):
        self.videoView.stop()
        self.autoCheck.cancel()
        self.afterMoveMotor()

    def onConnectButtonClicked(self, event):
        self.driver.setCallbacks(self.beforeConnect,
                                 lambda r: wx.CallAfter(self.afterConnect, r))
        self.driver.connect()

    def onSettingsButtonClicked(self, event):
        SettingsWindow(self)

    def beforeConnect(self):
        self.settingsButton.Disable()
        self.breadcrumbs.Disable()
        self.connectButton.Disable()
        self.prevButton.Disable()
        self.videoView.stop()
        self.driver.board.setUnplugCallback(None)
        self.driver.camera.setUnplugCallback(None)
        self.waitCursor = wx.BusyCursor()

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

        if not ret:
            if result is Error.WrongFirmware:
                dlg = wx.MessageDialog(
                    self,
                    _("Board has a wrong firmware.\nPlease select your Board\nand press Upload Firmware"
                      ), _(result), wx.OK | wx.ICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
                self.updateStatus(False)
                self.GetParent().parent.onPreferences(None)
            elif result is Error.BoardNotConnected:
                dlg = wx.MessageDialog(
                    self,
                    _("Board is not connected.\nPlease connect your board\nand select a valid Serial Name"
                      ), _(result), wx.OK | wx.ICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
                self.updateStatus(False)
                self.GetParent().parent.onPreferences(None)
            elif result is Error.CameraNotConnected:
                dlg = wx.MessageDialog(
                    self,
                    _("Please plug your camera and try to connect again"),
                    _(result), wx.OK | wx.ICON_ERROR)
                dlg.ShowModal()
                dlg.Destroy()
            elif result is Error.WrongCamera:
                dlg = wx.MessageDialog(
                    self,
                    _("You probably have selected a wrong camera.\nPlease select other Camera Id"
                      ), _(result), wx.OK | wx.ICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
                self.updateStatus(False)
                self.GetParent().parent.onPreferences(None)
            elif result is Error.InvalidVideo:
                dlg = wx.MessageDialog(
                    self,
                    _("Unplug and plug your camera USB cable and try to connect again."
                      ), _(result), wx.OK | wx.ICON_ERROR)
                dlg.ShowModal()
                dlg.Destroy()

        self.updateStatus(self.driver.isConnected)
        self.settingsButton.Enable()
        self.breadcrumbs.Enable()
        self.prevButton.Enable()
        del self.waitCursor

    def onAutoCheckButtonClicked(self, event):
        if profile.getProfileSettingBool('adjust_laser'):
            profile.putProfileSetting('adjust_laser', False)
            dlg = wx.MessageDialog(
                self,
                _("It is recomended to adjust line lasers vertically.\nYou need to use the allen wrench.\nDo 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:
                self.driver.board.setLeftLaserOn()
                self.driver.board.setRightLaserOn()
        else:
            self.beforeAutoCheck()

            #-- Perform auto check
            self.autoCheck.setCallbacks(
                None, lambda p: wx.CallAfter(self.progressAutoCheck, p),
                lambda r: wx.CallAfter(self.afterAutoCheck, r))
            self.autoCheck.start()

    def beforeAutoCheck(self):
        self.settingsButton.Disable()
        self.breadcrumbs.Disable()
        self.autoCheckButton.Disable()
        self.prevButton.Disable()
        self.skipButton.Disable()
        self.nextButton.Disable()
        self.enableNext = False
        self.gauge.SetValue(0)
        self.resultLabel.Hide()
        self.gauge.Show()
        self.waitCursor = wx.BusyCursor()
        self.Layout()

    def progressAutoCheck(self, progress):
        self.gauge.SetValue(0.9 * progress)

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

        if ret:
            self.resultLabel.SetLabel(
                _("All OK. Please press next to continue"))
        else:
            self.resultLabel.SetLabel(
                _("Please check motor direction and pattern position and try again"
                  ))

        if ret:
            self.skipButton.Disable()
            self.nextButton.Enable()
        else:
            self.skipButton.Enable()
            self.nextButton.Disable()

        self.videoView.setMilliseconds(20)
        self.videoView.setCallback(self.getFrame)

        self.driver.board.setSpeedMotor(150)
        self.driver.board.setRelativePosition(-90)
        self.driver.board.enableMotor()
        self.driver.board.moveMotor(
            nonblocking=True,
            callback=(lambda r: wx.CallAfter(self.afterMoveMotor)))

    def afterMoveMotor(self):
        self.videoView.setMilliseconds(50)
        self.videoView.setCallback(self.getDetectChessboardFrame)
        self.settingsButton.Enable()
        self.breadcrumbs.Enable()
        self.gauge.SetValue(100)
        self.enableNext = True
        self.resultLabel.Show()
        self.autoCheckButton.Enable()
        self.prevButton.Enable()
        self.driver.board.disableMotor()
        self.gauge.Hide()
        if hasattr(self, 'waitCursor'):
            del self.waitCursor
        self.panel.Fit()
        self.panel.Layout()
        self.Layout()

    def updateStatus(self, status):
        if status:
            self.driver.board.setUnplugCallback(
                lambda: wx.CallAfter(self.parent.onBoardUnplugged))
            self.driver.camera.setUnplugCallback(
                lambda: wx.CallAfter(self.parent.onCameraUnplugged))
            #if profile.getPreference('workbench') != 'Calibration workbench':
            profile.putPreference('workbench', 'Calibration workbench')
            self.GetParent().parent.workbenchUpdate(False)
            self.videoView.play()
            self.connectButton.Disable()
            self.autoCheckButton.Enable()
            self.patternLabel.Enable()
            self.imageView.Enable()
            self.skipButton.Enable()
            self.enableNext = True
            self.driver.board.setLeftLaserOff()
            self.driver.board.setRightLaserOff()
        else:
            self.videoView.stop()
            self.gauge.SetValue(0)
            self.gauge.Show()
            self.resultLabel.Hide()
            self.resultLabel.SetLabel("")
            self.connectButton.Enable()
            self.skipButton.Disable()
            self.nextButton.Disable()
            self.enableNext = False
            self.autoCheckButton.Disable()
        self.Layout()
Esempio n. 15
0
class CalibrationPage(WizardPage):
	def __init__(self, parent, buttonPrevCallback=None, buttonNextCallback=None):
		WizardPage.__init__(self, parent,
							title=_("Calibration"),
							buttonPrevCallback=buttonPrevCallback,
							buttonNextCallback=buttonNextCallback)

		self.driver = Driver.Instance()
		self.cameraIntrinsics = calibration.CameraIntrinsics.Instance()
		self.laserTriangulation = calibration.LaserTriangulation.Instance()
		self.platformExtrinsics = calibration.PlatformExtrinsics.Instance()
		self.phase = 'none'

		self.patternLabel = wx.StaticText(self.panel, label=_("Put the pattern on the platform as shown in the picture and press \"Calibrate\""))
		self.patternLabel.Wrap(400)
		self.imageView = ImageView(self.panel)
		self.imageView.setImage(wx.Image(resources.getPathForImage("pattern-position-right.jpg")))
		self.calibrateButton = wx.Button(self.panel, label=_("Calibrate"))
		self.cancelButton = wx.Button(self.panel, label=_("Cancel"))
		self.gauge = wx.Gauge(self.panel, range=100, size=(-1, 30))
		self.resultLabel = wx.StaticText(self.panel, size=(-1, 30))

		self.cancelButton.Disable()
		self.resultLabel.Hide()
		self.skipButton.Enable()
		self.nextButton.Disable()

		#-- Layout
		vbox = wx.BoxSizer(wx.VERTICAL)
		vbox.Add(self.patternLabel, 0, wx.ALL|wx.CENTER, 5)
		vbox.Add(self.imageView, 1, wx.ALL|wx.EXPAND, 5)
		vbox.Add(self.resultLabel, 0, wx.ALL|wx.CENTER, 5)
		vbox.Add(self.gauge, 0, wx.ALL|wx.EXPAND, 5)
		hbox = wx.BoxSizer(wx.HORIZONTAL)
		hbox.Add(self.cancelButton, 1, wx.ALL|wx.EXPAND, 5)
		hbox.Add(self.calibrateButton, 1, wx.ALL|wx.EXPAND, 5)
		vbox.Add(hbox, 0, wx.ALL|wx.EXPAND, 2)
		self.panel.SetSizer(vbox)

		self.Layout()

		self.calibrateButton.Bind(wx.EVT_BUTTON, self.onCalibrationButtonClicked)
		self.cancelButton.Bind(wx.EVT_BUTTON, self.onCancelButtonClicked)
		self.Bind(wx.EVT_SHOW, self.onShow)

		self.videoView.setMilliseconds(20)
		self.videoView.setCallback(self.getFrame)


	def onShow(self, event):
		if event.GetShow():
			self.updateStatus(self.driver.isConnected)
		else:
			try:
				self.videoView.stop()
			except:
				pass

	def getFrame(self):
		if self.phase is 'platformCalibration':
			frame = self.platformExtrinsics.getImage()
		elif self.phase is 'laserTriangulation':
			frame = self.laserTriangulation.getImage()
		else: # 'none'
			frame = self.driver.camera.captureImage()

		if frame is not None and self.phase is not 'laserTriangulation':
			retval, frame = self.cameraIntrinsics.detectChessboard(frame)

		return frame

	def onUnplugged(self):
		self.videoView.stop()
		self.laserTriangulation.cancel()
		self.platformExtrinsics.cancel()
		self.enableNext = True

	def onCalibrationButtonClicked(self, event):
		self.phase = 'laserTriangulation'
		self.laserTriangulation.setCallbacks(self.beforeCalibration,
											 lambda p: wx.CallAfter(self.progressLaserCalibration,p),
											 lambda r: wx.CallAfter(self.afterLaserCalibration,r))
		if profile.getProfileSettingFloat('pattern_distance') == 0:
			PatternDistanceWindow(self)
		else:
			self.laserTriangulation.start()

	def onCancelButtonClicked(self, event):
		boardUnplugCallback = self.driver.board.unplugCallback
		cameraUnplugCallback = self.driver.camera.unplugCallback
		self.driver.board.setUnplugCallback(None)
		self.driver.camera.setUnplugCallback(None)
		self.phase = 'none'
		self.resultLabel.SetLabel(_("Calibration canceled. To try again press \"Calibrate\""))
		self.platformExtrinsics.cancel()
		self.laserTriangulation.cancel()
		self.skipButton.Enable()
		self.onFinishCalibration()
		self.driver.board.setUnplugCallback(boardUnplugCallback)
		self.driver.camera.setUnplugCallback(cameraUnplugCallback)

	def beforeCalibration(self):
		self.calibrateButton.Disable()
		self.cancelButton.Enable()
		self.prevButton.Disable()
		self.skipButton.Disable()
		self.nextButton.Disable()
		self.enableNext = False
		self.gauge.SetValue(0)
		self.resultLabel.Hide()
		self.gauge.Show()
		self.Layout()
		self.waitCursor = wx.BusyCursor()

	def progressLaserCalibration(self, progress):
		self.gauge.SetValue(progress*0.6)

	def afterLaserCalibration(self, response):
		self.phase='platformCalibration'
		ret, result = response

		if ret:
			profile.putProfileSetting('distance_left', result[0][0])
			profile.putProfileSettingNumpy('normal_left', result[0][1])
			profile.putProfileSetting('distance_right', result[1][0])
			profile.putProfileSettingNumpy('normal_right', result[1][1])
			self.platformExtrinsics.setCallbacks(None,
												 lambda p: wx.CallAfter(self.progressPlatformCalibration,p),
												 lambda r: wx.CallAfter(self.afterPlatformCalibration,r))
			self.platformExtrinsics.start()
		else:
			if result == Error.CalibrationError:
				self.resultLabel.SetLabel(_("Error in lasers: please connect the lasers and try again"))
				dlg = wx.MessageDialog(self, _("Laser Calibration failed. Please try again"), _(result), wx.OK|wx.ICON_ERROR)
				dlg.ShowModal()
				dlg.Destroy()
				self.skipButton.Enable()
				self.onFinishCalibration()

	def progressPlatformCalibration(self, progress):
		self.gauge.SetValue(60 + progress*0.4)	

	def afterPlatformCalibration(self, response):
		self.phase = 'none'
		ret, result = response
		
		if ret:
			profile.putProfileSettingNumpy('rotation_matrix', result[0])
			profile.putProfileSettingNumpy('translation_vector', result[1])
		else:
			if result == Error.CalibrationError:
				self.resultLabel.SetLabel(_("Error in pattern: please check the pattern and try again"))
				dlg = wx.MessageDialog(self, _("Platform Calibration failed. Please try again"), _(result), wx.OK|wx.ICON_ERROR)
				dlg.ShowModal()
				dlg.Destroy()

		if ret:
			self.skipButton.Disable()
			self.nextButton.Enable()
			self.resultLabel.SetLabel(_("All OK. Please press next to continue"))
		else:
			self.skipButton.Enable()
			self.nextButton.Disable()

		self.onFinishCalibration()

	def onFinishCalibration(self):
		self.enableNext = True
		self.gauge.Hide()
		self.resultLabel.Show()
		self.calibrateButton.Enable()
		self.cancelButton.Disable()
		self.prevButton.Enable()
		self.panel.Fit()
		self.panel.Layout()
		self.Layout()
		if hasattr(self, 'waitCursor'):
			del self.waitCursor

	def updateStatus(self, status):
		if status:
			if profile.getPreference('workbench') != 'Calibration workbench':
				profile.putPreference('workbench', 'Calibration workbench')
				self.GetParent().parent.workbenchUpdate(False)
			self.videoView.play()
			self.calibrateButton.Enable()
			self.skipButton.Enable()
			self.driver.board.setLeftLaserOff()
			self.driver.board.setRightLaserOff()
		else:
			self.videoView.stop()
			self.gauge.SetValue(0)
			self.gauge.Show()
			self.prevButton.Enable()
			self.skipButton.Disable()
			self.nextButton.Disable()
			self.calibrateButton.Disable()
			self.cancelButton.Disable()