示例#1
0
    def render_images(self, value):
        print("Value: ", value)
        if len(self.pc_codes) == 0:
            return
        delta = (self.pc_codes[1] - self.pc_codes[0]) / (101)
        delta *= (int(value) + 1)
        pc_code = self.pc_codes[0] + delta
        pc = ptcloud_ae.decoder.predict(pc_code)
        pc *= 0.5
        target_path = os.path.join(PLOTS_PATH, value + ".png")
        fig = plot_3d_point_cloud(pc[0][:, 0],
                                  pc[0][:, 1],
                                  pc[0][:, 2],
                                  show=False,
                                  azim=320,
                                  colorize='rainbow',
                                  filename=target_path)
        if len(self.images) == 0:
            image = self.show_image(target_path, x=256, y=0)
            self.images.append(image)
            image = render_by_pc2pix(pc_code, self.pc2pix, azim=-40)
            image = self.display_image(image, x=256, y=256)
            self.images.append(image)
        else:
            img = Image.open(target_path)
            render = ImageTk.PhotoImage(img)
            self.images[0].configure(image=render)
            self.images[0].image = render

            img = render_by_pc2pix(pc_code, self.pc2pix, azim=-40)
            img = Image.fromarray(np.uint8(img * 255))
            img = img.resize((256, 256), Image.ANTIALIAS)
            render = ImageTk.PhotoImage(img)
            self.images[1].configure(image=render)
            self.images[1].image = render
示例#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
def plot_image2ptcloud_results(image2ptcloud):
    im, pc, vol = image2ptcloud.test_source.next_batch()
    print("pc: ", pc.shape)
    save_images(im, posterior_net.test_source)

    pre = image2ptcloud.predict(im)
    pre *= 0.5
    iou = 0.0
    for i in range(len(latent)):
        grd = pc[i]
        print("Ground: ", i)
        plot_3d_point_cloud(grd[:, 0],
                            grd[:, 1],
                            grd[:, 2],
                            title='point cloud',
                            in_u_sphere=True)

        print("Prediction: ", i)
        plot_3d_point_cloud(pre[i][:, 0],
                            pre[i][:, 1],
                            pre[i][:, 2],
                            title='point cloud',
                            in_u_sphere=True)
示例#4
0
def plot_decoded_ptcloud(ae, test_source):

    im, pc = test_source.next_batch()
    data_dir = 'ptcloud_out'
    save_dir = os.path.join(os.getcwd(), data_dir)
    if not os.path.isdir(save_dir):
        os.makedirs(save_dir)

    for i in range(len(pc)):
        test = pc[i]
        plot_3d_point_cloud(test[:, 0],
                            test[:, 1],
                            test[:, 2],
                            in_u_sphere=True)

        test = pc[i] / 0.5
        shape = (1, ) + test.shape
        test = np.reshape(test, shape)
        reconstruction = 0.5 * ae.predict(test)
        plot_3d_point_cloud(reconstruction[0][:, 0],
                            reconstruction[0][:, 1],
                            reconstruction[0][:, 2],
                            in_u_sphere=True)
示例#5
0
def plot_posterior_net_results(posterior_net,
                               ptcloud_ae=None,
                               image_ae=None,
                               im2pc=True):
    im, pc, view = posterior_net.test_source.next_batch()
    print("pc: ", pc.shape)
    # save_images(im, posterior_net.test_source)

    if im2pc:
        latent = posterior_net.posterior_net.predict(im)
        pre = ptcloud_ae.decoder.predict(latent)
        pre *= 0.5
        cost = get_chamfer(pc, pre)
        cost = np.sqrt(cost)
        print("Batch chamfer: ", cost.mean())
        for i in range(len(latent)):
            grd = pc[i]
            print("Ground: ", i)
            plot_3d_point_cloud(grd[:, 0],
                                grd[:, 1],
                                grd[:, 2],
                                title='point cloud',
                                in_u_sphere=True)

            print("Prediction: ", i)
            print("Chamfer: ", cost[i])
            plot_3d_point_cloud(pre[i][:, 0],
                                pre[i][:, 1],
                                pre[i][:, 2],
                                title='point cloud',
                                in_u_sphere=True)
    else:
        latent, v = posterior_net.posterior_net.predict([pc, view])
        pre = image_ae.decoder.predict(latent)
        for i in range(len(latent)):
            grd = pc[i]
            print("Prediction: ", i)
            print("View ground: ", view[i], " View pred: ", v[i])
            img = pre[i]
            s = img.shape
            img = np.reshape(img, (s[0], s[0]))
            save_image(img, i, folder="predictions")
            plot_3d_point_cloud(grd[:, 0],
                                grd[:, 1],
                                grd[:, 2],
                                title='point cloud',
                                in_u_sphere=True)
示例#6
0
        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)
            pc_codes.append(pc_code1)

            tag = tags[i+1]
            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_interpolate + 1) + ".png")
示例#7
0
            #    elev += 360.
            azim = azim[0][0]
            #if azim < 0:
            #    azim += 360.
            i = 0
            t += 1
            for path in paths:
                target_path = os.path.join(PLOTS_PATH, tag + "-" + str(i) + ".png")
                ply_file = os.path.join(path, tag + ".ply")
                i += 1

                ply_data = PlyData.read(ply_file)
                points = ply_data['vertex']
                pc = np.vstack([points['x'], points['y'], points['z']]).T
                fig = plot_3d_point_cloud(pc[:, 0], 
                                          pc[:, 1], 
                                          pc[:, 2],
                                          show=False,
                                          elev=elev,
                                          azim=azim,
                                          colorize='rainbow',
                                          filename=target_path)
                #fig.close('all')
                image = np.array(Image.open(target_path)) / 255.0
                images.append(image)
            print(str(t), view_file, ply_file, "-->", target_path, elev, azim)
            plot_images(1, 5, images, tag + ".png", dir_name="point_clouds")



示例#8
0
文件: data.py 项目: eduarddohr/pc2pix
    print(val.shape)
    test = np.array(x['test'])
    print(test.shape)

    print(val)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    args = parser.parse_args()
    load_samples()
    exit(0)

    dsource = DataSource()
    ims, pcs = dsource.next_batch()
    for i in range(len(ims)):
        im = ims[i]
        path = os.path.dirname(os.path.realpath(__file__))
        path = os.path.join(path, "tmp")
        f = "im-%d.png" % i
        path = os.path.join(path, f)
        dsource.save_img(im, path)
        reconstruction = pcs[i]
        plot_3d_point_cloud(reconstruction[:, 0],
                            reconstruction[:, 1],
                            reconstruction[:, 2],
                            in_u_sphere=True)
    print(ims.shape)
    print(pcs.shape)
    dsource.close()