Exemplo n.º 1
0
    def __init__(self, directory='NewTsukubaStereoDataset/', 
                 left_template='illumination/daylight/left/tsukuba_daylight_L_%05i.png', 
                 right_template='illumination/daylight/right/tsukuba_daylight_R_%05i.png', 
                 start_idx=1, max_files=50000, scale=1.0, grayscale=False): 

        # Minor dataset related check
        if start_idx < 1: 
            raise RuntimeError('TsukubaStereo2012Reader has to start at index 1')

        # Set args
        self.scale = scale

        # Get calib
        self.calib = TsukubaStereo2012Reader.calib.scaled(scale)

        # Read poses
        try: 
            pose_fn = os.path.join(os.path.expanduser(directory), 'groundtruth/camera_track.txt')
            self.poses = FileReader(pose_fn, start_idx=start_idx, process_cb=tsukuba_load_poses)                    
        except Exception as e: 
            self.poses = repeat(None)
            raise RuntimeError('Failed to load poses properly, cannot proceed {:}'.format(e))

        # Read stereo images
        self.stereo = StereoDatasetReader(directory=directory,
                                          left_template=left_template, 
                                          right_template=right_template, 
                                          start_idx=start_idx, max_files=max_files, scale=scale, grayscale=grayscale)
        print 'Initialized stereo dataset reader with %f scale' % scale
        gt_fn = os.path.join(os.path.expanduser(directory),
                             'groundtruth/disparity_maps/left/tsukuba_disparity_L_%05i.png')
        self.gt = DatasetReader(process_cb=TsukubaStereo2012Reader.dispread_process_cb(scale=scale), template=gt_fn, 
                                start_idx=start_idx, max_files=max_files)
Exemplo n.º 2
0
    def __init__(self, directory, 
                 sequence='',
                 left_template='image_00/data/%010i.png', 
                 right_template='image_01/data/%010i.png', 
                 velodyne_template='velodyne_points/data/%010i.bin', 
                 oxt_template='oxts/data/%010i.txt',
                 start_idx=0, max_files=50000, scale=1.0): 
        super(KITTIRawDatasetReader, self).__init__(directory, sequence, 
                                                    left_template=left_template, right_template=right_template, 
                                                    velodyne_template=velodyne_template, 
                                                    start_idx=start_idx, max_files=max_files, scale=scale)

        # Read stereo images
        self.stereo = StereoDatasetReader(directory=directory, 
                                          left_template=left_template, 
                                          right_template=right_template, 
                                          start_idx=start_idx, max_files=max_files, scale=scale)

        # Read poses
        try: 
            pose_fn = os.path.join(os.path.expanduser(directory), 'poses', ''.join([sequence, '.txt']))
            self.poses = FileReader(pose_fn, process_cb=kitti_load_poses)
        except: 
            self.poses = repeat(None)
            
        # Read velodyne
        self.velodyne = VelodyneDatasetReader(
            template=os.path.join(directory,velodyne_template), 
            start_idx=start_idx, max_files=max_files
        )

        # Read oxts
        def kitti_load_oxts(fn): 
            return (np.fromfile(fn, dtype=np.float64, sep=' '))
            
        try: 
            oxt_format_fn = os.path.join(os.path.expanduser(directory), 'oxts/dataformat.txt')
            self.oxt_formats = [line.split(':')[0] for line in open(oxt_format_fn)]
            
            oxt_fn = os.path.join(os.path.expanduser(directory), oxt_template)
            self.oxts = DatasetReader(template=oxt_fn, process_cb=lambda fn: kitti_load_oxts(fn), 
                                      start_idx=start_idx, max_files=max_files)
        except Exception as e:
            self.oxts = repeat(None)
Exemplo n.º 3
0
    def __init__(self,
                 directory='',
                 template='data/img/img%04i_0.png',
                 velodyne_template=None,
                 start_idx=1,
                 max_files=100000,
                 scale=1.0):

        # Set args
        self.scale = scale

        # Calibration
        try:
            calib_fn = os.path.join(os.path.expanduser(directory), 'info',
                                    'intrinsics.txt')
            s = open(calib_fn, 'r').readlines()
            s = ''.join(s[1:])
            for item in ['\n', '[', ']', ' ']:
                s = s.replace(item, '')
            K = np.fromstring(s, sep=',').reshape(3, 3)
            self.calib_ = Camera.from_intrinsics(
                CameraIntrinsic(K, shape=RPGUrban.shape[:2])).scaled(scale)
        except Exception as e:
            print('Failed to read calibration data: {}'.format(e))
            self.calib_ = None

        # Read stereo images
        try:
            self.rgb_ = ImageDatasetReader(template=os.path.join(
                os.path.expanduser(directory), template),
                                           start_idx=start_idx,
                                           max_files=max_files,
                                           scale=scale)
        except Exception as e:
            print('Failed to read rgb data: {}'.format(e))
            self.rgb_ = NoneReader()

        # Read poses
        def load_poses(fn):
            """
            poses: image_id tx ty tz qx qy qz qw
            """
            X = (np.fromfile(fn, dtype=np.float64, sep=' ')).reshape(-1, 8)
            abs_poses = map(lambda p: RigidTransform(xyzw=p[4:], tvec=p[1:4]),
                            X)
            rel_poses = [abs_poses[0].inverse() * p for p in abs_poses]
            return rel_poses

        try:
            pose_fn = os.path.join(os.path.expanduser(directory), 'info',
                                   'groundtruth.txt')
            self.poses_ = FileReader(pose_fn, process_cb=load_poses)
        except Exception as e:
            self.poses_ = NoneReader()
Exemplo n.º 4
0
    def __init__(self, directory='', 
                 sequence='', 
                 left_template='image_0/%06i.png', 
                 right_template='image_1/%06i.png', 
                 velodyne_template='velodyne/%06i.bin',
                 start_idx=0, max_files=50000, scale=1.0): 

        # Set args
        self.sequence = sequence
        self.scale = scale

        # Get calib
        self.calib = kitti_stereo_calib(sequence, scale=scale)

        # Read stereo images
        seq_directory = os.path.join(os.path.expanduser(directory), 'sequences', sequence)
        self.stereo = StereoDatasetReader(directory=seq_directory, 
                                          left_template=os.path.join(seq_directory,left_template), 
                                          right_template=os.path.join(seq_directory,right_template), 
                                          start_idx=start_idx, max_files=max_files, scale=scale)

        # Read poses
        try: 
            pose_fn = os.path.join(os.path.expanduser(directory), 'poses', ''.join([sequence, '.txt']))
            self.poses = FileReader(pose_fn, process_cb=kitti_load_poses)
        except Exception as e:
            self.poses = repeat(None)

        try: 
            # Read velodyne
            self.velodyne = VelodyneDatasetReader(
                template=os.path.join(seq_directory,velodyne_template), 
                start_idx=start_idx, max_files=max_files
            )
        except Exception as e: 
            self.velodyne = repeat(None)

        print 'Initialized stereo dataset reader with %f scale' % scale
Exemplo n.º 5
0
    def __init__(self, directory='',
                 sequence='',
                 left_template='image_0/%06i.png',
                 right_template='image_1/%06i.png',
                 velodyne_template='velodyne/%06i.bin',
                 start_idx=0, max_files=100000, scale=1.0):

        # Set args
        self.sequence = sequence
        self.scale = scale

        # Get calib
        try:
            self.calib = kitti_stereo_calib(sequence, scale=scale)
        except Exception as e:
            self.calib = None

        # Read stereo images
        seq_directory = os.path.join(os.path.expanduser(directory),
                                     'sequences', sequence)
        self.stereo = StereoDatasetReader(
            directory=seq_directory,
            left_template=os.path.join(seq_directory,left_template),
            right_template=os.path.join(seq_directory,right_template),
            start_idx=start_idx, max_files=max_files, scale=scale)
        print('Initialized stereo dataset reader with %f scale' % scale)

        # Read poses
        try:
            pose_fn = os.path.join(
                os.path.expanduser(directory),
                'poses', ''.join([sequence, '.txt']))
            self.poses_ = FileReader(pose_fn, process_cb=kitti_load_poses)
        except Exception as e:
            print('Failed to read pose data: {}'.format(e))
            self.poses_ = NoneReader()

        # Read velodyne
        if velodyne_template is None:
            self.velodyne = NoneReader()
            print('Skipping velodyne data')
        else:
            try:
                self.velodyne = VelodyneDatasetReader(
                    template=os.path.join(seq_directory,velodyne_template),
                    start_idx=start_idx, max_files=max_files
                )
            except Exception as e:
                print('Failed to read velodyne data: {}'.format(e))
                self.velodyne = NoneReader()
Exemplo n.º 6
0
class TsukubaStereo2012Reader(object): 
    """
    TsukubaStereo2012Reader: StereoDatasetReader + Calib

    The resolution of the images is 640x480 pixels, the baseline of the stereo 
    camera is 10cm and the focal length of the camera is 615 pixels.

    https://github.com/pablospe/tsukuba_db/blob/master/README.Tsukuba

    """
    calib = StereoCamera.from_calib_params(615, 615, 319.5, 239.5, 
                                           baseline=0.10, shape=np.int32([480, 640]))



    def __init__(self, directory='NewTsukubaStereoDataset/', 
                 left_template='illumination/daylight/left/tsukuba_daylight_L_%05i.png', 
                 right_template='illumination/daylight/right/tsukuba_daylight_R_%05i.png', 
                 start_idx=1, max_files=50000, scale=1.0, grayscale=False): 

        # Minor dataset related check
        if start_idx < 1: 
            raise RuntimeError('TsukubaStereo2012Reader has to start at index 1')

        # Set args
        self.scale = scale

        # Get calib
        self.calib = TsukubaStereo2012Reader.calib.scaled(scale)

        # Read poses
        try: 
            pose_fn = os.path.join(os.path.expanduser(directory), 'groundtruth/camera_track.txt')
            self.poses = FileReader(pose_fn, start_idx=start_idx, process_cb=tsukuba_load_poses)                    
        except Exception as e: 
            self.poses = repeat(None)
            raise RuntimeError('Failed to load poses properly, cannot proceed {:}'.format(e))

        # Read stereo images
        self.stereo = StereoDatasetReader(directory=directory,
                                          left_template=left_template, 
                                          right_template=right_template, 
                                          start_idx=start_idx, max_files=max_files, scale=scale, grayscale=grayscale)
        print 'Initialized stereo dataset reader with %f scale' % scale
        gt_fn = os.path.join(os.path.expanduser(directory),
                             'groundtruth/disparity_maps/left/tsukuba_disparity_L_%05i.png')
        self.gt = DatasetReader(process_cb=TsukubaStereo2012Reader.dispread_process_cb(scale=scale), template=gt_fn, 
                                start_idx=start_idx, max_files=max_files)
        
    @staticmethod
    def dispread_process_cb(scale=1.0):
        """Scale disparity values for depth images"""
        return lambda fn: im_resize(cv2.imread(fn, cv2.IMREAD_UNCHANGED), scale=scale) * scale


    def iterframes(self, *args, **kwargs): 
        for (left, right), pose in izip(self.iter_stereo_frames(*args, **kwargs), 
                                               self.poses.iteritems(*args, **kwargs)):
            yield AttrDict(left=left, right=right, pose=pose)

    def iter_gt_frames(self, *args, **kwargs): 
        for (left, right), pose, depth in izip(self.iter_stereo_frames(*args, **kwargs), 
                                               self.poses.iteritems(*args, **kwargs), 
                                               self.gt.iteritems(*args, **kwargs)): 
            yield AttrDict(left=left, right=right, pose=pose, depth=depth)

    def iter_stereo_frames(self, *args, **kwargs): 
        return self.stereo.iteritems(*args, **kwargs)

    @property
    def stereo_frames(self): 
        return self.iter_stereo_frames()

    def viz_gt_poses(self): 
        draw_utils.publish_pose_list('POSES', self.poses.items, frame_id='camera')
Exemplo n.º 7
0
class KITTIDatasetReader(object): 
    """
    KITTIDatasetReader: ImageDatasetReader + VelodyneDatasetReader + Calib
    http://www.cvlibs.net/datasets/kitti/setup.php
    """
    kitti_00_02 = StereoCamera.from_calib_params(718.86, 718.86, 607.19, 185.22, 
                                                 baseline_px=386.1448, shape=np.int32([376, 1241]))
    kitti_03 = StereoCamera.from_calib_params(721.5377, 721.5377, 609.5593, 172.854, 
                                                 baseline_px=387.5744, shape=np.int32([376, 1241]))
    kitti_04_12 = StereoCamera.from_calib_params(707.0912, 707.0912, 601.8873, 183.1104, 
                                                    baseline_px=379.8145, shape=np.int32([376, 1241]))
    baseline = 0.5371 # baseline_px / fx
    velo2cam = 0.27 # Velodyne is 27 cm behind cam_0 (x-forward, y-left, z-up)

    def __init__(self, directory='', 
                 sequence='', 
                 left_template='image_0/%06i.png', 
                 right_template='image_1/%06i.png', 
                 velodyne_template='velodyne/%06i.bin',
                 start_idx=0, max_files=50000, scale=1.0): 

        # Set args
        self.sequence = sequence
        self.scale = scale

        # Get calib
        self.calib = kitti_stereo_calib(sequence, scale=scale)

        # Read stereo images
        seq_directory = os.path.join(os.path.expanduser(directory), 'sequences', sequence)
        self.stereo = StereoDatasetReader(directory=seq_directory, 
                                          left_template=os.path.join(seq_directory,left_template), 
                                          right_template=os.path.join(seq_directory,right_template), 
                                          start_idx=start_idx, max_files=max_files, scale=scale)

        # Read poses
        try: 
            pose_fn = os.path.join(os.path.expanduser(directory), 'poses', ''.join([sequence, '.txt']))
            self.poses = FileReader(pose_fn, process_cb=kitti_load_poses)
        except Exception as e:
            self.poses = repeat(None)

        try: 
            # Read velodyne
            self.velodyne = VelodyneDatasetReader(
                template=os.path.join(seq_directory,velodyne_template), 
                start_idx=start_idx, max_files=max_files
            )
        except Exception as e: 
            self.velodyne = repeat(None)

        print 'Initialized stereo dataset reader with %f scale' % scale

    def iteritems(self, *args, **kwargs): 
        return self.stereo.left.iteritems(*args, **kwargs)

    def iter_stereo_frames(self, *args, **kwargs): 
        return self.stereo.iteritems(*args, **kwargs)

    def iter_velodyne_frames(self, *args, **kwargs):         
        """
        for pc in dataset.iter_velodyne_frames(): 
          X = pc[:,:3]
        """
        return self.velodyne.iteritems(*args, **kwargs)

    def iter_stereo_velodyne_frames(self, *args, **kwargs):         
        return izip(self.left.iteritems(*args, **kwargs), 
                    self.right.iteritems(*args, **kwargs), 
                    self.velodyne.iteritems(*args, **kwargs))

    def iterframes(self, *args, **kwargs): 
        for (left, right), pose in izip(self.iter_stereo_frames(*args, **kwargs), self.poses.iteritems(*args, **kwargs)): 
            yield AttrDict(left=left, right=right, velodyne=None, pose=pose)

    def iter_gt_frames(self, *args, **kwargs): 
        for (left, right), pose in izip(self.iter_stereo_frames(*args, **kwargs), self.poses.iteritems(*args, **kwargs)): 
            yield AttrDict(left=left, right=right, velodyne=None, pose=pose)

    @property
    def stereo_frames(self): 
        return self.iter_stereo_frames()

    @property
    def velodyne_frames(self): 
        return self.iter_velodyne_frames()

    
    # @classmethod
    # def stereo_test_dataset(cls, directory, subdir, scale=1.0):
    #     """
    #     Ground truth dataset iterator
    #     """

    #     left_directory = os.path.join(os.path.expanduser(directory), '%s_0' % subdir)
    #     right_directory = os.path.join(os.path.expanduser(directory), '%s_1' % subdir)
    #     noc_directory = os.path.join(os.path.expanduser(directory), 'disp_noc')
    #     occ_directory = os.path.join(os.path.expanduser(directory), 'disp_occ')

    #     c = cls(sequence='00')
    #     c.scale = scale
    #     c.calib = kitti_stereo_calib(1, scale=scale)

    #     # Stereo is only evaluated on the _10.png images
    #     c.stereo = StereoDatasetReader.from_directory(left_directory, right_directory, pattern='*_10.png')
    #     c.noc = ImageDatasetReader.from_directory(noc_directory)
    #     c.occ = ImageDatasetReader.from_directory(occ_directory)
    #     c.poses = [None] * c.stereo.length

    #     return c

    @classmethod
    def iterscenes(cls, sequences, directory='', 
                   left_template='image_0/%06i.png', right_template='image_1/%06i.png', 
                   velodyne_template='velodyne/%06i.bin', start_idx=0, max_files=50000, 
                   scale=1.0, verbose=False): 
        
        for seq in progressbar(sequences, size=len(sequences), verbose=verbose): 
            yield seq, cls(
                directory=directory, sequence=seq, left_template=left_template, 
                right_template=right_template, velodyne_template=velodyne_template, 
                start_idx=start_idx, max_files=max_files)
Exemplo n.º 8
0
class KITTIRawDatasetReader(KITTIDatasetReader): 
    """
    KITTIRawDatasetReader: KITTIDatasetReader + OXTS reader
    """

    def __init__(self, directory, 
                 sequence='',
                 left_template='image_00/data/%010i.png', 
                 right_template='image_01/data/%010i.png', 
                 velodyne_template='velodyne_points/data/%010i.bin', 
                 oxt_template='oxts/data/%010i.txt',
                 start_idx=0, max_files=50000, scale=1.0): 
        super(KITTIRawDatasetReader, self).__init__(directory, sequence, 
                                                    left_template=left_template, right_template=right_template, 
                                                    velodyne_template=velodyne_template, 
                                                    start_idx=start_idx, max_files=max_files, scale=scale)

        # Read stereo images
        self.stereo = StereoDatasetReader(directory=directory, 
                                          left_template=left_template, 
                                          right_template=right_template, 
                                          start_idx=start_idx, max_files=max_files, scale=scale)

        # Read poses
        try: 
            pose_fn = os.path.join(os.path.expanduser(directory), 'poses', ''.join([sequence, '.txt']))
            self.poses = FileReader(pose_fn, process_cb=kitti_load_poses)
        except: 
            self.poses = repeat(None)
            
        # Read velodyne
        self.velodyne = VelodyneDatasetReader(
            template=os.path.join(directory,velodyne_template), 
            start_idx=start_idx, max_files=max_files
        )

        # Read oxts
        def kitti_load_oxts(fn): 
            return (np.fromfile(fn, dtype=np.float64, sep=' '))
            
        try: 
            oxt_format_fn = os.path.join(os.path.expanduser(directory), 'oxts/dataformat.txt')
            self.oxt_formats = [line.split(':')[0] for line in open(oxt_format_fn)]
            
            oxt_fn = os.path.join(os.path.expanduser(directory), oxt_template)
            self.oxts = DatasetReader(template=oxt_fn, process_cb=lambda fn: kitti_load_oxts(fn), 
                                      start_idx=start_idx, max_files=max_files)
        except Exception as e:
            self.oxts = repeat(None)
        
    def iterframes(self, *args, **kwargs): 
        for (left, right), pose, oxt in izip(self.iter_stereo_frames(*args, **kwargs), 
                                             self.poses.iteritems(*args, **kwargs), 
                                             self.oxts.iteritems(*args, **kwargs)): 
            yield AttrDict(left=left, right=right, velodyne=None, pose=pose, oxt=AttrDict(zip(self.oxt_formats, oxt)))
    
    @property
    def oxt_fieldnames(self): 
        return self.oxt_formats

    def iter_oxts(self, *args, **kwargs): 
        return self.oxts.iteritems()