MATLAB代码:
% addpath(genpath(pwd))
% --> model
% 载入原始的BFM模型
load('raw/01_MorphableModel.mat');
% 载入3dffa中 BFM信息
load('3ddfa/model_info.mat');
% BFM 处理后 共有 53490个点
% trimIndex: 53215x1, trimIndex_f: 53215*3
% 点的索引, 维度是53251,对应BFM中的 53490个点
trimIndex_f = [trimIndex*3-2, 3*trimIndex-1, 3*trimIndex]';
trimIndex_f = trimIndex_f(:); % 维度 159645 * 1
model.shapeMU = shapeMU(trimIndex_f, :); % 平均形状向量 159645 * 1
model.shapePC = shapePC(trimIndex_f, :); % 形状PCA降维矩阵 159645 * 199
model.shapeEV = shapeEV; % 形状正交空间的系数; 199*1
model.texMU = texMU(trimIndex_f, :); % 平均纹理向量159645 * 1
model.texPC = texPC(trimIndex_f, :); % 纹理PCA降维矩阵 159645 * 199
model.texEV = texEV; % 纹理正交空间的系数 199*1
model.tri = tri; % 三角格坐标, 维度 105840 * 3
model.kpt_ind = keypoints; % 68个特征点
% 存储相关模型信息
model_info.kpt_ind = keypoints;
model_info.trimIndex = trimIndex;
model_info.symlist = symlist; % 对称点信息 大小为 2*26720
model_info.symlist_tri = symlist_tri; % 对称网格信息, 大小 2*52937
model_info.segbin = segbin(trimIndex, :)'; % 获得掩模
model_info.segbin_tri = segbin_tri'; % 获得三角格掩模
% 2 载入表情模型
load('3ddfa/Model_Expression.mat');
model.expMU = mu_exp; % 平均表情向量 159645 * 1
model.expPC = w_exp; % 表情PCA降维矩阵 159645 * 29
model.expEV = sigma_exp; % 表情系数 29*1
% 159645 / 3 = 53215, 不够 53490 个点, 缺少 275 点
% 3 加载嘴唇三角格信息
load('3ddfa/Model_tri_mouth');
model.tri_mouth = tri_mouth; % 嘴唇坐标, 3*107
model_info.tri_mouth = tri_mouth;
% 4. 载入 脸部轮廓信息
load('3ddfa/Model_face_contour_trimed.mat');
model_info.face_contour = face_contour; % 人脸轮廓点索引, 维度28
model_info.face_contour_line = face_contour_line; % 人脸轮廓线索引 512
model_info.face_contour_front = face_contour_front; % 正面人脸轮廓线索引 28
model_info.face_contour_front_line = face_contour_front_line; % 正面人脸轮廓线索引 512
% 5 载入鼻子空洞
load('3ddfa/Modelplus_nose_hole.mat');
model_info.nose_hole = nose_hole; % 鼻子索引 142
model_info.nose_hole_right = nose_hole_right; % 右侧鼻子索引 71
model_info.nose_hole_left = nose_hole_left; % 左侧鼻子索引 71
% 6 parallel for key points
load('3ddfa/Modelplus_parallel.mat');
model_info.parallel = parallel;
model_info.parallel_face_contour = parallel_face_contour;
% 7. PNCC
% 从 提前 计算好的 vertex_code.mat 得到PNCC特征
copyfile('3ddfa/vertex_code.mat', 'Out/pncc_code.mat');
% 载入UV坐标, 计算方法来自 3DMMasSTN论文
load('stn/BFM_UV.mat');
uv_coords = UV(trimIndex, :)'; % 2*53215
% 修改不好的顶点
bad_ind = [10032, 10155, 10280];
round1 = [10033, 10158 ];
round2 = [10534, 10157, 10661];
round3 = [10916, 10286];
uv_coords(:, bad_ind(1)) = mean(uv_coords(:, round1), 2);
uv_coords(:, bad_ind(2)) = mean(uv_coords(:, round2), 2);
uv_coords(:, bad_ind(3)) = mean(uv_coords(:, round3), 2);
model_info.uv_coords = uv_coords';
UV = model_info.uv_coords;
% 添加嘴唇三角网络
tm_inner = model.tri_mouth;
tm_inner_add =[6420 6542 6664; %% add inner mouth triangles
6420 6294 6167;
6167 6297 6420;
6167 6297 6296;
6167 6296 6295;
6167 6295 6039;
6168 6295 6039];
ind_bad = 38;
all_ind = 1:size(tm_inner, 2);
tm_inner = tm_inner(:, setdiff(all_ind, bad_ind));
tm_inner = [tm_inner tm_inner_add'];
model_info.tri_mouth = tm_inner;
model.tri_mouth = tm_inner;
% save
clearvars -except model model_info UV
save 'Out/BFM.mat' model
save 'Out/BFM_info.mat' model_info
save 'Out/BFM_UV.mat' UV
% copyfile('3ddfa/pncc_code.mat', 'Out/pncc_code.mat')
对应文件: 此处 密码: b8la