求助,opencv3.0 人脸检测运行人脸检测程序出错

查看: 1891|回复: 2
新手求助:OpenCV官方的人脸识别Demo运行出错is_block_type_vaild
新人求助:打开OpenCV官方的人脸识别示例,运行出错。错误提示如下:
bug.jpg (166.34 KB, 下载次数: 0)
13:33 上传
Debug Assertion Failed
Program : D:\OpenCVPractice\HumanDetect\HumanDetect\Debug\HumanDetect.exe
File : minkernal\crts\ucrt\src\appcrt\heap\debug_heap.cpp
Line : 892
Expression : is_block_type_vaild(header-&_block_use)
现象:运行后,有时候能显示出人脸识别后的结果,然后报错。有时候不显示出图像窗口就会报错。运行后多久报错似乎得看人品。。。
经检查,出错的代码为:
& & & & face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
复制代码这一句。
运行的代码为官方给的示例:\sources\samples\cpp\tutorial_code\objectDetection\objectDetection.cpp
/**
* @file objectDetection.cpp
* @author A. Huaman ( based in the classic facedetect.cpp in samples/c )
* @brief A simplified version of facedetect.cpp, show how to load a cascade classifier and how to find objects (Face + eyes) in a video stream
*/
#include &opencv2/opencv.hpp&
#include &opencv2/objdetect/objdetect.hpp&
#include &opencv2/highgui/highgui.hpp&
#include &opencv2/imgproc/imgproc.hpp&
#include &iostream&
#include &stdio.h&
/** Function Headers */
void detectAndDisplay(Mat frame);
/** Global variables */
//-- Note, either copy these two files from opencv/data/haarscascades to your current folder, or change these locations
String face_cascade_name = &D:\\OpenCv249\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_alt.xml&;
String eyes_cascade_name = &D:\\OpenCv249\\opencv\\sources\\data\\haarcascades\\haarcascade_eye_tree_eyeglasses.xml&;
CascadeClassifier face_
CascadeClassifier eyes_
string window_name = &Capture - Face detection&;
RNG rng(12345);
/**
* @function main
*/
int main(void)
{
& & & & VideoC
& & & & M
& & & & //-- 1. Load the cascades
& & & & 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. Read the video stream
& & & & capture.open(0);
& & & & if (capture.isOpened())
& & & & {
& & & & & & & & for (;;)
& & & & & & & & {
& & & & & & & & & & & & capture &&
& & & & & & & & & & & & //-- 3. Apply the classifier to the frame
& & & & & & & & & & & & if (!frame.empty())
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & detectAndDisplay(frame);
& & & & & & & & & & & & }
& & & & & & & & & & & & else
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & printf(& --(!) No captured frame -- Break!&);
& & & & & & & & & & & & }
& & & & & & & & & & & & int c = waitKey(100);
& & & & & & & & & & & & if ((char)c == 'c') { }
& & & & & & & & }
& & & & }
& & & & return 0;
}
/**
* @function detectAndDisplay
*/
void detectAndDisplay(Mat frame)
{
& & & & std::vector&Rect&
& & & & Mat frame_
& & & & cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
& & & & equalizeHist(frame_gray, frame_gray);
& & & & //-- Detect faces
& & & & face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
& & & & for (size_t i = 0; i & faces.size(); i++)
& & & & {
& & & & & & & & Point center(faces[i].x + faces[i].width / 2, faces[i].y + faces[i].height / 2);
& & & & & & & & ellipse(frame, center, Size(faces[i].width / 2, faces[i].height / 2), 0, 0, 360, Scalar(255, 0, 255), 2, 8, 0);
& & & & & & & & Mat faceROI = frame_gray(faces[i]);
& & & & & & & & std::vector&Rect&
& & & & & & & & //-- In each face, detect eyes
& & & & & & & & eyes_cascade.detectMultiScale(faceROI, eyes, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
& & & & & & & & for (size_t j = 0; j & eyes.size(); j++)
& & & & & & & & {
& & & & & & & & & & & & Point eye_center(faces[i].x + eyes[j].x + eyes[j].width / 2, faces[i].y + eyes[j].y + eyes[j].height / 2);
& & & & & & & & & & & & int radius = cvRound((eyes[j].width + eyes[j].height)*0.25);
& & & & & & & & & & & & circle(frame, eye_center, radius, Scalar(255, 0, 0), 3, 8, 0);
& & & & & & & & }
& & & & }
& & & & //-- Show what you got
& & & & imshow(window_name, frame);
}
复制代码
运行环境为:
OpenCV 2.4.9(测试过:OpenCV 3.0.0也会报错)
Visual Studio 2015 ,Debug模式,x86
使用的库为:opencv\build\x86\vc12 下的内容。&&
刚接触OpenCV没多久,希望大家帮忙看一下。感激不尽!
经过测试,发现VS2015 RC 不兼容OpenCV?
今天改安装了一个VS2013,发现一切正常运行。
搞不太懂为啥。。。
vc12对应的是啥 不知道吗?
Powered by&&&&&&&&基于Opencv的人脸检测程序源代码(可运行)
正在努力加载播放器,请稍等…
正在努力加载播放器
大小:66.00KB&&所需金币:80
&& & 金币不足怎么办?
下载量:-次 浏览量:709次
贡献时间: 9:39:46
文档标签:
已有-位用户参与评分
下载过这篇文档的还下载过
同类热门文档
你可能喜欢
看过这篇文档的还看过
阅读:1068&&下载:14
阅读:1046&&下载:5
阅读:810&&下载:3
阅读:248&&下载:3
阅读:204&&下载:1
阅读:251&&下载:0
阅读:704&&下载:0
阅读:102&&下载:0
阅读:618&&下载:0
阅读:662&&下载:0
该用户的其他文档
所需财富值:
80文件大小:66.00KB
您当前剩余财富值:&&
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
举报该文档侵犯版权。
例: /help.shtml[ 转载请注明来自CoderJeff的CSDN博客:,谢谢!]
试验环境:
Visual Studio Community 2015
OpenCV 3.0
采用OpenCV官方网站中的教程试验“人脸检测”的功能,但无论怎么调试,窗口总是显示灰色的背景,如下图所示:
奇怪的是,摄像头的绿色指示灯还正常亮着,说明摄像头正常工作了,但窗口里就是没有任何图像。
后来,找了段试验了一下,能正常显示人像,说明摄像头和OpenCV都没问题,应该还是教程中的参数或函数调用有问题。
一段一段的屏蔽,运行......终于找到了原因,教程中关于摄像头的设备号的设置如下:
capture.open(-1);
把-1改成0,即
capture.open(0);
或者,直接把两行代码
capture.open(0);
合并成一行代码:
VideoCapture capture(0);
找到源码opencv\sources\modules\videoio\src\cap.cpp
bool VideoCapture::open(int device)
&&& if (isOpened()) release();
&&& icap = IVideoCapture_create(device);
&&& if (!icap.empty())
&&& cap.reset(cvCreateCameraCapture(device));
&&& return isOpened();
以及IVideoCapture_create和cvCreateCameraCapture的源码,感觉赋值-1没有意义,尽管输入参数确实也是int类型,可以为负。而其,教程中提到的Git上的最新代码也都是-1,可能还真不是笔误。
原因待查。

参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:6627次
排名:千里之外
(3)(5)(7)(2)

我要回帖

更多关于 opencv人脸识别源代码 的文章

 

随机推荐