我正在使用haar级联方法在c ++ visual studio中开发一个人脸检测算法。
在以下行应用程序退出,而相同的应用程序在linux环境中完美运行。
是否有可能导致此问题的opencv配置?
任何帮助都会非常棒。
frontfaceCascade.detectMultiScale(grey_image, faces, 1.1, 0, 0 |
CV_HAAR_SCALE_IMAGE, cv::Size(30, 30));
感谢。
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include <iostream>
#include <thread>
#include <stdlib.h>
#include <corecrt_math_defines.h>
using namespace std;
using namespace cv;
vector<Mat> Frames;
void getFrames(char* fileName);
cv::CascadeClassifier frontfaceCascade;
cv::CascadeClassifier sidefaceCascade;
int main(int argc, char *argv[]) {
if (argc < 2) {
cout << " enter file name: \n";
exit(1);
}
char* fileName = argv[1];
// if( !frontfaceCascade.load("lbpcascade_frontalface.xml")){
if (!frontfaceCascade.load("haarcascade_frontalface_default.xml")) {
std::cout << "Error Loading frontface haarcascade" << std::endl;
}
if (!sidefaceCascade.load("haarcascade_profileface.xml"))
{
std::cout << "Error Loading sideface haarcascade" << std::endl;
}
namedWindow("Faces", WINDOW_NORMAL);
resizeWindow("Faces", 100, 400);
moveWindow("Faces", 30, 100);
getFrames(fileName);
return 0;
}
void getFrames(char* fileName) {
cv::VideoCapture vcap(fileName);
if (!vcap.isOpened()) {
cout << "Error opening video stream or file" << endl;
return;
}
cv::Mat grey_image;
Mat img;
namedWindow("Frames", CV_WINDOW_AUTOSIZE);
resizeWindow("Frames", 640, 360);
moveWindow("Frames", 130, 100);
int init = 0;
while (1)
{
vcap >> img;
// If the frame is empty, break immediately
if (img.empty())
break;
unsigned int prevSize = 0;
resize(img, img, cv::Size(640, 360));
cv::cvtColor(img, grey_image, CV_RGB2GRAY);
//cv::equalizeHist(grey_image, grey_image);
std::vector<cv::Rect> faces;
frontfaceCascade.detectMultiScale(grey_image, faces, 1.1, 0, 0 | CV_HAAR_SCALE_IMAGE, cv::Size(30, 30)); // Minimum size of obj
//sidefaceCascade.detectMultiScale(grey_image, faces, 1.1, 4, 0 | 1, Size(40, 40), Size(100, 100)); // Minimum size of obj
/****/
}
destroyAllWindows();
vcap.release();
}