这是我的代码,我从这个链接得到
int main(int agrc, char **argv)
{
HaarClassifierCascade *p = 0;
MemStorage *pstore = 0;
Seq *Faceseq;
int i;
Mat test_sample = imread("1.jpg");
pstore = CreateMemStorage(0);
p = (HaarClassifierCascade *)Load(("/home/itachi/opencv-2.4.6/data/haarcascades/haarcascade_frontalface_default.xml"),0,0,0);
if( !test_sample || !pstore || !p)
{
printf("Initialization failed : %s \n",(!test_sample)? "didn't load image file" : (!p)? "didn't load Haar cascade --" "make sure path is correct" : "failed to allocate memory for data storage");
exit(-1);
}
Faceseq = HaarDetectObjects(test_sample,p,pstore,1.1,3,CV_HAAR_DO_CANNY_PRUNING,Size(0,0));
NamedWindow("Haar Window", CV_WINDOW_AUTOSIZE);
for(i=0;i<(Faceseq? Faceseq->total:0);i++)
{
Rect *r = (Rect*)GetSeqElem(Faceseq,i);
Point pt1 = { r->x, r->y };
Point pt2 = { r->x + r->width, r->y + r->height };
Rectangle(test_sample,pt1,pt2,CV_RGB(0,255,0),3,4,0);
}
ShowImage("Haar Window", CV_WINDOW_AUTOSIZE);
WaitKey(0);
DestroyWindow("Haar Window");
ReleaseImage(test_sample);
if(p) ReleaseHaarClassifierCascade(&p);
if(pstore) ReleaseMemStorage (&pstore);
}
我正在我的新系统中尝试此代码,我最近在其中安装了 opencv。以前,在我的旧系统中使用时,我通常使用ShowImage 之类的函数,之前没有cv标签。但编译这段代码给了我以下错误:
facedetecthaar.cpp:28:91: error: ‘HaarDetectObjects’ was not declared in this scope
facedetecthaar.cpp:29:47: error: ‘NamedWindow’ was not declared in this scope
还有更多类似的。如果我在这些函数前面添加Cv,就可以了。为什么需要这样做?这是命名空间不起作用的问题吗?请在这里帮助我。这是我的 Makefile:
LIBS=`pkg-config --libs opencv`
INCLUDE=`pkg-config --cflags opencv`
Facedetect: facedetecthaar.o
g++ $^ -o $@ $(LIBS)
facedetecthaar.o: facedetecthaar.cpp
g++ -c $^ $(INCLUDE)