Exemple #1
0
def upsampling(dataroot, base_name, mesh_list):
    with open('./mtl_info.txt', 'r') as m_info:
        mtl_info = m_info.readlines()
    for mesh in mesh_list:
        body = Mesh(filename=os.path.join(dataroot, mesh))
        v, f = body.v, body.f
        (mapping, hf) = loop_subdivider(v, f)
        hv = mapping.dot(v.ravel()).reshape(-1, 3)
        body_hres = Mesh(hv, hf)

        vt, ft = np.hstack((body.vt, np.ones((body.vt.shape[0], 1)))), body.ft
        (mappingt, hft) = loop_subdivider(vt, ft)
        hvt = mappingt.dot(vt.ravel()).reshape(-1, 3)[:, :2]
        body_hres.vt, body_hres.ft = hvt, hft

        #body_hres.set_texture_image(body_tex)
        body_hres.write_obj(
            os.path.join(dataroot, mesh.replace('.obj', '_hres.obj')))

        with open(os.path.join(dataroot, mesh.replace('.obj', '_hres.obj')),
                  'r') as original:
            data = original.read()
        with open(os.path.join(dataroot, mesh.replace('.obj', '_hres.obj')),
                  'w') as modified:
            modified.write(f"mtllib {mesh.replace('.obj', '_hres.mtl')}\n" +
                           data)

        with open(os.path.join(dataroot, mesh.replace('.obj', '_hres.mtl')),
                  'w') as fm:
            fm.write(''.join(mtl_info))
            fm.write('map_Kd %s_octopus_hres.jpg' % (base_name))
def upsampling_mesh(verts, faces):
    """
    メッシュの頂点数を増やし、メッシュを高解像度化する
    [args]
        verts : numpy / shape=[V,3]
        faces : numpy / shape=[F,3]
    """
    (mapping, hres_faces) = loop_subdivider(verts, faces)
    hres_verts = mapping.dot(verts.ravel()).reshape(-1, 3)
    return hres_verts, hres_faces, mapping
Exemple #3
0
def get_hres(v, f):
    """
    Get an upsampled version of the mesh.
    OUTPUT:
        - nv: new vertices
        - nf: faces of the upsampled
        - mapping: mapping from low res to high res
    """
    from opendr.topology import loop_subdivider
    (mapping, nf) = loop_subdivider(v, f)
    nv = mapping.dot(v.ravel()).reshape(-1, 3)
    return (nv, nf, mapping)
Exemple #4
0


parser = argparse.ArgumentParser()
parser.add_argument('dir', type=str,)
args = parser.parse_args()
name = ' '.join((args.dir).split('/')).split()[-1]
os.makedirs(os.path.join(args.dir,'unwraps'),exist_ok=True)
step1_make_unwraps.main(os.path.join(args.dir,'frame_data.pkl'),os.path.join(args.dir,'frames'),os.path.join(args.dir,'segmentations'),os.path.join(args.dir,'unwraps'))
step2_segm_vote_gmm.main(os.path.join(args.dir,'unwraps'),os.path.join(args.dir,'segm.png'),os.path.join(args.dir,'gmm.pkl'))
step3_stitch_texture.main(os.path.join(args.dir,'unwraps'), os.path.join(args.dir,'segm.png'), os.path.join(args.dir,'gmm.pkl'), os.path.join(args.dir,name+'_octopus.jpg'),20)

filename = os.path.join(args.dir,name+'.obj')
body = Mesh(filename=filename.replace(name+'.obj',name+'_octopus.obj'))
body_tex = filename.replace('.obj', '_octopus.jpg')
if not os.path.exists(body_tex):
    body_tex = 'tex_{}'.format(body_tex)

v, f = body.v, body.f
(mapping, hf) = loop_subdivider(v, f)
hv = mapping.dot(v.ravel()).reshape(-1, 3)
body_hres = Mesh(hv, hf)

vt, ft = np.hstack((body.vt, np.ones((body.vt.shape[0], 1)))), body.ft
(mappingt, hft) = loop_subdivider(vt, ft)
hvt = mappingt.dot(vt.ravel()).reshape(-1, 3)[:, :2]
body_hres.vt, body_hres.ft = hvt, hft

body_hres.set_texture_image(body_tex)
body_hres.write_obj(os.path.join(filename.replace('.obj', '_octopus_hres.obj')))