三维人脸重建:精读3dmm.py
生活随笔
收集整理的這篇文章主要介紹了
三维人脸重建:精读3dmm.py
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 代碼解析
- 1. 載入模型
- 2. 生成mesh, 也就是一些點,三角形的集合
- 3. 坐標變換
- 4. 使用68個關鍵點做fit
- 轉載請注明出處
這個代碼的主要內容就是根據一些隨機的參數從3d模型渲染到2d圖片
然后從圖片再變換回去
代碼解析
1. 載入模型
bfm = MorphabelModel('Data/BFM/Out/BFM.mat')# 這里面初始化的參數有: 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 # 頂點的個數self.ntri = self.model['tri'].shape[0] # 三角形的個數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'] # 關鍵點索引self.triangles = self.model['tri']self.full_triangles = np.vstack((self.model['tri'], self.model['tri_mouth'])) # 按行堆疊, 例如兩個(1, 3)成為(2, 3)2. 生成mesh, 也就是一些點,三角形的集合
sp = bfm.get_shape_para('random') ep = bfm.get_exp_para('random') # 上面就是生成一些隨機的形狀與表情參數vertices = bfm.generate_vertices(sp, ep) # 模型所有不包含顏色后加和的點tp = bfm.get_tex_para('random') colors = bfm.generate_colors(tp) colors = np.minimum(np.maximum(colors, 0), 1)- 看看這個generate_vertices, 輸入形狀系數和表情系數,返回頂點, 大小是(nver, 3)
- 這個generated_colors是根據紋理系數生成顏色, 其實這里并沒有對
紋理也就是顏色做后續的fit, 只不過是用一個隨機數乘了原來的系數
3. 坐標變換
- 指定了s, R, t等縮放旋轉位移參數, 然后把3D的點變到2D
4. 使用68個關鍵點做fit
x = projected_vertices[bfm.kpt_ind, :2] # 這個是相機坐標系下的人臉關鍵點X_ind = bfm.kpt_ind # index of keypoints in 3DMM. fixed. # fit 根據二維點來解出對應的3d參數叫fit fitted_sp, fitted_ep, fitted_s, fitted_angles, fitted_t = bfm.fit(x, X_ind, max_iter = 3)- 這里的fit算法里面有個黃金標準算法, 網上沒有講的很深入的, 同時現在大多數是用深度學習的方法fit了, 這個先占坑
這里的fit結果有5個參數, 分別是形狀, 表情, s, R, t
總結
以上是生活随笔為你收集整理的三维人脸重建:精读3dmm.py的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java设计模式-外观模式(Facade
- 下一篇: C# 6.0语法新特性体验(二)