C++ Opencv中的人脸跟踪问题
我是opencv的新手,一开始我就在处理颜色、阈值,然后开始进行人脸跟踪。下面是我编写的代码,用我的网络摄像头的输入实现人脸跟踪矩形。问题是“face_cascade.detectMultiScale”填充的向量的大小变大,导致未处理的异常 我已经包括了所有的库和级联xml文件,我没有看到任何错误。为了便于调试,我在多尺度方法调用后添加了一个coutC++ Opencv中的人脸跟踪问题,c++,opencv,visual-studio-2012,face-detection,C++,Opencv,Visual Studio 2012,Face Detection,我是opencv的新手,一开始我就在处理颜色、阈值,然后开始进行人脸跟踪。下面是我编写的代码,用我的网络摄像头的输入实现人脸跟踪矩形。问题是“face_cascade.detectMultiScale”填充的向量的大小变大,导致未处理的异常 我已经包括了所有的库和级联xml文件,我没有看到任何错误。为了便于调试,我在多尺度方法调用后添加了一个cout #include "stdafx.h" #include "opencv2/imgproc/imgproc.hpp" #include "open
#include "stdafx.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{
//creating the classifier object used for the face detection
CascadeClassifier face_cascade;
//use the haarcascade_frontface_alt.xml library
face_cascade.load("haarcascade_frontalcatface.xml");
//setup camera
VideoCapture captureDevice;
captureDevice.open(0);
//setup image files used in the capture process
Mat capFrame;
Mat grayscaleFrame;
//create a window to present the results
namedWindow("output", 1);
//create a loop to capture and find the faces
while (true)
{
//capture a new image frame
captureDevice >> capFrame;
//convert captured Image to grayscale and equalize
cvtColor(capFrame, grayscaleFrame, CV_BGR2GRAY);
equalizeHist(grayscaleFrame, grayscaleFrame);
//create a vector array to store the faces found
std::vector<Rect> faces;
//find faces and store them in the vector array
face_cascade.detectMultiScale(grayscaleFrame, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30));
cout << faces.size();
//draw a rectangle on the face
for (int i = 0; i < faces.size(); i++)
{
Point pt1(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
Point pt2(faces[i].x, faces[i].y);
rectangle(capFrame, pt1, pt2, cvScalar(0, 255, 0, 0), 1, 8, 0);
}
//print the output
imshow("output", capFrame);
//pause for 33 ms
waitKey(33);
}
return 0;
}
我已经学习了很多关于人脸跟踪的教程,所有内容都与此类似。这是最简单的,即使这样也不行。
p、 s:不要担心xml文件。我已经尝试了所有的xml文件,这不会是一个问题
提前谢谢你首先,尝试一下地球上最简单的事情:
对输入错误也没什么帮助。至少它有助于明确每帧的实际检测数量。现在,我不认为错误在你的代码中,而是在你将你的程序链接到win的方式中。如果您严格地将发布libs(检查所有libs)链接到发布版本,并将调试libs链接到调试版本,请执行三重检查。
4292486918