C++ opencv检测多尺度
我正在尝试学习opencv和对象检测。我在opencv示例中使用了objecdetection.cpp,当我运行它时,我得到了这个错误 级联加载非常好,相机也是唯一的问题是detectmultiscale,因为每当我把它注释掉时,程序不会崩溃 以下是objectdecetion2.cpp的代码C++ opencv检测多尺度,c++,windows,opencv,C++,Windows,Opencv,我正在尝试学习opencv和对象检测。我在opencv示例中使用了objecdetection.cpp,当我运行它时,我得到了这个错误 级联加载非常好,相机也是唯一的问题是detectmultiscale,因为每当我把它注释掉时,程序不会崩溃 以下是objectdecetion2.cpp的代码 #include "opencv2/objdetect.hpp" #include "opencv2/videoio.hpp" #include "opencv2/highgui
#include "opencv2/objdetect.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
/** Function Headers */
void detectAndDisplay(Mat frame);
/** Global variables */
String face_cascade_name = "..\\Debug\\haarcascade_frontalface_alt.xml";
String eyes_cascade_name = "..\\Debug\\haarcascade_eye_tree_eyeglasses.xml";
CascadeClassifier face_cascade;
CascadeClassifier eyes_cascade;
String window_name = "Capture - Face detection";
/**
* @function main
*/
int main(void)
{
VideoCapture capture;
Mat frame;
//-- 1. Load the cascade
if (!face_cascade.load(face_cascade_name)){ printf("--(!)Error loading face cascade\n"); return -1; };
if (!eyes_cascade.load(eyes_cascade_name)){ printf("--(!)Error loading eyes cascade\n"); return -1; };
//-- 2. Read the video stream
capture.open(0);
if (!capture.isOpened()) { printf("--(!)Error opening video capture\n"); return -1; }
while (capture.read(frame))
{
if (frame.empty())
{
printf(" --(!) No captured frame -- Break!");
break;
}
//-- 3. Apply the classifier to the frame
detectAndDisplay(frame);
//-- bail out if escape was pressed
int c = waitKey(10);
if ((char)c == 27) { break; }
}
return 0;
}
/**
* @function detectAndDisplay
*/
void detectAndDisplay(Mat frame)
{
std::vector<Rect> faces;
Mat frame_gray;
cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
equalizeHist(frame_gray, frame_gray);
face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0, Size(80, 80));
imshow(window_name, frame);
}
#包括“opencv2/objdetect.hpp”
#包括“opencv2/videoio.hpp”
#包括“opencv2/highgui.hpp”
#包括“opencv2/imgproc.hpp”
#包括
#包括
使用名称空间std;
使用名称空间cv;
/**函数头*/
空隙检测和显示(垫架);
/**全局变量*/
字符串face_cascade_name=“..\\Debug\\haarcascade_frontalface_alt.xml”;
字符串eyes\u cascade\u name=“..\\Debug\\haarcascade\u eye\u tree\u eyegories.xml”;
层叠式分级机;
级联效应;
字符串窗口\u name=“捕获-人脸检测”;
/**
*@主功能
*/
内部主(空)
{
视频捕获;
垫架;
//--1.加载叶栅
如果(!face_cascade.load(face_cascade_name)){printf(“-(!)错误加载face cascade\n”);返回-1;};
如果(!eyes_cascade.load(eyes_cascade_name)){printf(“-(!)加载eyes cascade时出错\n”);返回-1;};
//--2.读取视频流
capture.open(0);
如果(!capture.isOpened()){printf(“-(!)打开视频捕获时出错,\n”);返回-1;}
while(捕获.读取(帧))
{
if(frame.empty())
{
printf(“--(!)未捕获帧--Break!”);
打破
}
//--3.将分类器应用于框架
检测显示(帧);
//--如果迫于逃生的压力,就进行救援
int c=等待键(10);
如果((char)c==27){break;}
}
返回0;
}
/**
*@功能检测和显示
*/
空隙检测和显示(垫架)
{
向量面;
垫子框架为灰色;
CVT颜色(框架、框架灰、颜色灰);
均衡器历史(帧灰,帧灰);
face_cascade.检测多尺度(frame_gray,faces,1.1,2,0,大小(80,80));
imshow(窗口名称、框架);
}
您可能遇到OpenCV错误,如下所述:
您发布的代码在我看来是正确的,否则。您发布的代码是正确的!但我怀疑你的opencv配置不对!如果您在windows上工作,请检查您的.dll文件和lib文件 你不混合调试/发布DLL吗?混合调试/发布DLL是什么意思?我一步一步地跟着这个视频讲述如何设置opencv是的,我知道这一点,因为你的代码与opencv示例代码相同。所以在配置上有些地方是错误的。你使用opencv 3.0.0了吗?没有,也许我以后会尝试opencv 2.4,我的朋友说3.0有漏洞?是真的吗?所以我应该把我的形象放大?