gpt4 book ai didi

c++ - 使用 OpenCV CascadeClassifier : . exe 的人脸检测已触发断点

转载 作者:太空宇宙 更新时间:2023-11-03 22:51:07 27 4
gpt4 key购买 nike

我正在尝试编写一个简单的程序,它读取图像、检测图像上的人脸并在图像上用矩形标记人脸。我使用 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 函数和 draw rectangle 函数。程序运行没有错误。

有没有人知道我做错了什么?

感谢您的帮助!

最佳答案

问题是我的环境变量中的 opencv bin 文件夹路径错误。我最近停止使用 Visual Studio 2010 并开始使用 VS2012 并忘记调整路径。我不得不改变它从
C:\opencv\build\x64\vc10\bin;

C:\opencv\build\x64\vc11\bin;
并重新启动计算机。

现在一切似乎都正常工作。

关于c++ - 使用 OpenCV CascadeClassifier : . exe 的人脸检测已触发断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37447522/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com