我编译了dlib示例,示例工作正常。 然后我尝试用c ++编写自己的样本。
所以这是我的代码:
#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/image_processing.h>
#include <dlib/gui_widgets.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;
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);
image_window win;
// Display it all on the screen
win.clear_overlay();
win.set_image(cimg);
}
}catch(exception& e)
{
cout << endl << e.what() << endl;
}
}
在我的编译中,我运行以下内容:
g++ -I /../dlib-19.4/ cam.cpp -o camera
dlib文件夹位于dlib-19.4。
在链接期间...我收到很多错误
undefined reference to `cv::VideoCapture::VideoCapture(int)
undefined reference to `cv::VideoCapture::isOpened() const
.....
它一直在继续......
想法?