dlib - face detector error: cannot convert std::vector<dlib::rectangle> to int
dlib - face detector error: cannot convert std::vector<dlib::rectangle> to int
我尝试在 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);
我copied/pasted来自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
有什么想法吗?
我最好的猜测是问题出在 rectangle
标识符上,在我查看文档时,它是在 cv
和 dlib
命名空间中定义的。 using namespace ...
对于多个命名空间通常不是一个好主意。尝试从 cv
命名空间中删除 using namespace cv
并相应地为所有标识符添加前缀。
我尝试在 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);
我copied/pasted来自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
有什么想法吗?
我最好的猜测是问题出在 rectangle
标识符上,在我查看文档时,它是在 cv
和 dlib
命名空间中定义的。 using namespace ...
对于多个命名空间通常不是一个好主意。尝试从 cv
命名空间中删除 using namespace cv
并相应地为所有标识符添加前缀。