dlib - 面部检测器错误:无法将std :: vector <dlib :: rectangle>转换为int

时间:2018-01-25 16:48:09

标签: c++ parameter-passing dlib

我尝试在复制此代码的某些部分时尝试在dlib中移动几个步骤突然停止 http://dlib.net/face_landmark_detection_ex.cpp.html

这是我到目前为止所得到的

// video and image capturing
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/video.hpp"

//Dlib libraries
#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 "dlib/image_io.h"

#include <iostream>

using namespace dlib;
using namespace cv;
using namespace std;

int main()
{

    frontal_face_detector detector = get_frontal_face_detector();
    shape_predictor sp;


    array2d<rgb_pixel> img;

    VideoCapture cap("/home/francesco/Downloads/05-1.avi");

    if (!cap.isOpened())
    {
        cout << "Cannot open the video file. \n";
        return -1;
    }

    double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per second

    namedWindow("UNLTD", CV_WINDOW_AUTOSIZE);
    //For future: WINDOW_OPENGL instead of WINDOW_AUTOSIZE;

    while(1)
    {
        Mat frame;
        //Mat is basic image container, frame is an object of Mat.


        std::vector<rectangle> dets = detector(img);

        if (!cap.read(frame))
        //read() decodes and capture the next frame, if it fails, break
        {
            cout << "Failed to read the video. \n";
            break;

        }

        imshow("UNLTD", frame);

        if(waitKey(30) == 27) //ESCAPE
        {
            break;
        }
    }

    return 0;

}

目前,我希望该软件能做的就是播放视频而不会返回错误但不幸的是我得到了这个

error: template argument 1 is invalid
error: template argument 2 is invalid
error: cannot convert 'std::vector<dlib::rectangle>' to 'int' in initialization

指的是

 std::vector<rectangle> dets = detector(img);

我从官方dlib.net网站提供的示例中复制/粘贴。

构建日志:

g++ -Wall -fexceptions -g -std=c++11 -I../../../../opt/opencv/include/opencv -I../../../../opt/opencv/include/opencv2 -c /home/francesco/dlib/OpenCV_videoPlayer_v01/main.cpp -o obj/Debug/main.o
/home/francesco/dlib/OpenCV_videoPlayer_v01/main.cpp: In function ‘int main()’:
/home/francesco/dlib/OpenCV_videoPlayer_v01/main.cpp:46:30: error: template argument 1 is invalid
     std::vector<rectangle> dets = detector(img);
                          ^
/home/francesco/dlib/OpenCV_videoPlayer_v01/main.cpp:46:30: error: template argument 2 is invalid
/home/francesco/dlib/OpenCV_videoPlayer_v01/main.cpp:46:51: error: cannot convert ‘std::vector<dlib::rectangle>’ to ‘int’ in initialization
     std::vector<rectangle> dets = detector(img);
                                               ^

此处提供完整代码 http://dlib.net/face_landmark_detection_ex.cpp.html

任何想法?

1 个答案:

答案 0 :(得分:3)

我最好的猜测是问题在于rectangle标识符,正如我在文档中看到的那样,它在cvdlib名称空间中定义。对于多个名称空间,using namespace ...通常不是一个好主意。尝试删除using namespace cv并相应地为cv命名空间中的所有标识符添加前缀。