Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
eos
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Richard Torenvliet
eos
Commits
0ac742dd
Commit
0ac742dd
authored
9 years ago
by
patrikhuber
Browse files
Options
Downloads
Patches
Plain Diff
Added try/catch to landmark and model loading
Also removed a few trailing whitespaces
parent
9ea01877
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/fit-model.cpp
+20
-6
20 additions, 6 deletions
examples/fit-model.cpp
with
20 additions
and
6 deletions
examples/fit-model.cpp
+
20
−
6
View file @
0ac742dd
...
...
@@ -70,7 +70,7 @@ LandmarkCollection<cv::Vec2f> read_pts_landmarks(std::string filename)
if
(
!
file
.
is_open
())
{
throw
std
::
runtime_error
(
string
(
"Could not open landmark file: "
+
filename
));
}
string
line
;
// Skip the first 3 lines, they're header lines:
getline
(
file
,
line
);
// 'version: 1'
...
...
@@ -91,7 +91,7 @@ LandmarkCollection<cv::Vec2f> read_pts_landmarks(std::string filename)
throw
std
::
runtime_error
(
string
(
"Landmark format error while parsing the line: "
+
line
));
}
// From the iBug website:
// "Please note that the re-annotated data for this challenge are saved in the Matlab convention of 1 being
// "Please note that the re-annotated data for this challenge are saved in the Matlab convention of 1 being
// the first index, i.e. the coordinates of the top left pixel in an image are x=1, y=1."
// ==> So we shift every point by 1:
landmark
.
coordinates
[
0
]
-=
1.0
f
;
...
...
@@ -147,8 +147,22 @@ int main(int argc, char *argv[])
// Load the image, landmarks, LandmarkMapper and the Morphable Model:
Mat
image
=
cv
::
imread
(
imagefile
.
string
());
auto
landmarks
=
read_pts_landmarks
(
landmarksfile
.
string
());
morphablemodel
::
MorphableModel
morphable_model
=
morphablemodel
::
load_model
(
modelfile
.
string
());
LandmarkCollection
<
cv
::
Vec2f
>
landmarks
;
try
{
landmarks
=
read_pts_landmarks
(
landmarksfile
.
string
());
}
catch
(
const
std
::
runtime_error
&
e
)
{
cout
<<
"Error reading the landmarks: "
<<
e
.
what
()
<<
endl
;
return
EXIT_FAILURE
;
}
morphablemodel
::
MorphableModel
morphable_model
;
try
{
morphable_model
=
morphablemodel
::
load_model
(
modelfile
.
string
());
}
catch
(
const
std
::
runtime_error
&
e
)
{
cout
<<
"Error loading the Morphable Model: "
<<
e
.
what
()
<<
endl
;
return
EXIT_FAILURE
;
}
core
::
LandmarkMapper
landmark_mapper
=
mappingsfile
.
empty
()
?
core
::
LandmarkMapper
()
:
core
::
LandmarkMapper
(
mappingsfile
);
// Draw the loaded landmarks:
...
...
@@ -156,7 +170,7 @@ int main(int argc, char *argv[])
for
(
auto
&&
lm
:
landmarks
)
{
cv
::
rectangle
(
outimg
,
cv
::
Point2f
(
lm
.
coordinates
[
0
]
-
2.0
f
,
lm
.
coordinates
[
1
]
-
2.0
f
),
cv
::
Point2f
(
lm
.
coordinates
[
0
]
+
2.0
f
,
lm
.
coordinates
[
1
]
+
2.0
f
),
{
255
,
0
,
0
});
}
// Convert the landmarks to clip-space:
std
::
for_each
(
begin
(
landmarks
),
end
(
landmarks
),
[
&
image
](
Landmark
<
Vec2f
>&
lm
)
{
lm
.
coordinates
=
render
::
screen_to_clip_space
(
lm
.
coordinates
,
image
.
cols
,
image
.
rows
);
});
...
...
@@ -178,7 +192,7 @@ int main(int argc, char *argv[])
vertex_indices
.
emplace_back
(
vertex_idx
);
image_points
.
emplace_back
(
landmarks
[
i
].
coordinates
);
}
// Estimate the camera from the 2D - 3D point correspondences
Mat
affine_cam
=
fitting
::
estimate_affine_camera
(
image_points
,
model_points
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment