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
77f271f1
Commit
77f271f1
authored
Jun 30, 2015
by
Patrik Huber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved some function implementations into headers and changed to snake_case
parent
9f2bf891
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
35 deletions
+36
-35
examples/fit_model.cpp
examples/fit_model.cpp
+3
-3
include/eos/fitting/AffineCameraEstimation.hpp
include/eos/fitting/AffineCameraEstimation.hpp
+16
-4
include/eos/render/utils.hpp
include/eos/render/utils.hpp
+17
-4
src/eos/fitting/AffineCameraEstimation.cpp
src/eos/fitting/AffineCameraEstimation.cpp
+0
-9
src/eos/render/utils.cpp
src/eos/render/utils.cpp
+0
-15
No files found.
examples/fit_model.cpp
View file @
77f271f1
...
@@ -167,7 +167,7 @@ int main(int argc, char *argv[])
...
@@ -167,7 +167,7 @@ int main(int argc, char *argv[])
vertexIndices
.
emplace_back
(
vertexIdx
);
vertexIndices
.
emplace_back
(
vertexIdx
);
imagePoints
.
emplace_back
(
landmarks
[
i
]);
imagePoints
.
emplace_back
(
landmarks
[
i
]);
}
}
catch
(
std
::
out_of_range
&
e
)
{
catch
(
const
std
::
out_of_range
&
)
{
// just continue if the point isn't defined in the mapping
// just continue if the point isn't defined in the mapping
}
}
++
ibugId
;
++
ibugId
;
...
@@ -178,7 +178,7 @@ int main(int argc, char *argv[])
...
@@ -178,7 +178,7 @@ int main(int argc, char *argv[])
// Draw the mean-face landmarks projected using the estimated camera:
// Draw the mean-face landmarks projected using the estimated camera:
for
(
auto
&&
vertex
:
modelPoints
)
{
for
(
auto
&&
vertex
:
modelPoints
)
{
Vec2f
screenPoint
=
fitting
::
project
A
ffine
(
vertex
,
affineCam
,
image
.
cols
,
image
.
rows
);
Vec2f
screenPoint
=
fitting
::
project
_a
ffine
(
vertex
,
affineCam
,
image
.
cols
,
image
.
rows
);
cv
::
circle
(
outimg
,
cv
::
Point2f
(
screenPoint
),
5.0
f
,
{
0.0
f
,
255.0
f
,
0.0
f
});
cv
::
circle
(
outimg
,
cv
::
Point2f
(
screenPoint
),
5.0
f
,
{
0.0
f
,
255.0
f
,
0.0
f
});
}
}
...
@@ -193,7 +193,7 @@ int main(int argc, char *argv[])
...
@@ -193,7 +193,7 @@ int main(int argc, char *argv[])
// Draw the projected points again, this time using the fitted model shape:
// Draw the projected points again, this time using the fitted model shape:
for
(
auto
&&
idx
:
vertexIndices
)
{
for
(
auto
&&
idx
:
vertexIndices
)
{
Vec4f
modelPoint
(
mesh
.
vertices
[
idx
][
0
],
mesh
.
vertices
[
idx
][
1
],
mesh
.
vertices
[
idx
][
2
],
mesh
.
vertices
[
idx
][
3
]);
Vec4f
modelPoint
(
mesh
.
vertices
[
idx
][
0
],
mesh
.
vertices
[
idx
][
1
],
mesh
.
vertices
[
idx
][
2
],
mesh
.
vertices
[
idx
][
3
]);
Vec2f
screenPoint
=
fitting
::
project
A
ffine
(
modelPoint
,
affineCam
,
image
.
cols
,
image
.
rows
);
Vec2f
screenPoint
=
fitting
::
project
_a
ffine
(
modelPoint
,
affineCam
,
image
.
cols
,
image
.
rows
);
cv
::
circle
(
outimg
,
cv
::
Point2f
(
screenPoint
),
3.0
f
,
{
0.0
f
,
0.0
f
,
255.0
f
});
cv
::
circle
(
outimg
,
cv
::
Point2f
(
screenPoint
),
3.0
f
,
{
0.0
f
,
0.0
f
,
255.0
f
});
}
}
...
...
include/eos/fitting/AffineCameraEstimation.hpp
View file @
77f271f1
...
@@ -22,6 +22,8 @@
...
@@ -22,6 +22,8 @@
#ifndef AFFINECAMERAESTIMATION_HPP_
#ifndef AFFINECAMERAESTIMATION_HPP_
#define AFFINECAMERAESTIMATION_HPP_
#define AFFINECAMERAESTIMATION_HPP_
#include "eos/render/utils.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/core/core.hpp"
#include <vector>
#include <vector>
...
@@ -51,13 +53,23 @@ cv::Mat estimateAffineCamera(std::vector<cv::Vec2f> imagePoints, std::vector<cv:
...
@@ -51,13 +53,23 @@ cv::Mat estimateAffineCamera(std::vector<cv::Vec2f> imagePoints, std::vector<cv:
* also flips the y-axis (the image origin is top-left, while in
* also flips the y-axis (the image origin is top-left, while in
* clip space top is +1 and bottom is -1).
* clip space top is +1 and bottom is -1).
*
*
* Note: Assumes the affine camera matrix only projects from world
* to clip space, because a subsequent window transform is applied.
*
* @param[in] vertex A vertex in 3D space. vertex[3] = 1.0f.
* @param[in] vertex A vertex in 3D space. vertex[3] = 1.0f.
* @param[in] affine
CameraM
atrix A 3x4 affine camera matrix.
* @param[in] affine
_camera_m
atrix A 3x4 affine camera matrix.
* @param[in] screen
W
idth Width of the screen or window used for projection.
* @param[in] screen
_w
idth Width of the screen or window used for projection.
* @param[in] screen
H
eight Height of the screen or window used for projection.
* @param[in] screen
_h
eight Height of the screen or window used for projection.
* @return A vector with x and y coordinates transformed to screen coordinates.
* @return A vector with x and y coordinates transformed to screen coordinates.
*/
*/
cv
::
Vec2f
projectAffine
(
cv
::
Vec4f
vertex
,
cv
::
Mat
affineCameraMatrix
,
int
screenWidth
,
int
screenHeight
);
inline
cv
::
Vec2f
project_affine
(
cv
::
Vec4f
vertex
,
cv
::
Mat
affine_camera_matrix
,
int
screen_width
,
int
screen_height
)
{
// Transform to clip space:
cv
::
Mat
clip_coords
=
affine_camera_matrix
*
cv
::
Mat
(
vertex
);
// Take the x and y coordinates in clip space and apply the window transform:
cv
::
Vec2f
screen_coords
=
render
::
clip_to_screen_space
(
cv
::
Vec2f
(
clip_coords
.
rowRange
(
0
,
2
)),
screen_width
,
screen_height
);
return
screen_coords
;
};
}
/* namespace fitting */
}
/* namespace fitting */
}
/* namespace eos */
}
/* namespace eos */
...
...
include/eos/render/utils.hpp
View file @
77f271f1
...
@@ -39,12 +39,25 @@ namespace eos {
...
@@ -39,12 +39,25 @@ namespace eos {
* we flip y at the end.
* we flip y at the end.
* Qt: Origin top-left. OpenGL: bottom-left. OCV: top-left.
* Qt: Origin top-left. OpenGL: bottom-left. OCV: top-left.
*
*
* @param[in] clip
C
oordinates A point in clip coordinates.
* @param[in] clip
_c
oordinates A point in clip coordinates.
* @param[in] screen
W
idth Width of the screen or window.
* @param[in] screen
_w
idth Width of the screen or window.
* @param[in] screen
H
eight Height of the screen or window.
* @param[in] screen
_h
eight Height of the screen or window.
* @return A vector with x and y coordinates transformed to screen space.
* @return A vector with x and y coordinates transformed to screen space.
*/
*/
cv
::
Vec2f
clipToScreenSpace
(
cv
::
Vec2f
clipCoordinates
,
int
screenWidth
,
int
screenHeight
);
inline
cv
::
Vec2f
clip_to_screen_space
(
cv
::
Vec2f
clip_coordinates
,
int
screen_width
,
int
screen_height
)
{
// Window transform:
float
x_ss
=
(
clip_coordinates
[
0
]
+
1.0
f
)
*
(
screen_width
/
2.0
f
);
float
y_ss
=
screen_height
-
(
clip_coordinates
[
1
]
+
1.0
f
)
*
(
screen_height
/
2.0
f
);
// also flip y; Qt: Origin top-left. OpenGL: bottom-left.
return
cv
::
Vec2f
(
x_ss
,
y_ss
);
/* Note: What we do here is equivalent to
x_w = (x * vW/2) + vW/2;
However, Shirley says we should do:
x_w = (x * vW/2) + (vW-1)/2;
(analogous for y)
Todo: Check the consequences.
*/
};
/**
/**
* Transforms a point from image (screen) coordinates to
* Transforms a point from image (screen) coordinates to
...
...
src/eos/fitting/AffineCameraEstimation.cpp
View file @
77f271f1
...
@@ -144,14 +144,5 @@ Mat estimateAffineCamera(vector<Vec2f> imagePoints, vector<Vec4f> modelPoints)
...
@@ -144,14 +144,5 @@ Mat estimateAffineCamera(vector<Vec2f> imagePoints, vector<Vec4f> modelPoints)
return
P_Affine
;
return
P_Affine
;
}
}
cv
::
Vec2f
projectAffine
(
cv
::
Vec4f
vertex
,
cv
::
Mat
affineCameraMatrix
,
int
screenWidth
,
int
screenHeight
)
{
// Transform to clip space:
Mat
clipCoords
=
affineCameraMatrix
*
Mat
(
vertex
);
// Take the x and y coordinates in clip space and apply the window transform:
cv
::
Vec2f
screenCoords
=
render
::
clipToScreenSpace
(
cv
::
Vec2f
(
clipCoords
.
rowRange
(
0
,
2
)),
screenWidth
,
screenHeight
);
return
screenCoords
;
}
}
/* namespace fitting */
}
/* namespace fitting */
}
/* namespace eos */
}
/* namespace eos */
src/eos/render/utils.cpp
View file @
77f271f1
...
@@ -24,21 +24,6 @@ using cv::Vec2f;
...
@@ -24,21 +24,6 @@ using cv::Vec2f;
namespace
eos
{
namespace
eos
{
namespace
render
{
namespace
render
{
Vec2f
clipToScreenSpace
(
Vec2f
clipCoordinates
,
int
screenWidth
,
int
screenHeight
)
{
// Window transform:
float
x_ss
=
(
clipCoordinates
[
0
]
+
1.0
f
)
*
(
screenWidth
/
2.0
f
);
float
y_ss
=
screenHeight
-
(
clipCoordinates
[
1
]
+
1.0
f
)
*
(
screenHeight
/
2.0
f
);
// also flip y; Qt: Origin top-left. OpenGL: bottom-left.
return
Vec2f
(
x_ss
,
y_ss
);
/* Note: What we do here is equivalent to
x_w = (x * vW/2) + vW/2;
However, Shirley says we should do:
x_w = (x * vW/2) + (vW-1)/2;
(analogous for y)
Todo: Check the consequences.
*/
}
Vec2f
screenToClipSpace
(
Vec2f
screenCoordinates
,
int
screenWidth
,
int
screenHeight
)
Vec2f
screenToClipSpace
(
Vec2f
screenCoordinates
,
int
screenWidth
,
int
screenHeight
)
{
{
float
x_cs
=
screenCoordinates
[
0
]
/
(
screenWidth
/
2.0
f
)
-
1.0
f
;
float
x_cs
=
screenCoordinates
[
0
]
/
(
screenWidth
/
2.0
f
)
-
1.0
f
;
...
...
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