Beispiel #1
0
 def test(self, sample_id, write_ply=False):
     gt_offset = np.load(
         join(self.gt_offset_dir, 'offset_{:08d}.npy'.format(sample_id)))
     skin = np.load(join(self.skin_dir,
                         'skin_{:08d}.npy'.format(sample_id)))
     gt_vt = gt_offset + skin
     lap = self.L.dot(gt_vt)
     # lap_path=join(self.lap_dir,'lap_{:08d}.npy'.format(sample_id))
     # np.save(lap_path,lap)
     # print('write',lap_path)
     if write_ply:
         ln = np.linalg.norm(lap, axis=1)
         ln_min, ln_max = np.min(ln), np.max(ln)
         print('ln_min', ln_min, 'ln_max', ln_max)
         ln = (ln - ln_min) / (ln_max - ln_min)
         n_vts = gt_vt.shape[0]
         ln = ln.reshape(n_vts, 1)
         red = np.tile(np.array([[1, 0, 0]]), (n_vts, 1))
         blue = np.tile(np.array([[0, 0, 1]]), (n_vts, 1))
         colors = red * ln + blue * (1 - ln)
         colors = np.uint8(colors * 255)
         write_ply(join(self.out_img_dir,
                        'lap_{:08}.ply'.format(sample_id)),
                   gt_vt,
                   self.f,
                   colors=colors)
Beispiel #2
0
def save_pc(pc, path, downsample=False, verbose=False):

    drop = [c for c, d in zip(pc.columns, pc.dtypes) if d in ['object']]
    ply_io.write_ply(
        path,
        pc.drop(columns=drop).loc[pc.downsample if downsample else pc.index])
    if verbose: print('point cloud saved to:', path)
Beispiel #3
0
def write_area_ratio_ply(samples_dir,
                         in_pattern,
                         out_pattern,
                         ratio_range=0.5):
    sample_dirs = os.listdir(samples_dir)
    area_utils = AreaUtils()
    for sample_dir in sample_dirs:
        sample_id = int(sample_dir)
        obj_path = join(samples_dir, sample_dir, in_pattern.format(sample_id))
        obj = read_obj(obj_path)
        v = obj.v
        r = area_utils.compute_vt_area_ratios(v)
        # print('min:',np.min(r),'max:',np.max(r))
        t = ((r - 1) / ratio_range).clip(-1, 1)
        color0 = np.array([[1, 1, 1]])
        color_neg = np.array([[0, 0, 1]])
        color_pos = np.array([[1, 0, 0]])
        colors = np.zeros_like(v)
        # print('colors',colors.shape,'t',t.shape)
        pos_i = t >= 0
        neg_i = t < 0
        pos_t = (t[pos_i]).reshape((-1, 1))
        neg_t = (-t[neg_i]).reshape((-1, 1))
        colors[pos_i] = (1 - pos_t) * color0 + pos_t * color_pos
        colors[neg_i] = (1 - neg_t) * color0 + neg_t * color_neg
        colors = np.uint8(colors * 255)
        out_path = join(samples_dir, sample_dir, out_pattern.format(sample_id))
        print('write to', out_path)
        write_ply(out_path, v, obj.f, colors)
Beispiel #4
0
def save_centres(centres, path, verbose=False):

    drop = [
        c for c, d in zip(centres.columns, centres.dtypes) if d in ['object']
    ]
    ply_io.write_ply(
        path,
        centres.drop(columns=drop).rename(columns={
            'cx': 'x',
            'cy': 'y',
            'cz': 'z'
        }))
    if verbose: print('skeleton points saved to:', path)
Beispiel #5
0
 def draw_visible(self,cam_i):
     gt_obj=read_obj(self.gt_path)
     n_vts=len(gt_obj.v)
     colors=np.full((n_vts,3),255,dtype=np.uint8)
     gt_visible=pkl.load(open(join(self.sample_dir,'cam_visible.pkl'),'rb'))
     gt_visible=np.array(gt_visible)
     visible_color=np.array([255,0,0],dtype=np.uint8)
     colors[gt_visible[:,cam_i]]=visible_color
     # for v_i,visible in enumerate(gt_visible[:,cam_i]):
     #     if visible:
     #         colors[v_i]=visible_color
     out_path=join(self.sample_dir,'visible_{}.ply'.format(cam_i))
     print('write to',out_path)
     write_ply(out_path,gt_obj.v,gt_obj.f,colors)
Beispiel #6
0
    def test_curvature(self):
        obj = read_obj(join(self.data_dir, 'avatar.obj'))
        L_path = join(self.data_dir, 'L.npz')
        if not isfile(L_path):
            print('compute L...')
            L = build_LB(obj.v, obj.f)
            save_npz(L_path, L)
        else:
            print('load L...')
            L = load_npz(L_path)

        curvs = L.dot(obj.v)
        curv_mags = np.linalg.norm(curvs, axis=1)
        colors = self.cvt_colors(curv_mags)
        out_path = join(self.data_dir, 'avatar_curv.ply')
        print('write to', out_path)
        write_ply(out_path, obj.v, obj.f, colors=colors)
Beispiel #7
0
def draw_m(obj_path,m_path,ply_path,c0=np.array([1,1,1]),c1=np.array([1,0,0])):
	obj=read_obj(obj_path)
	m=np.load(m_path)
	mmin=np.min(m)
	mmax=np.max(m)
	print('min:',mmin,'max',mmax)
	mmin,mmax=0.5,1.5
	t=(m-mmin)/(mmax-mmin)
	t=np.clip(t,0,1)
	n_vts=t.shape[0]
	t=t.reshape((n_vts,1))
	C0=np.tile(c0.reshape((1,3)),(n_vts,1))
	C1=np.tile(c1.reshape((1,3)),(n_vts,1))
	colors=C0*(1-t)+C1*t
	colors=np.uint8(colors*255)
	print('write to',ply_path)
	write_ply(ply_path,obj.v,obj.f,colors=colors)
Beispiel #8
0
 def color_obj(self,out_ply_path,in_obj_path,aux_info_path):
     obj=read_obj(in_obj_path)
     aux_info=pkl.load(open(aux_info_path,'rb'))
     v_ids,cams=aux_info
     cams=np.array(cams)
     n_cams=np.max(cams)+1
     def f(attr):
         i0,i1=attr
         if i1>i0:
             i0,i1=i1,i0
         return (i0*n_cams+i1)/(n_cams*(n_cams-1))*0.75
     cmap=plt.get_cmap('hsv')
     colors=np.full((len(obj.v),3),255,dtype=np.uint8)
     for i,v_id in enumerate(v_ids):
         color=np.array(cmap(f(cams[i]))[:3])
         colors[v_id]=color*255
     print('write to',out_ply_path)
     write_ply(out_ply_path,obj.v,obj.f,colors)
Beispiel #9
0
def write_diff_ply(samples_dir,gt_pattern,pd_pattern,out_pattern,max_diff=0.04):
    sample_dirs=os.listdir(samples_dir)
    for sample_dir in sample_dirs:
        sample_id=int(sample_dir)
        gt_path=join(samples_dir,sample_dir,gt_pattern.format(sample_id))
        gt_obj=read_obj(gt_path)
        gt_v=gt_obj.v
        pd_path=join(samples_dir,sample_dir,pd_pattern.format(sample_id))
        pd_v=read_obj(pd_path).v
        d=norm(pd_v-gt_v,axis=1)
        t=np.clip(d/max_diff,0,1).reshape((-1,1))
        color0=np.array([[1,1,1]])
        color1=np.array([[1,0,0]])
        colors=color0*(1-t)+color1*t
        colors=np.uint8(colors*255)
        out_path=join(samples_dir,sample_dir,out_pattern.format(sample_id))
        print('write to',out_path)
        write_ply(out_path,pd_v,gt_obj.f,colors)
    snow.loc[:, 'green'] = 255
    snow.loc[:, 'blue'] = 255
    tree_pc = tree_pc.append(snow)

tree_pc = tree_pc.append(baubals[['x', 'y', 'z', 'red', 'green', 'blue']])
tree_pc.loc[:, 'on'] = 0
tree_pc = tree_pc.append(lights[['x', 'y', 'z', 'red', 'green', 'blue', 'on']])

if args.sketchfab and len(tree_pc) > 3e6:
    if args.verbose: print('thinning from', len(tree_pc), 'to 2.5M points')
    tree_pc = tree_pc.sample(n=int(3e6))

for i, lo in enumerate([1, 2]):
    write_ply(
        os.path.join(folder, 'xmas_tree_pc{}.ply'.format(i)),
        tree_pc[tree_pc.on.isin([0,
                                 lo])][['x', 'y', 'z', 'red', 'green',
                                        'blue']])

if args.sketchfab:
    if args.verbose: print('preparing sketchfab upload')

    with open(os.path.join(folder, 'sketchfab.timeframe'), 'w') as fh:
        fh.write('1 xmas_tree_pc0.ply\n')
        fh.write('1 xmas_tree_pc1.ply\n')

    with ZipFile(os.path.join(folder, 'my-awesome-christmas-tree.zip'),
                 'w') as zip:
        # writing each file one by one
        zip.write(os.path.join(folder, 'sketchfab.timeframe'))
        zip.write(os.path.join(folder, 'xmas_tree_pc0.ply'))
Beispiel #11
0
def save_centres(self, path):
    
    ply_io.write_ply(path, self.centres.rename(columns={'cx':'x', 'cy':'y', 'cz':'z'}))
Beispiel #12
0
def save_pc(self, path, downsample=False):
    
    ply_io.write_ply(path, self.pc[self.pc.columns.drop('VX')].loc[self.pc.downsample if downsample else self.pc.index])
Beispiel #13
0
        if 'red' in df.columns:
            pass
        elif 'rgb' in df.columns:
            cmap = pd.DataFrame.from_dict(
                {
                    c: np.random.randint(0, high=255, size=3)
                    for c in df.rgb.unique()
                },
                orient='index')
            cmap.reset_index(inplace=True)
            cmap.columns = ['rgb', 'red', 'green', 'blue']
            df = pd.merge(df, cmap, on='rgb')
        elif args.colour:
            df['red'] = np.random.randint(0, 255)
            df['green'] = np.random.randint(0, 255)
            df['blue'] = np.random.randint(0, 255)
        else:
            pass

        if args.rotation:
            M = np.loadtxt(args.rotation)
            pc = apply_rotation(M, pc)

        if not args.combine:
            write_ply(pcd.replace('.pcd', '.ply'), df)
        else:
            pc = pc.append(df)

    if args.combine:
        write_ply(args.combine[0], pc)