【发布时间】:2016-09-23 16:06:10
【问题描述】:
我正在尝试编写一个简单的程序,它读取图像,检测图像上的人脸并在图像上用矩形标记人脸。 我使用 Visual Studio 2012 和 OpenCV 2.4.9。
我使用 OpenCV 提供的 cv::CascadeClassifier 和 haarcascade_frontalface_default.xml。这是我的代码:
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <stdio.h>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
//load image, in this case it's allready gray
Mat img = imread("H:/BioID/BioID-FaceDatabase-V1.2/BioID_0000.pgm");
Mat grayImg;
cvtColor(img, grayImg, CV_BGR2GRAY);
//create vector of rectangles that will represent the faces
vector<Rect> faces;
CascadeClassifier* faseCascade = new CascadeClassifier("C:\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_default.xml");
faseCascade->detectMultiScale(grayImg, faces);
//draw rectangle on img; param: image, rectangle, color
cv::rectangle(img, faces[0],Scalar(255,0,0),2);
//display image
imshow("image", img);
waitKey(0);
return 0;
}
程序运行正常,最后它向我显示了脸部周围有一个蓝色矩形的图像。但是在我按下一个键并且程序试图关闭之后,它就中断了。
输出显示:
HEAP[myProgram.exe]: Invalid address specified to RtlValidateHeap( 00000004F9F30000, 00000004FC23ECE0 )
myProgram.exe has triggered a breakpoint.
如果我注释掉 detectMultiscale 函数和绘制矩形函数。程序运行没有错误。
有人知道我做错了什么吗?
感谢您的帮助!
【问题讨论】:
-
返回前可以添加deallocate faseCascade吗?
-
使用过时版本的 OpenCV 有什么特别的原因吗?调试还是发布模式?您链接了哪些库?
-
-
@DanMašek 没有别的原因,就是我的前辈用的是2.4.9版本,我继续用。我处于调试模式。我与这些库链接:opencv_calib3d249d.lib opencv_contrib249d.lib opencv_core249d.lib opencv_features2d249d.lib opencv_flann249d.lib opencv_gpu249d.lib opencv_highgui249d.lib opencv_imgproc249d.lib opencv_legacy249d.lib opencv_ml249d.lib opencv_nonfree249d.lib opencv_objdetect249d.lib opencv_photo249d.lib opencv_stitching249d.lib opencv_ts249d。 lib opencv_video249d.lib opencv_videostab249d.lib
标签: c++ opencv face-detection