这是我的代码,我来自link
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 ,它就会变得很好。有什么理由需要这个吗?这是命名空间无法正常工作的问题吗?请帮帮我。这个问题可能真的很天真,但我想知道,所以请光临我。这是我的make文件:
LIBS=`pkg-config --libs opencv`
INCLUDE=`pkg-config --cflags opencv`
Facedetect: facedetecthaar.o
g++ $^ -o $@ $(LIBS)
facedetecthaar.o: facedetecthaar.cpp
g++ -c $^ $(INCLUDE)
谢谢你的到来。
答案 0 :(得分:4)
使用此而不是showImage 这很容易
// Open the window
cv::namedWindow("foo");
// Display the image m in this window
cv::imshow("foo", m);
函数前面的cvxxxx_xxx是函数名的一部分,你不应该删除它们。
以cv开头的所有这些功能都是旧的,并且在新版本的openCV中可以替换所有这些功能,在某些情况下甚至更快。
你可以在这里看到完整的差异:
http://opencv.willowgarage.com/documentation/index.html openCV 2.0
http://docs.opencv.org/index.html openCV 2.4