三维人脸重建:精读3dmm.py
生活随笔
收集整理的這篇文章主要介紹了
三维人脸重建:精读3dmm.py
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
文章目錄
- 代碼解析
- 1. 載入模型
- 2. 生成mesh, 也就是一些點(diǎn),三角形的集合
- 3. 坐標(biāo)變換
- 4. 使用68個(gè)關(guān)鍵點(diǎn)做fit
- 轉(zhuǎn)載請(qǐng)注明出處
這個(gè)代碼的主要內(nèi)容就是根據(jù)一些隨機(jī)的參數(shù)從3d模型渲染到2d圖片
然后從圖片再變換回去
代碼解析
1. 載入模型
bfm = MorphabelModel('Data/BFM/Out/BFM.mat')# 這里面初始化的參數(shù)有: def __init__(self, model_path, model_type = 'BFM'):super( MorphabelModel, self).__init__()if model_type=='BFM':self.model = load.load_BFM(model_path)# fixed attributesself.nver = self.model['shapePC'].shape[0]/3 # 頂點(diǎn)的個(gè)數(shù)self.ntri = self.model['tri'].shape[0] # 三角形的個(gè)數(shù)self.n_shape_para = self.model['shapePC'].shape[1] # 199self.n_exp_para = self.model['expPC'].shape[1] # 29self.n_tex_para = self.model['texMU'].shape[1] # 1self.kpt_ind = self.model['kpt_ind'] # 關(guān)鍵點(diǎn)索引self.triangles = self.model['tri']self.full_triangles = np.vstack((self.model['tri'], self.model['tri_mouth'])) # 按行堆疊, 例如兩個(gè)(1, 3)成為(2, 3)2. 生成mesh, 也就是一些點(diǎn),三角形的集合
sp = bfm.get_shape_para('random') ep = bfm.get_exp_para('random') # 上面就是生成一些隨機(jī)的形狀與表情參數(shù)vertices = bfm.generate_vertices(sp, ep) # 模型所有不包含顏色后加和的點(diǎn)tp = bfm.get_tex_para('random') colors = bfm.generate_colors(tp) colors = np.minimum(np.maximum(colors, 0), 1)- 看看這個(gè)generate_vertices, 輸入形狀系數(shù)和表情系數(shù),返回頂點(diǎn), 大小是(nver, 3)
- 這個(gè)generated_colors是根據(jù)紋理系數(shù)生成顏色, 其實(shí)這里并沒有對(duì)
紋理也就是顏色做后續(xù)的fit, 只不過(guò)是用一個(gè)隨機(jī)數(shù)乘了原來(lái)的系數(shù)
3. 坐標(biāo)變換
- 指定了s, R, t等縮放旋轉(zhuǎn)位移參數(shù), 然后把3D的點(diǎn)變到2D
4. 使用68個(gè)關(guān)鍵點(diǎn)做fit
x = projected_vertices[bfm.kpt_ind, :2] # 這個(gè)是相機(jī)坐標(biāo)系下的人臉關(guān)鍵點(diǎn)X_ind = bfm.kpt_ind # index of keypoints in 3DMM. fixed. # fit 根據(jù)二維點(diǎn)來(lái)解出對(duì)應(yīng)的3d參數(shù)叫fit fitted_sp, fitted_ep, fitted_s, fitted_angles, fitted_t = bfm.fit(x, X_ind, max_iter = 3)- 這里的fit算法里面有個(gè)黃金標(biāo)準(zhǔn)算法, 網(wǎng)上沒有講的很深入的, 同時(shí)現(xiàn)在大多數(shù)是用深度學(xué)習(xí)的方法fit了, 這個(gè)先占坑
這里的fit結(jié)果有5個(gè)參數(shù), 分別是形狀, 表情, s, R, t
總結(jié)
以上是生活随笔為你收集整理的三维人脸重建:精读3dmm.py的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Java设计模式-外观模式(Facade
- 下一篇: 3dmm人脸配准/重建:gold sta