求助!毕业设计!是一个人脸检测,运行之后闪退
opencv吧
全部回复
仅看楼主
level 1
下面是我的代码 弄了好长时间解决不了 希望大家可以帮一下忙 谢谢啦!
-----------------------------------------------------------
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
/** 函数声明 */
void detectAndDisplay(Mat frame);
/** 全局变量 */
string face_cascade_name = "haarcascade_frontalface_alt.xml";
string eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
CascadeClassifier face_cascade;
CascadeClassifier eyes_cascade;
string window_name = "Capture - Face detection";
RNG rng(12345);
/** @主函数 */
int main(int argc, const char** argv)
{
//-- 1. 加载级联分类器文件
if (!face_cascade.load(face_cascade_name)) { printf("--(!)Error loading\n"); return -1; };
if (!eyes_cascade.load(eyes_cascade_name)) { printf("--(!)Error loading\n"); return -1; };
//-- 2. 打开内置摄像头视频流
VideoCapture capture(0);
if (!capture.isOpened())
return -2;
Mat frame;
while (1)
{
capture >> frame;//帧捕获,一帧一帧分解检测。
//-- 3. 对当前帧使用分类器进行检测
if (!frame.empty())
{
detectAndDisplay(frame);//调用这个方法进行识别。
}
else
{
printf(" --(!) No captured frame -- Break!"); break;//没有捕获到帧,跳出!
}
int c = waitKey(30);
if ((char)c == 'c') { break; }
}
return 0;
}
/** @函数 detectAndDisplay */
void detectAndDisplay(Mat frame)
{
std::vector<Rect> faces;
Mat frame_gray;
cvtColor(frame, frame_gray, CV_BGR2GRAY);//得到灰度图像
equalizeHist(frame_gray, frame_gray);//直方图均衡化
//-- 多尺寸检测人脸
face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
for (int i = 0; i < faces.size(); i++)
{
Point center(int(faces[i].x + faces[i].width*0.5), int(faces[i].y + faces[i].height*0.5));
ellipse(frame, center, Size(int(faces[i].width*0.5), int(faces[i].height*0.5)), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0);
Mat faceROI = frame_gray(faces[i]);
std::vector<Rect> eyes;
//-- 在每张人脸上检测双眼
eyes_cascade.detectMultiScale(faceROI, eyes, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
for (int j = 0; j < eyes.size(); j++)
{
Point center(int(faces[i].x + eyes[j].x + eyes[j].width*0.5), int(faces[i].y + eyes[j].y + eyes[j].height*0.5));
int radius = cvRound((eyes[j].width + eyes[i].height)*0.25);
circle(frame, center, radius, Scalar(255, 0, 0), 4, 8, 0);
}
}
//-- 显示结果图像
imshow(window_name, frame);
}
2017年07月14日 07点07分 1
level 1
运行之后就闪退
2017年07月14日 07点07分 4
level 1
点击菜单“工具”-“选项”。
在选项窗口中,展开“调试”-“常规”,然后在右边的窗格中勾选“启用源服务器支持”。
然后展开“调试”-“符号”,勾选“Windows符号服务器”。
这时,会弹出一个警告对话框,无视点击“确定”即可。
最后,点击“确定”关闭选项窗口。
------------------
以上这个办法也用 了
2017年07月14日 07点07分 5
level 1
求助!大神 帮忙 万分感谢!
2017年07月14日 07点07分 7
level 1
是不是我的代码有逻辑问题啊??
2017年07月14日 07点07分 9
level 1
自己顶一下 求帮助!!
2017年07月14日 07点07分 10
level 1
求帮助
2017年07月14日 07点07分 11
level 7
你的程序可以运行
估计是你是分类器没有加载成功
把分类器复制到当前路径中应该可以了
上图中的你用到的两个分类器
2017年07月15日 03点07分 12
谢谢 大神 这两个分类器应该放在哪里呢!是和这个.cpp文件放在一个文件夹里么
2017年07月15日 08点07分
2017年07月15日 08点07分
@白芦花 已经放了 然后提示:未找到schedulerproxy.cpp 0x000007FEE8B04A6F (concrt140.dll) (ConsoleApplication1.exe 中)处有未经处理的异常: 0xC0000005: 写入位置 0x000000D900000191 时发生访问冲突。这是咋回事 大神
2017年07月15日 08点07分
@半越三霸蜜2y 不知,我这里偶尔也会出错,不过正常的多。这种错误一般是函数的参数错了
2017年07月15日 08点07分
1