0

I have compiled the dlib examples and the examples works fine. I then tried to write my own sample using c++.

So here is my code:

#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;
    }

}

In my compilation I am running the following:

g++ -I /../dlib-19.4/  cam.cpp -o camera

The dlib folder is under dlib-19.4.

During the linking... I am getting many errors

undefined reference to `cv::VideoCapture::VideoCapture(int)

undefined reference to `cv::VideoCapture::isOpened() const

.....

And it goes on and on....

Ideas?

  • You don't link to any library, hence the error. – arrowd Jul 25 '17 at 13:54
  • Thanks, I did later linked to the library I even installed the library directly on the linux with make install so I do not need to link it every time...still got issues. The way I have solved it is to use cmake.. the way the author of dlib build his examples... –  Jul 27 '17 at 16:32

0 Answers0