Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
eos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Richard Torenvliet
eos
Commits
1c51f4c3
Commit
1c51f4c3
authored
Sep 26, 2016
by
Patrik Huber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Matlab script to convert the BFM to a raw binary file
parent
ee1c359a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
0 deletions
+88
-0
share/convert_bfm2009_to_raw_binary.m
share/convert_bfm2009_to_raw_binary.m
+88
-0
No files found.
share/convert_bfm2009_to_raw_binary.m
0 → 100644
View file @
1c51f4c3
% Converts the 2009 Basel Face Model (BFM, [1]) to a binary file that can be
% directly read byte for byte in C++. The workflow is to feed this
% generated "raw" binary file into the bfm-binary-to-cereal app, which
% reads this binary byte for byte and converts it to a cereal .bin file
% that is then readable by eos.
%
% [1]: A 3D Face Model for Pose and Illumination Invariant Face
% Recognition, P. Paysan, R. Knothe, B. Amberg, S. Romdhani, and T. Vetter,
% AVSS 2009.
% http://faces.cs.unibas.ch/bfm/main.php?nav=1-0&id=basel_face_model
%
% Developer notes:
% - The BFM data type is single, SFM is double
% - The BFM Matlab file contains the "unnormalised", orthonormal basis
% (as do the Surrey .scm files).
% - Domains:
% Colour: BFM: [0, 255], SFM: [0, 1].
% Shape: BFM: in mm (e.g. 50000), SFM: in cm, e.g. 50.
% (Note: I think that's wrong, since we have to divide by 1000.)
% - The BFM doesn't have any texture coordinates.
%
function
[]
=
convert_bfm2009_to_raw_binary
(
bfm_file
,
binary_out_file
)
if
(
~
exist
(
'bfm_file'
,
'var'
))
bfm_file
=
'D:/Github/data/bfm/PublicMM1/01_MorphableModel.mat'
;
end
if
(
~
exist
(
'binary_out_file'
,
'var'
))
binary_out_file
=
'bfm.raw'
;
end
bfm
=
load
(
bfm_file
);
f
=
fopen
(
binary_out_file
,
'w'
);
fwrite
(
f
,
size
(
bfm
.
shapeMU
,
1
),
'int32'
);
% num vertices times 3
fwrite
(
f
,
size
(
bfm
.
shapePC
,
2
),
'int32'
);
% number of basis vectors
% Write the shape mean:
for
i
=
1
:
size
(
bfm
.
shapeMU
,
1
)
fwrite
(
f
,
bfm
.
shapeMU
(
i
),
'float'
);
end
% Write the unnormalised shape PCA basis matrix:
% All of basis 1 will be written first, then basis 2, etc.
for
basis
=
1
:
size
(
bfm
.
shapePC
,
2
)
for
j
=
1
:
size
(
bfm
.
shapePC
,
1
)
% all data points of the basis
fwrite
(
f
,
bfm
.
shapePC
(
j
,
basis
),
'float'
);
end
end
% Write the shape eigenvalues:
for
i
=
1
:
size
(
bfm
.
shapeEV
,
1
)
fwrite
(
f
,
bfm
.
shapeEV
(
i
),
'float'
);
end
% Write num_triangles and the triangle list:
fwrite
(
f
,
size
(
bfm
.
tl
,
1
),
'int32'
);
for
i
=
1
:
size
(
bfm
.
tl
,
1
)
fwrite
(
f
,
bfm
.
tl
(
i
,
1
),
'int32'
);
fwrite
(
f
,
bfm
.
tl
(
i
,
2
),
'int32'
);
fwrite
(
f
,
bfm
.
tl
(
i
,
3
),
'int32'
);
end
% Now just exactly the same for the colour (albedo) model:
fwrite
(
f
,
size
(
bfm
.
texMU
,
1
),
'int32'
);
% num vertices times 3
fwrite
(
f
,
size
(
bfm
.
texPC
,
2
),
'int32'
);
% number of basis vectors
% Write the colour mean:
for
i
=
1
:
size
(
bfm
.
texMU
,
1
)
fwrite
(
f
,
bfm
.
texMU
(
i
),
'float'
);
end
% Write the unnormalised colour PCA basis matrix:
% All of basis 1 will be written first, then basis 2, etc.
for
basis
=
1
:
size
(
bfm
.
texPC
,
2
)
for
j
=
1
:
size
(
bfm
.
texPC
,
1
)
% all data points of the basis
fwrite
(
f
,
bfm
.
texPC
(
j
,
basis
),
'float'
);
end
end
% Write the colour eigenvalues:
for
i
=
1
:
size
(
bfm
.
texEV
,
1
)
fwrite
(
f
,
bfm
.
texEV
(
i
),
'float'
);
end
fclose
(
f
);
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment