【发布时间】:2020-07-04 10:39:54
【问题描述】:
我从 GitHub 下载了一个 webcam_face_pose_ex.cpp 文件,现在我想在我的 Mac 上编译和运行它。
#include <dlib/opencv.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
#include <X11/Xlib.h>
using namespace dlib;
using namespace std;
int main()
{
try
{
cv::VideoCapture cap(0);
if (!cap.isOpened())
{
cerr << "Unable to connect to camera" << endl;
return 1;
}
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;
if (!cap.read(temp))
{
break;
}
// 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://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl;
cout << endl << e.what() << endl;
}
catch(exception& e)
{
cout << e.what() << endl;
}
}
我尝试了 g++ webcam_face_pose_ex.cpp 命令,但我得到了:
webcam_face_pose_ex.cpp:30:10: fatal error: 'dlib/opencv.h' file not found
#include <dlib/opencv.h>
^~~~~~~~~~~~~~~
1 error generated.
想知道我能做些什么来解决这个问题吗?
【问题讨论】:
-
嗨,欢迎来到 Stack Overflow!请首先发布您尝试编译的代码的minimal reproducible example,以便我们可以帮助解决与您相同的问题并告诉您如何解决它。
-
您需要一个
-I<path to OpenCV include folder>并使用它,您还需要-L<Path to OpenCV library>和-l<Danged if I can remember the name of the Open CV library at the moment> -
嘿@Alex 这将不得不进入你的问题。当您粘贴它时,突出显示它并单击 { } 代码按钮以使其格式化。
-
@CausingUnderflowsEverywhere 谢谢我用我认为导致错误的代码编辑了帖子。
-
嘿@Alex 你为什么要编译那个特定的文件?
标签: c++