예제 #1
0
 def get_pc(self, sid, mid, idx):
     rand_idx = idx
     pcs = []
     for ix in rand_idx:
         f = mid + '.ply'
         f = osp.join(self.pc_dir, sid, f)
         pc = load_ply(f)
         pcs.append(pc)
     return np.stack(pcs, axis=0)
예제 #2
0
    def init_pc2pix(self):
        # datasets = ('test')
        os.makedirs(PLOTS_PATH, exist_ok=True)
        # sofa2car - modify these 2 keys manually
        #keys = [ "04256520", "02958343"]
        # sofa2chair
        keys = ["04256520", "03001627"]
        # chair2chair
        # keys = [ "03001627", "03001627"]
        tags = []
        data = js[keys[0]]
        tag = data['test']
        tags.append(tag)
        data = js[keys[1]]
        tag = data['test']
        tags.append(tag)
        plys = []
        ply_path = os.path.join(self.ply, keys[0])
        plys.append(ply_path)
        ply_path = os.path.join(self.ply, keys[1])
        plys.append(ply_path)
        tagslen = min(len(tags[0]), len(tags[1]))

        self.tags = []
        self.pc_codes = []

        np.random.seed(int(time.time()))
        for i in range(2):
            j = np.random.randint(0, tagslen, 1)[0]
            tag = tags[i][j]
            self.tags.append(tag)
            # images = []
            # pc_codes = []
            ply_file = os.path.join(plys[i], tag + ".ply")
            pc = load_ply(ply_file)

            target_path = os.path.join(PLOTS_PATH, tag + ".png")
            fig = plot_3d_point_cloud(pc[:, 0],
                                      pc[:, 1],
                                      pc[:, 2],
                                      show=False,
                                      azim=320,
                                      colorize='rainbow',
                                      filename=target_path)

            pc = norm_pc(pc)
            shape = pc.shape
            pc = np.reshape(pc, [-1, shape[0], shape[1]])
            pc_code = ptcloud_ae.encoder.predict(pc)
            self.pc_codes.append(pc_code)

            self.show_image(target_path, x=(i * 2) * 256, y=0)
            image = render_by_pc2pix(pc_code, self.pc2pix, azim=-40)
            print(image.shape)
            self.display_image(image, x=(i * 2) * 256, y=256)
예제 #3
0
 for key in js.keys():
     # key eg 03001627
     data = js[key]
     tags = data['test']
     ply_path_main = os.path.join(args.ply, key)
     tagslen = len(tags)
     n_interpolate = 10
     if not interpolate:
         n_interpolate = 2
     for i in range(tagslen - 1):
         n = 0
         tag = tags[i]
         images = []
         pc_codes = []
         ply_file = os.path.join(ply_path_main, tag + ".ply")
         pc = load_ply(ply_file)
         target_path = os.path.join(PLOTS_PATH, tag + "_" + str(n) + ".png")
         n += 1
         fig = plot_3d_point_cloud(pc[:, 0],
                                   pc[:, 1],
                                   pc[:, 2],
                                   show=False,
                                   azim=320,
                                   colorize='rainbow',
                                   filename=target_path)
         image = np.array(Image.open(target_path)) / 255.0
         images.append(image)
         pc = norm_pc(pc)
         shape = pc.shape
         pc = np.reshape(pc, [-1, shape[0], shape[1]])
         pc_code1 = ptcloud_ae.encoder.predict(pc)
예제 #4
0
    fake_pc_codes = None
    start_time = datetime.datetime.now()
    print("Generating fake pc codes...")
    print("Saving pc codes to file: ", pc_codes_filename)
    i = 0
    for dataset in datasets:
        for key in js.keys():
            # key eg 03001627
            data = js[key]
            tags = data[dataset]
            ply_path_main = os.path.join(args.ply, key)
            for tag in tags:
                # tag eg fff29a99be0df71455a52e01ade8eb6a
                ply_file = os.path.join(ply_path_main, tag + ".ply")
                pc = norm_pc(load_ply(ply_file))
                shape = pc.shape
                pc = np.reshape(pc, [-1, shape[0], shape[1]])
                fake_pc_code = ptcloud_ae.encoder.predict(pc)
                if fake_pc_codes is None:
                    fake_pc_codes = fake_pc_code
                else:
                    fake_pc_codes = np.append(fake_pc_codes,
                                              fake_pc_code,
                                              axis=0)
                elapsed_time = datetime.datetime.now() - start_time
                i += 1
                pcent = 100. * float(i) / steps
                log = "%0.2f%% of %d [shape: %s] [tag: %s] [time: %s]" % (
                    pcent, steps, fake_pc_codes.shape, tag, elapsed_time)
                print(log)