class ViewPage(wx.SplitterWindow): def __init__(self, parent, get_image): wx.SplitterWindow.__init__(self, parent, style=wx.SP_3D) # | wx.SP_LIVE_UPDATE) self.get_image = get_image self.video_view = VideoView(self, get_image) self.scene_panel = wx.Panel(self) self.scene_view = SceneView(self.scene_panel) self.gauge = wx.Gauge(self.scene_panel, size=(-1, 30)) self.gauge.Hide() # Layout vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(self.scene_view, 1, wx.ALL | wx.EXPAND, 0) vbox.Add(self.gauge, 0, wx.ALL | wx.EXPAND, 0) self.scene_panel.SetSizer(vbox) self.SplitVertically(self.video_view, self.scene_panel) self.SetMinimumPaneSize(200) # Video view selector _choices = [] choices = profile.settings.get_possible_values('video_scanning') for i in choices: _choices.append(_(i)) self.video_views_dict = dict(list(zip(_choices, choices))) self.combo_video_views = wx.ComboBox(self.video_view, value=_('Texture'), choices=_choices, style=wx.CB_READONLY, size=(100, -1), pos=(0, -1)) self.combo_video_views.Hide() self.combo_video_views.Bind(wx.EVT_COMBOBOX, self.on_combo_box_video_views_select) # Events self.video_view.Bind(wx.EVT_SHOW, self.on_show) def on_show(self, event): # if event.GetShow(): if event.IsShown(): if driver.is_connected and profile.settings[ 'workbench'] == 'scanning': self.video_view.play() else: try: self.video_view.stop() except: pass def on_combo_box_video_views_select(self, event): value = self.video_views_dict[self.combo_video_views.GetValue()] current_video.mode = value profile.settings['video_scanning'] = value
class VideoPage(Page): 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() def initialize(self): self.gauge.SetValue(0) self.right_button.Enable() def play(self): self.video_view.play() self.GetParent().Layout() self.Layout() def stop(self): self.initialize() self.video_view.stop() def reset(self): self.video_view.reset() def get_image(self): if scanner_autocheck.image is not None: image = scanner_autocheck.image elif laser_triangulation.image is not None: image = laser_triangulation.image elif platform_extrinsics.image is not None: image = platform_extrinsics.image else: image = image_capture.capture_pattern() image = image_detection.detect_pattern(image) return image
class CapturePage(Page): 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) def initialize(self): self.desc_text.SetLabel( _("Default values are recommended. To perform the calibration, " "click over the video panel and press " "space bar to perform the captures.")) self.current_grid = 0 self.gauge.SetValue(0) camera_intrinsics.reset() for panel in xrange(self.rows * self.columns): self.panel_grid[panel].SetBackgroundColour((221, 221, 221)) self.panel_grid[panel].set_image(wx.Image(resources.get_path_for_image("void.png"))) def play(self): self.gauge.SetValue(0) self.video_view.play() self.image_grid_panel.SetFocus() self.GetParent().Layout() self.Layout() def stop(self): self.initialize() self.video_view.stop() def reset(self): self.video_view.reset() def get_image(self): image = image_capture.capture_pattern() chessboard = image_detection.detect_pattern(image) return chessboard def on_key_press(self, event): if event.GetKeyCode() == 32: # spacebar self.video_view.stop() image = camera_intrinsics.capture() if image is not None: self.add_frame_to_grid(image) if self.current_grid <= self.rows * self.columns: self.gauge.SetValue(self.current_grid * 100.0 / self.rows / self.columns) self.video_view.play() def add_frame_to_grid(self, image): if self.current_grid < (self.columns * self.rows): self.panel_grid[self.current_grid].set_frame(image) self.current_grid += 1 if self.current_grid is (self.columns * self.rows): self.desc_text.SetLabel(_("Press space bar to continue")) if self.button_right_callback is not None: self.button_right_callback()