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()