예제 #1
0
    def run_from_file(self):
        assert os.path.isdir(self.args.disparity_dir)
        assert os.path.isdir(self.args.calib_dir)

        if not os.path.isdir(self.args.save_dir):
            os.makedirs(self.args.save_dir)

        disps = [
            x for x in os.listdir(self.args.disparity_dir)
            if x[-3:] == 'png' or x[-3:] == 'npy'
        ]
        disps = sorted(disps)

        for fn in disps:
            predix = fn[:-4]
            calib_file = '{}/{}.txt'.format(self.args.calib_dir, predix)
            calib = kitti_util.Calibration(calib_file)

            # disp_map = ssc.imread(args.disparity_dir + '/' + fn) / 256.
            disp_map = np.load(self.args.disparity_dir + '/' + predix + '.npy')
            disp_map = (disp_map * 256).astype(np.uint16) / 256.

            lidar = self.pcl_generator.run(calib, disp_map)

            # pad 1 in the indensity dimension
            lidar = np.concatenate([lidar, np.ones((lidar.shape[0], 1))], 1)
            lidar = lidar.astype(np.float32)
            lidar.tofile('{}/{}.bin'.format(self.args.save_dir, predix))
            print('Finish Depth {}'.format(predix))
 def __init__(self, img_dir, lidar_dir, calib_dir):
     self.calib = utils.Calibration(calib_dir, from_video=True)
     self.img_dir = img_dir
     self.lidar_dir = lidar_dir
     self.img_filenames = sorted([os.path.join(img_dir, filename) \
         for filename in os.listdir(img_dir)])
     self.lidar_filenames = sorted([os.path.join(lidar_dir, filename) \
         for filename in os.listdir(lidar_dir)])
     print(len(self.img_filenames))
     print(len(self.lidar_filenames))
     #assert(len(self.img_filenames) == len(self.lidar_filenames))
     self.num_samples = len(self.img_filenames)
예제 #3
0
 def __init__(self, img_dir, lidar_dir, calib_dir):   #初始化,kitti_object的构造函数 -H
     self.calib = utils.Calibration(calib_dir, from_video=True)   #调用Calibration进行标定 -H
     self.img_dir = img_dir
     self.lidar_dir = lidar_dir
     self.img_filenames = sorted([os.path.join(img_dir, filename) #sorted生成排序后的新list,不改变原list -H
         for filename in os.listdir(img_dir)])
     self.lidar_filenames = sorted([os.path.join(lidar_dir, filename) \
         for filename in os.listdir(lidar_dir)])
     print(len(self.img_filenames))//返回self.num_samples -H
     print(len(self.lidar_filenames))
     #assert(len(self.img_filenames) == len(self.lidar_filenames))//要求处理前后的num_samples一致-H
     self.num_samples = len(self.img_filenames)
예제 #4
0
    def get_calibration(self, idx):
        """
        Get calib object
        :param idx: for calib file name
        :return:
        """
        assert (idx < self.num_samples)
        calib_filename = os.path.join(self.calib_dir, '%06d.txt' % (idx))
        # calib_filename = "/media/zelt/Données/KITTI/raw/calib/2011_09_26/2011_09_26.txt"

        # calib_filename = "/media/zelt/Données/KITTI/raw/calib/2011_09_28/2011_09_28.txt"
        # calib_filename = "/media/zelt/Données/KITTI/raw/calib/2011_09_26/2011_09_26.txt"
        # calib_filename = "/media/zelt/Données/KITTI/raw/calib/2011_09_26/2011_09_26.txt"
        return utils.Calibration(calib_filename)
예제 #5
0
    def __init__(self, img_dir, lidar_dir, calib_dir):
        self.calib = utils.Calibration(calib_dir, from_video=True)
        self.img_dir = img_dir
        self.lidar_dir = lidar_dir
        self.img_filenames = {
            int(os.path.splitext(f)[0]): os.path.join(img_dir, f)
            for f in os.listdir(img_dir)
        }
        self.lidar_filenames = {
            int(os.path.splitext(f)[0]): os.path.join(lidar_dir, f)
            for f in os.listdir(lidar_dir)
        }

        assert (len(self.img_filenames) == len(self.lidar_filenames))
        self.num_samples = len(self.img_filenames)
예제 #6
0
 def __init__(self, img_dir, lidar_dir, calib_dir, label_file=None):
     self.calib = utils.Calibration(calib_dir, from_video=True)
     self.img_dir = img_dir
     self.lidar_dir = lidar_dir
     self.img_filenames = sorted([
         os.path.join(img_dir, filename) for filename in os.listdir(img_dir)
     ])
     self.lidar_filenames = sorted([
         os.path.join(lidar_dir, filename)
         for filename in os.listdir(lidar_dir)
     ])
     assert (len(self.img_filenames) == len(self.lidar_filenames))
     self.num_samples = len(self.img_filenames)
     if label_file is not None:
         self.frame_dict_2d, self.frame_dict_3d, self.frame_dict_obj, self.frame_dict_id = \
             utils.read_label_video(label_file, self.calib)
예제 #7
0
파일: datagen.py 프로젝트: Xiang95/MA
    def __getitem__(self, item):
        sample_idx = item
        # sample = self.kitti_data.sample[sample_idx]
        velo_pc = kitti_util.load_velo_scan(
            os.path.join(self.data_path_pc,
                         sorted(os.listdir(self.data_path_pc))[item]))
        # img are numpy array so transform must add ToPIL
        img = kitti_util.load_image(
            os.path.join(self.data_path_image,
                         sorted(os.listdir(self.data_path_image))[item]))
        calibration_path = os.path.join(
            self.data_path_calib,
            sorted(os.listdir(self.data_path_calib))[item])
        calibration = kitti_util.Calibration(calibration_path)
        img = transform(img)
        sample = {'image': img, 'velo_pc': velo_pc, 'calibration': calibration}

        return sample
def extract_ransac(calib_dir, lidar_dir, planes_dir):
    data_idx_list = [x[:-4] for x in os.listdir(lidar_dir) if x[-4:] == '.bin']
    data_idx_list = sorted(data_idx_list)

    if not os.path.isdir(planes_dir):
        os.makedirs(planes_dir)

    for data_idx in data_idx_list:

        print('------------- ', data_idx)
        calib = calib_dir + '/' + data_idx + '.txt'
        calib = utils.Calibration(calib)
        pc_velo = lidar_dir + '/' + data_idx + '.bin'
        pc_velo = np.fromfile(pc_velo, dtype=np.float32).reshape(-1, 4)
        pc_rect = calib.project_velo_to_rect(pc_velo[:, :3])
        valid_loc = (pc_rect[:, 1] > 1.5) & \
                    (pc_rect[:, 1] < 1.86) & \
                    (pc_rect[:, 2] > 0) & \
                    (pc_rect[:, 2] < 40) & \
                    (pc_rect[:, 0] > -15) & \
                    (pc_rect[:, 0] < 15)
        pc_rect = pc_rect[valid_loc]
        if len(pc_rect) < 5:
            w = [0, -1, 0]
            h = 1.65
        else:
            reg = RANSACRegressor().fit(pc_rect[:, [0, 2]], pc_rect[:, 1])
            w = np.zeros(3)
            w[0] = reg.estimator_.coef_[0]
            w[2] = reg.estimator_.coef_[1]
            w[1] = -1.0
            h = reg.estimator_.intercept_
            w = w / np.linalg.norm(w)
        print(w)
        print(h)

        lines = ['# Plane', 'Width 4', 'Height 1']

        plane_file = os.path.join(planes_dir, data_idx + '.txt')
        result_lines = lines[:3]
        result_lines.append("{:e} {:e} {:e} {:e}".format(w[0], w[1], w[2], h))
        result_str = '\n'.join(result_lines)
        with open(plane_file, 'w') as f:
            f.write(result_str)
예제 #9
0
    def run_from_file(self):
        if self.args_disp.KITTI == '2015':
            from dataloader import KITTI_submission_loader as DA
        else:
            from dataloader import KITTI_submission_loader2012 as DA
        test_left_img, test_right_img = DA.dataloader(self.args_disp.datapath)

        if not os.path.isdir(self.args_disp.save_path):
            os.makedirs(self.args_disp.save_path)

        for inx in range(len(test_left_img)):
            imgL_o = (skimage.io.imread(test_left_img[inx]).astype('float32'))
            imgR_o = (skimage.io.imread(test_right_img[inx]).astype('float32'))

            img = self.disp_pred_net.run(imgL_o, imgR_o)

            # # file output
            # print(test_left_img[inx].split('/')[-1])
            # if self.args.save_figure:
            #     skimage.io.imsave(self.args.save_path+'/'+test_left_img[inx].split('/')[-1],(img*256).astype('uint16'))
            # else:
            #     np.save(self.args.save_path+'/'+test_left_img[inx].split('/')[-1][:-4], img)

            predix = test_left_img[inx].split('/')[-1][:-4]
            calib_file = '{}/{}.txt'.format(self.args_gen_lidar.calib_dir,
                                            predix)
            calib = kitti_util.Calibration(calib_file)

            img = (img * 256).astype(np.uint16) / 256.
            lidar = self.pcl_generator.run(calib, img)

            # pad 1 in the indensity dimension
            lidar = np.concatenate([lidar, np.ones((lidar.shape[0], 1))], 1)
            lidar = lidar.astype(np.float32)
            lidar.tofile('{}/{}.bin'.format(self.args_gen_lidar.save_dir,
                                            predix))
            print('Finish Depth {}'.format(predix))
예제 #10
0
 def get_calibration(self, idx):#校准图片-H
     assert(idx<self.num_samples)        #断言,若不满足条件就报错-H  ,补充说明这句话是说如果下标超出文件的范围就报错
     calib_filename = os.path.join(self.calib_dir, '%06d.txt'%(idx))
     return utils.Calibration(calib_filename)
예제 #11
0
def get_calibration(idx):
    calib_filename = path.join(calib_dir, "%06d.txt" % (idx))
    return utils.Calibration(calib_filename)
def calib_loader(path):
    fu = kitti_util.Calibration(path).f_u
    return fu
예제 #13
0
 def get_calibration(self, idx):
     # assert idx < self.num_samples
     calib_filename = os.path.join(self.calib_dir, f"{self.index_format}.txt" % (idx))
     return utils.Calibration(calib_filename, camera_name=f'P2')
예제 #14
0
    if not os.path.isdir(disparity_dir):
        os.makedirs(disparity_dir)

    lidar_files = [x for x in os.listdir(lidar_dir) if x[-3:] == 'bin']
    lidar_files = sorted(lidar_files)

    assert os.path.isfile(args.split_file)
    with open(args.split_file, 'r') as f:
        file_names = [x.strip() for x in f.readlines()]

    for fn in lidar_files:
        predix = fn[:-4]
        if predix not in file_names:
            continue
        calib_file = '{}/{}.txt'.format(calib_dir, predix)
        calib = kitti_util.Calibration(calib_file,
                                       right_calib=args.right_calib)
        # load point cloud
        lidar = np.fromfile(lidar_dir + '/' + fn, dtype=np.float32).reshape(
            (-1, 4))[:, :3]
        image_file = '{}/{}.png'.format(image_dir, predix)
        image = imageio.imread(image_file)
        height, width = image.shape[:2]
        print('calib baseline {}'.format(calib.baseline))
        disp = generate_dispariy_from_velo(lidar,
                                           height,
                                           width,
                                           calib,
                                           depth_as_disp=DEPTH_AS_DISP,
                                           baseline=calib.baseline)
        np.save(
            disparity_dir + '/' + predix + ('_r' if args.right_calib else ''),
예제 #15
0
 def get_calibration(self, idx, drive_idx):
     calib_filename = os.path.join(self.calib_dir, '%04d.txt' % (drive_idx))
     return utils.Calibration(calib_filename, from_video=False)
예제 #16
0
 def get_calibration(self, idx):
     assert(idx<self.num_samples) 
     #** calib_filename = os.path.join(self.calib_dir, '%06d.txt'%(idx))
     calib_filename = os.path.join(self.calib_dir, '%06d.txt'%(0))
     #print(calib_filename)
     return utils.Calibration(calib_filename)
예제 #17
0
 def get_calibration(self, idx):
     idx = self.sample_ids[idx]
     calib_filename = os.path.join(self.calib_dir, "%06d.txt" % (idx))
     return utils.Calibration(calib_filename)
                        default='~/Kitti/object/training/predicted_disparity')
    parser.add_argument('--save_dir',
                        type=str,
                        default='~/Kitti/object/training/predicted_velodyne')
    parser.add_argument('--max_high', type=int, default=1)
    args = parser.parse_args()

    assert os.path.isdir(args.depth_dir)
    assert os.path.isdir(args.calib_dir)

    if not os.path.isdir(args.save_dir):
        os.makedirs(args.save_dir)

    depths = [
        x for x in os.listdir(args.depth_dir)
        if x[-3:] == 'npy' and 'std' not in x
    ]
    depths = sorted(depths)

    for fn in depths:
        predix = fn[:-4]
        calib_file = '{}/{}.txt'.format(args.calib_dir, predix)
        calib = kitti_util.Calibration(calib_file)
        depth_map = np.load(args.depth_dir + '/' + fn)
        lidar = project_disp_to_depth(calib, depth_map, args.max_high)
        # pad 1 in the indensity dimension
        lidar = np.concatenate([lidar, np.ones((lidar.shape[0], 1))], 1)
        lidar = lidar.astype(np.float32)
        lidar.tofile('{}/{}.bin'.format(args.save_dir, predix))
        print('Finish Depth {}'.format(predix))
예제 #19
0
 def get_calibration(self, idx: str):
     calib_filename = os.path.join(self.calib_dir, '{}.txt'.format(idx))
     return utils.Calibration(calib_filename)
예제 #20
0
 def get_calibration(self, idx):
     assert idx < self.num_samples
     calib_filename = os.path.join(self.calib_dir, "%06d.txt" % (idx))
     return utils.Calibration(calib_filename)
예제 #21
0
from shutil import copyfile
import os
import numpy as np
import kitti_util
import kitti_object
from warp import *
import imageio

c = 0
for r,_,fs in os.walk('/share/nikola/export/yw763/Dataset/kitti_od/training/image_2/'):
    for f in fs:
        print(c)
        c += 1
        copyfile(r+'/'+f,'kitti_od/image_2/'+f)
        copyfile('image_3'.join(r.split('image_2'))+f,'kitti_od/image_3/'+f)
        vel = np.fromfile('velodyne'.join(r.split('image_2'))+f[:-4]+'.bin',dtype=np.float32).reshape([-1,4])[:,:3]
        cal = kitti_util.Calibration('calib'.join(r.split('image_2'))+f[:-4]+'.txt')
        lidar = assign_img_for_pc(vel,imageio.imread(r+'/'+f),cal)
        lidar = np.where(lidar>0.0,0.54*721/lidar,0.0)
        imageio.imsave('kitti_od/disp/'+f,np.array(lidar*256,dtype=np.uint16))