MCPcopy Create free account
hub / github.com/davisking/dlib / main

Function main

examples/webcam_face_pose_ex.cpp:40–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38using namespace std;
39
40int main()
41{
42 try
43 {
44 cv::VideoCapture cap(0);
45 if (!cap.isOpened())
46 {
47 cerr << "Unable to connect to camera" << endl;
48 return 1;
49 }
50
51 image_window win;
52
53 // Load face detection and pose estimation models.
54 frontal_face_detector detector = get_frontal_face_detector();
55 shape_predictor pose_model;
56 deserialize("shape_predictor_68_face_landmarks.dat") >> pose_model;
57
58 // Grab and process frames until the main window is closed by the user.
59 while(!win.is_closed())
60 {
61 // Grab a frame
62 cv::Mat temp;
63 if (!cap.read(temp))
64 {
65 break;
66 }
67 // Turn OpenCV's Mat into something dlib can deal with. Note that this just
68 // wraps the Mat object, it doesn't copy anything. So cimg is only valid as
69 // long as temp is valid. Also don't do anything to temp that would cause it
70 // to reallocate the memory which stores the image as that will make cimg
71 // contain dangling pointers. This basically means you shouldn't modify temp
72 // while using cimg.
73 cv_image<bgr_pixel> cimg(temp);
74
75 // Detect faces
76 std::vector<rectangle> faces = detector(cimg);
77 // Find the pose of each face.
78 std::vector<full_object_detection> shapes;
79 for (unsigned long i = 0; i < faces.size(); ++i)
80 shapes.push_back(pose_model(cimg, faces[i]));
81
82 // Display it all on the screen
83 win.clear_overlay();
84 win.set_image(cimg);
85 win.add_overlay(render_face_detections(shapes));
86 }
87 }
88 catch(serialization_error& e)
89 {
90 cout << "You need dlib's default face landmarking model file to run this example." << endl;
91 cout << "You can get it from the following URL: " << endl;
92 cout << " http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl;
93 cout << endl << e.what() << endl;
94 }
95 catch(exception& e)
96 {
97 cout << e.what() << endl;

Callers

nothing calls this directly

Calls 10

render_face_detectionsFunction · 0.85
clear_overlayMethod · 0.80
deserializeFunction · 0.70
readMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
set_imageMethod · 0.45
add_overlayMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected