Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
dac39d2b
Commit
dac39d2b
authored
Nov 15, 2014
by
Davis King
Browse files
Added an example showing how to use OpenCV's frame grabber
for face pose estimation.
parent
cc70a8e0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
0 deletions
+102
-0
examples/CMakeLists.txt
examples/CMakeLists.txt
+12
-0
examples/webcam_face_pose_ex.cpp
examples/webcam_face_pose_ex.cpp
+90
-0
No files found.
examples/CMakeLists.txt
View file @
dac39d2b
...
...
@@ -97,3 +97,15 @@ add_example(train_object_detector)
add_example
(
train_shape_predictor_ex
)
add_example
(
using_custom_kernels_ex
)
add_example
(
xml_parser_ex
)
find_package
(
OpenCV
)
if
(
OpenCV_FOUND
)
include_directories
(
${
OpenCV_INCLUDE_DIRS
}
)
ADD_EXECUTABLE
(
webcam_face_pose_ex webcam_face_pose_ex.cpp
)
TARGET_LINK_LIBRARIES
(
webcam_face_pose_ex dlib
${
OpenCV_LIBS
}
)
endif
()
examples/webcam_face_pose_ex.cpp
0 → 100644
View file @
dac39d2b
// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/*
This example program shows how to find frontal human faces in an image and
estimate their pose. The pose takes the form of 68 landmarks. These are
points on the face such as the corners of the mouth, along the eyebrows, on
the eyes, and so forth.
This example is essentially just a version of the face_landmark_detection_ex.cpp
example modified to use OpenCV's VideoCapture object to read from a camera instead
of files.
Finally, note that the face detector is fastest when compiled with at least
SSE2 instructions enabled. So if you are using a PC with an Intel or AMD
chip then you should enable at least SSE2 instructions. If you are using
cmake to compile this program you can enable them by using one of the
following commands when you create the build project:
cmake path_to_dlib_root/examples -DUSE_SSE2_INSTRUCTIONS=ON
cmake path_to_dlib_root/examples -DUSE_SSE4_INSTRUCTIONS=ON
cmake path_to_dlib_root/examples -DUSE_AVX_INSTRUCTIONS=ON
This will set the appropriate compiler options for GCC, clang, Visual
Studio, or the Intel compiler. If you are using another compiler then you
need to consult your compiler's manual to determine how to enable these
instructions. Note that AVX is the fastest but requires a CPU from at least
2011. SSE4 is the next fastest and is supported by most current machines.
*/
#include <dlib/opencv.h>
#include <opencv2/highgui/highgui.hpp>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/gui_widgets.h>
using
namespace
dlib
;
using
namespace
std
;
int
main
()
{
try
{
cv
::
VideoCapture
cap
(
0
);
image_window
win
;
// Load face detection and pose estimation models.
frontal_face_detector
detector
=
get_frontal_face_detector
();
shape_predictor
pose_model
;
deserialize
(
"shape_predictor_68_face_landmarks.dat"
)
>>
pose_model
;
// Grab and process frames until the main window is closed by the user.
while
(
!
win
.
is_closed
())
{
// Grab a frame
cv
::
Mat
temp
;
cap
>>
temp
;
// Turn OpenCV's Mat into something dlib can deal with. Note that this just
// wraps the Mat object, it doesn't copy anything. So cimg is only valid as
// long as temp is valid. Also don't do anything to temp that would cause it
// to reallocate the memory which stores the image as that will make cimg
// contain dangling pointers. This basically means you shouldn't modify temp
// while using cimg.
cv_image
<
bgr_pixel
>
cimg
(
temp
);
// Detect faces
std
::
vector
<
rectangle
>
faces
=
detector
(
cimg
);
// Find the pose of each face.
std
::
vector
<
full_object_detection
>
shapes
;
for
(
unsigned
long
i
=
0
;
i
<
faces
.
size
();
++
i
)
shapes
.
push_back
(
pose_model
(
cimg
,
faces
[
i
]));
// Display it all on the screen
win
.
clear_overlay
();
win
.
set_image
(
cimg
);
win
.
add_overlay
(
render_face_detections
(
shapes
));
}
}
catch
(
serialization_error
&
e
)
{
cout
<<
"You need dlib's default face landmarking model file to run this example."
<<
endl
;
cout
<<
"You can get it from the following URL: "
<<
endl
;
cout
<<
" http://sourceforge.net/projects/dclib/files/dlib/v18.10/shape_predictor_68_face_landmarks.dat.bz2"
<<
endl
;
cout
<<
endl
<<
e
.
what
()
<<
endl
;
}
catch
(
exception
&
e
)
{
cout
<<
e
.
what
()
<<
endl
;
}
}
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