gpt4 book ai didi

c++ - 在使用opencv和eclipse的facedetect程序中使用 'CvHaarClassifierCascade*'

转载 作者:行者123 更新时间:2023-11-28 07:21:50 26 4
gpt4 key购买 nike

我正在尝试在 eclipse 中使用 opencv2 检测人脸。我正在使用以下程序进行相同的...

#include <cv.h>
#include"opencv2/highgui/highgui.hpp"
#include"opencv2/core/core.hpp"
#include"opencv2/imgproc/imgproc.hpp"
using namespace cv;
using namespace std;

CvRect detectFaceInImage(IplImage *inputImg, CvHaarClassifierCascade* cascade);
String face_cascade_name = "src/haarcascade_frontalface_alt.xml";
CvHaarClassifierCascade* cascade;

int main(int argc, const char* argv[])
{
CvCapture* capture =0;

capture = cvCaptureFromCAM(0);
IplImage* inputImg=0;

if( !cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };

while(true)
{
inputImg = cvQueryFrame(capture);
if(!inputImg) break;

namedWindow("My_capture",CV_WINDOW_AUTOSIZE);

CvRect outputImg;

outputImg = detectFaceInImage(inputImg, cascade);
}

return 0;
}
// Perform face detection on the input image, using the given Haar Cascade.
// Returns a rectangle for the detected region in the given image.
CvRect detectFaceInImage(IplImage *inputImg, CvHaarClassifierCascade* cascade)
{
// Smallest face size.
CvSize minFeatureSize = cvSize(20, 20);
// Only search for 1 face.
int flags = CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH;
// How detailed should the search be.
float search_scale_factor = 1.1f;
IplImage *detectImg;
IplImage *greyImg = 0;
CvMemStorage* storage;
CvRect rc;
double t;
CvSeq* rects;
CvSize size;
int ms, nFaces;
storage = cvCreateMemStorage(0);
cvClearMemStorage( storage );
// If the image is color, use a greyscale copy of the image.
detectImg = (IplImage*)inputImg;
if (inputImg->nChannels > 1)
{
size = cvSize(inputImg->width, inputImg->height);
greyImg = cvCreateImage(size, IPL_DEPTH_8U, 1 );
cvCvtColor( inputImg, greyImg, CV_BGR2GRAY );
detectImg = greyImg; // Use the greyscale image.
}

// Detect all the faces in the greyscale image.
t = (double)cvGetTickCount();
rects = cvHaarDetectObjects( detectImg, cascade, storage,search_scale_factor, 3, flags, minFeatureSize);
t = (double)cvGetTickCount() - t;
ms = cvRound( t / ((double)cvGetTickFrequency() * 1000.0) );
nFaces = rects->total;
printf("Face Detection took %d ms and found %d objects\n", ms, nFaces);
// Get the first detected face (the biggest).
if (nFaces > 0)
rc = *(CvRect*)cvGetSeqElem( rects, 0 );
else
rc = cvRect(-1,-1,-1,-1); // Couldn't find the face.
if (greyImg)
cvReleaseImage( &greyImg );
cvReleaseMemStorage( &storage );
//cvReleaseHaarClassifierCascade( &cascade );
return rc; // Return the biggest face found, or (-1,-1,-1,-1).
}

但是我收到这个错误...

../src/test3.cpp:28:15: 错误:请求'cascade'中的成员'load',它是非类类型'CvHaarClassifierCascade*'

我已经在源文件夹中添加了“haarcascade_frontalface_alt.xml”。当我将级联定义为 CascadeClassifier 时,它显示一些兼容性错误。

我实际上是 opencv 的新手...所以请帮忙

最佳答案

请不要使用过时的c-api,它在不久的将来不会被支持。

look here获取更新版本

顺便说一句,如果你有一个指向某物的指针,你需要访问它:something->,而不是something.

关于c++ - 在使用opencv和eclipse的facedetect程序中使用 'CvHaarClassifierCascade*',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19342547/

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