Example #1
0
class Vision(Page):
    def __init__(self, builder, config):
        super(Vision, self).__init__(builder, config)
        self.update = False
        self.left_image = None
        self.right_image = None

        self.left_view = VideoView('Left Camera')
        self.right_view = VideoView('Right Camera')
        self.depth_view = VideoView('Depth View')

        self.rectify_check = self.builder.get_object('rectify_check')

        self.notebook = self.builder.get_object('stereo_notebook')

    def on_prepare(self):
        self.camera = StereoCamera(self.config.camera.left_id,
                                   self.config.camera.right_id,
                                   self.config.camera.width,
                                   self.config.camera.height)

        for view in (self.left_view, self.right_view, self.depth_view):
            view.set_default_size(self.camera.width, self.camera.height)
            view.show_all()

        self.left_maps = cv2.initUndistortRectifyMap(
            self.config.camera.left_intrinsics,
            self.config.camera.left_distortion, self.config.camera.R1,
            self.config.camera.P1, self.camera.size, cv2.CV_16SC2)

        self.right_maps = cv2.initUndistortRectifyMap(
            self.config.camera.right_intrinsics,
            self.config.camera.right_distortion, self.config.camera.R2,
            self.config.camera.P2, self.camera.size, cv2.CV_16SC2)

        self.update = True
        GLib.idle_add(self.on_update)

    def on_cleanup(self):
        self.update = False
        self.left_view.hide()
        self.right_view.hide()
        self.depth_view.hide()

        self.camera.release()
        self.camera = None

    def on_update(self):
        if not self.update:
            return False

        self.camera.grab()
        left_image, right_image = self.camera.retrieve()

        if self.rectify_check.get_active():
            left_image = cv2.remap(left_image, self.left_maps[0],
                                   self.left_maps[1], cv2.INTER_LINEAR)
            right_image = cv2.remap(right_image, self.right_maps[0],
                                    self.right_maps[1], cv2.INTER_LINEAR)

        if self.notebook.get_current_page() == 0:
            disparity_image = vision.stereobm(self.config, left_image,
                                              right_image)
        elif self.notebook.get_current_page() == 1:
            disparity_image = vision.stereosgbm(self.config, left_image,
                                                right_image)
        elif self.notebook.get_current_page() == 2:
            disparity_image = vision.stereovar(self.config, left_image,
                                               right_image)

        # Redraw the windows
        self.left_view.update(left_image)
        self.right_view.update(right_image)
        self.depth_view.update_depth(disparity_image)

        return True
Example #2
0
class Vision(Page):
    def __init__(self, builder, config):
        super(Vision, self).__init__(builder, config)
        self.update = False
        self.left_image = None
        self.right_image = None

        self.left_view = VideoView('Left Camera')
        self.right_view = VideoView('Right Camera')
        self.depth_view = VideoView('Depth View')

        self.rectify_check = self.builder.get_object(
                'rectify_check')

        self.notebook = self.builder.get_object('stereo_notebook')

    def on_prepare(self):
        self.camera = StereoCamera(self.config.camera.left_id,
                                   self.config.camera.right_id,
                                   self.config.camera.width,
                                   self.config.camera.height)

        for view in (self.left_view, self.right_view, self.depth_view):
            view.set_default_size(self.camera.width,
                                  self.camera.height)
            view.show_all()

        self.left_maps = cv2.initUndistortRectifyMap(
            self.config.camera.left_intrinsics,
            self.config.camera.left_distortion,
            self.config.camera.R1, self.config.camera.P1,
            self.camera.size, cv2.CV_16SC2)

        self.right_maps = cv2.initUndistortRectifyMap(
                self.config.camera.right_intrinsics,
                self.config.camera.right_distortion,
                self.config.camera.R2, self.config.camera.P2,
                self.camera.size, cv2.CV_16SC2)

        self.update = True
        GLib.idle_add(self.on_update)

    def on_cleanup(self):
        self.update = False
        self.left_view.hide()
        self.right_view.hide()
        self.depth_view.hide()

        self.camera.release()
        self.camera = None

    def on_update(self):
        if not self.update:
            return False

        self.camera.grab()
        left_image, right_image = self.camera.retrieve()

        if self.rectify_check.get_active():
            left_image = cv2.remap(left_image, self.left_maps[0],
                                   self.left_maps[1], cv2.INTER_LINEAR)
            right_image = cv2.remap(right_image, self.right_maps[0],
                                    self.right_maps[1], cv2.INTER_LINEAR)

        if self.notebook.get_current_page() == 0:
            disparity_image = vision.stereobm(self.config,
                                              left_image, right_image)
        elif self.notebook.get_current_page() == 1:
            disparity_image = vision.stereosgbm(self.config,
                                                left_image, right_image)
        elif self.notebook.get_current_page() == 2:
            disparity_image = vision.stereovar(self.config,
                                               left_image, right_image)

        # Redraw the windows
        self.left_view.update(left_image)
        self.right_view.update(right_image)
        self.depth_view.update_depth(disparity_image)

        return True
Example #3
0
class Capture(Page):
    def __init__(self, builder, config):
        super(Capture, self).__init__(builder, config)
        self.update = False
        self.left_image = None
        self.right_image = None

        self.left_view = VideoView('Left Camera')
        self.right_view = VideoView('Right Camera')

        self.count_entry = self.builder.get_object('snap_count_entry')

        self.builder.get_object('snap_button').connect('clicked', self.on_snap)
        self.builder.get_object('save_points_button').connect(
            'clicked', self.on_save)

    def on_prepare(self):
        self.camera = StereoCamera(self.config.camera.left_id,
                                   self.config.camera.right_id,
                                   self.config.camera.width,
                                   self.config.camera.height)

        self.count_entry.set_text('0')

        for view in (self.left_view, self.right_view):
            view.set_default_size(self.config.camera.width,
                                  self.config.camera.height)
            view.show_all()

        self.update = True
        GLib.idle_add(self.on_update)

    def on_cleanup(self):
        self.update = False
        self.left_view.hide()
        self.right_view.hide()

        self.camera.release()
        self.camera = None

    def on_update(self):
        if not self.update:
            return False

        self.camera.grab()
        self.left_image, self.right_image = self.camera.retrieve()

        self.left_points = vision.find_points(self.config, self.left_image)
        self.right_points = vision.find_points(self.config, self.right_image)

        # Redraw the windows
        self.left_view.update(self.left_image)
        self.right_view.update(self.right_image)

        return True

    def on_snap(self, button):
        if None in (self.left_points, self.right_points):
            return

        self.config.calibration.append_point(
            vision.get_pattern_points(self.config), self.left_points,
            self.right_points)
        self.count_entry.set_text(str(self.config.calibration.len_points()))

    def on_save(self, button):
        file_name = self._do_save_dialog('Save captured points as...',
                                         'points.json')
        if file_name is not None:
            self.config.save_points(file_name)
Example #4
0
class Capture(Page):
    def __init__(self, builder, config):
        super(Capture, self).__init__(builder, config)
        self.update = False
        self.left_image = None
        self.right_image = None

        self.left_view = VideoView('Left Camera')
        self.right_view = VideoView('Right Camera')

        self.count_entry = self.builder.get_object('snap_count_entry')

        self.builder.get_object('snap_button').connect('clicked', self.on_snap)
        self.builder.get_object('save_points_button').connect('clicked',
                                self.on_save)

    def on_prepare(self):
        self.camera = StereoCamera(self.config.camera.left_id,
                                    self.config.camera.right_id,
                                    self.config.camera.width,
                                    self.config.camera.height)

        self.count_entry.set_text('0')

        for view in (self.left_view, self.right_view):
            view.set_default_size(self.config.camera.width,
                                  self.config.camera.height)
            view.show_all()

        self.update = True
        GLib.idle_add(self.on_update)

    def on_cleanup(self):
        self.update = False
        self.left_view.hide()
        self.right_view.hide()

        self.camera.release()
        self.camera = None

    def on_update(self):
        if not self.update:
            return False

        self.camera.grab()
        self.left_image, self.right_image = self.camera.retrieve()

        self.left_points = vision.find_points(self.config, self.left_image)
        self.right_points = vision.find_points(self.config, self.right_image)

        # Redraw the windows
        self.left_view.update(self.left_image)
        self.right_view.update(self.right_image)

        return True

    def on_snap(self, button):
        if None in (self.left_points, self.right_points):
            return

        self.config.calibration.append_point(
                vision.get_pattern_points(self.config),
                self.left_points, self.right_points)
        self.count_entry.set_text(str(self.config.calibration.len_points()))

    def on_save(self, button):
        file_name = self._do_save_dialog('Save captured points as...',
                                         'points.json')
        if file_name is not None:
            self.config.save_points(file_name)