function [face,vert,extra] = read_obj(filename)
fid = fopen(filename);
if fid<0
error(['cannot open ' filename '.']);
end
face = [];
vert = [];
vt = [];
vn = [];
while true
line = get_next_line(fid);
if line == -1
break;
end
if length(line) < 2
continue
end
[format,sz] = get_format(line);
if strcmpi(line(1:2), 'vt')
fseek(fid,-length(line),'cof');
data = fscanf(fid,format);
vt = [vt;reshape(data,[sz,length(data)/sz])'];
fseek(fid,-1,'cof');
elseif strcmpi(line(1:2), 'vn')
fseek(fid,-length(line),'cof');
data = fscanf(fid,format);
vn = [vn;reshape(data,[sz,length(data)/sz])'];
fseek(fid,-1,'cof');
elseif strcmpi(line(1), 'v')
fseek(fid,-length(line),'cof');
data = fscanf(fid,format);
vert = [vert;reshape(data,[sz,length(data)/sz])'];
fseek(fid,-1,'cof');
elseif strcmpi(line(1), 'f')
fseek(fid,-length(line),'cof');
data = fscanf(fid,format);
face = [face;reshape(data,[sz,length(data)/sz])'];
fseek(fid,-1,'cof');
end
end
fclose(fid);
has_vt = ~isempty(vt);
has_vn = ~isempty(vn);
if has_vt
extra.vt = vt;
end
if has_vn
extra.vn = vn;
end
extra.face = face;
extra.vert = vert;
if size(face,2) == 6
face = face(:,[1 3 5]);
elseif size(face,2) == 9
face = face(:,[1 4 7]);
end
if size(vert,2) > 3
vert = vert(:,1:3);
end
function line = get_next_line(fid)
% read next line, skip comment, blank line and eof
line = fgets(fid);
if line == -1
return
end
while isempty(strtrim(line)) || line(1) == '#'
line = fgets(fid);
if line == -1
line = '';
return;
end
end
function [format,sz] = get_format(str)
% determine the format of input str
sn = '[\-+]?(?:\d*\.|)\d+\.?(?:[eE][\-+]?\d+|)'; % match number
format = regexprep(str,sn,'%f');
[~,splitstr] = regexp(str,sn,'match');
sz = length(splitstr);
没有合适的资源?快使用搜索试试~ 我知道了~
3D Morphable Model pca algorithm
共10个文件
m:5个
xls:3个
obj:1个
5星 · 超过95%的资源 需积分: 16 20 下载量 106 浏览量
2018-10-21
15:07:44
上传
评论 3
收藏 6.8MB RAR 举报
温馨提示
实现了论文A Morphable Model For The Synthesis Of 3D Faces中的pca算法,并随机生成一张人脸
资源推荐
资源详情
资源评论
收起资源包目录
pca_basis_matlab.rar (10个子文件)
pca_basis_matlab
face.obj 333KB
shapepca.xls 12.66MB
read_obj.m 2KB
standard.xls 25KB
GetFiles.m 278B
get_shape.m 533B
write_obj.m 745B
average.xls 600KB
face.obj.meshcache 653KB
smodel.m 1KB
共 10 条
- 1
资源评论
- HU_LSS2018-12-12请问一下这个代码实现的步骤是什么样的?
展风free
- 粉丝: 2
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功