专栏名称: 人工智能头条
专注人工智能技术前沿、实战技巧及大牛心得。
目录
相关文章推荐
爱可可-爱生活  ·  【Anthropic团队内部如何用Claud ... ·  昨天  
爱可可-爱生活  ·  【[90星]torchvista:用一行代码 ... ·  昨天  
爱可可-爱生活  ·  [LG]《Kinetics: ... ·  昨天  
宝玉xp  ·  Anthropic ... ·  昨天  
51好读  ›  专栏  ›  人工智能头条

3D 建模费时费力,Python 让照片秒变模型

人工智能头条  · 公众号  · AI  · 2021-04-20 18:30

正文

请到「今天看啥」查看全文


], v[ 1 ], v[ 2 ]))
file . write ( 'vt %.4f %.4f\n' % (vt[ 0 ], vt[ 1 ]))
for f in faces:
f_plus = f + 1
file . write ( 'f %d/%d %d/%d %d/%d\n' % (f_plus[ 0 ], f_plus[ 0 ],
f_plus[ 2 ], f_plus[ 2 ],
f_plus[ 1 ], f_plus[ 1 ]))
file .close()

(2)PiFuHD算法是使用图片中的上下文信息,通过对原始不清晰图像先进行了超分辨率重建获得,其中高分辨率详细信息是通过在相似的轻量级PIFu网络中使用这些第一个3D输出作为高分辨率输入来添加的。
def gen_mesh(res, net, cuda, data, save_path, thresh=0.5, use_octree=True, components=False):
    image_tensor_global = data['img_512']
    image_tensor = data['img']
    calib_tensor = data['calib']
    net.filter_global(image_tensor_global)
    net.filter_local(image_tensor[:,None])
    try:
        if net.netG.netF is not None:
            image_tensor_global = torch.cat([image_tensor_global, net.netG.nmlF], 0)
        if net.netG.netB is not None:
            image_tensor_global = torch.cat([image_tensor_global, net.netG.nmlB], 0)
    except:
        pass
    b_min = data['b_min']
    b_max = data['b_max']
    try:
        save_img_path = save_path[:-4] + '.png'
        save_img_list = []
        for v in range(image_tensor_global.shape[0]):
            save_img = (np.transpose(image_tensor_global[v].detach().cpu().numpy(), (120)) * 0.5 + 0.5)[:, :, ::-1] * 255.0
            save_img_list.append(save_img)
        save_img = np.concatenate(save_img_list, axis=1)
        cv2.imwrite(save_img_path, save_img)
        verts, faces, _, _ = reconstruction(
            net, cuda, calib_tensor, res, b_min, b_max, thresh, use_octree=use_octree, num_samples=50000)
        verts_tensor = torch.from_numpy(verts.T).unsqueeze(0).to(device=cuda).float()
        # if 'calib_world' in data:
        #     calib_world = data['calib_world'].numpy()[0]
        #     verts = np.matmul(np.concatenate([verts, np.ones_like(verts[:,:1])],1), inv(calib_world).T)[:,:3]
        color = np.zeros(verts.shape)
        interval = 50000
        for i in range(len(color) // interval + 1):
            left = i * interval
            if i == len(color) // interval:
                right = -1
            else:
                right = (i + 1) * interval
            net.calc_normal(verts_tensor[:, None, :, left:right], calib_tensor[:,None], calib_tensor)
            nml = net.nmls.detach().cpu().numpy()[0] * 0.5 + 0.5
            color[left:right] = nml.T
        save_obj_mesh_with_color(save_path, verts, faces, color)
    except Exception as e:
        print(e)

(3)人体表面颜色重建。基于上一步的重建深度特征,这是模型只需要关注于模型各点的颜色即可,而不需要关注潜在的3D信息。
def gen_mesh_imgColor(res, net, cuda, data, save_path, thresh=0.5, use_octree=True, components=False):
    image_tensor_global = data['img_512'].to(device=cuda)
    image_tensor = data['img'].to(device=cuda)
    calib_tensor = data['calib'].to(device=cuda)
    net.filter_global(image_tensor_global)
    net.filter_local(image_tensor[:,None])
    try:
        if net.netG.netF is not None:
            image_tensor_global = torch.cat([image_tensor_global, net.netG.nmlF], 0)
        if net.netG.netB is not None:
            image_tensor_global = torch.cat([image_tensor_global, net.netG.nmlB], 0)
    except:
        pass
    b_min = data['b_min']
    b_max = data['b_max']
    try:
        save_img_path = save_path[:-4






请到「今天看啥」查看全文