【问题标题】:Is this namespace issue这是命名空间问题吗
【发布时间】:2013-07-20 23:10:39
【问题描述】:

这是我的代码,我从这个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 ,就可以了。为什么需要这样做?这是命名空间不起作用的问题吗?请在这里帮助我。这是我的 Makefile:

    LIBS=`pkg-config --libs opencv`
    INCLUDE=`pkg-config --cflags opencv`



    Facedetect: facedetecthaar.o
            g++ $^ -o $@ $(LIBS)

    facedetecthaar.o: facedetecthaar.cpp
            g++ -c $^ $(INCLUDE)

【问题讨论】:

    标签: c++ opencv gcc namespaces face-detection


    【解决方案1】:

    用这个代替 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.htmlopenCV 2.0

    http://docs.opencv.org/index.htmlopenCV 2.4

    【讨论】:

    • 感谢您的帮助。你能看看我提供的链接吗?该代码具有以 Cvxxx_xxx 开头的功能。我想知道这是否是由于函数名本身是否必须以 Cv 开头的命名空间?谢谢。
    • @LakshmiNarayanan CvxXxxxx 适用于 OpenCV 的 C 接口的函数和类型。 C++ 的东西都存在于 cv 命名空间中。
    • @Khashayar 无论如何我能找到旧函数的新等效项吗?
    • 所有旧的都带有 IplImages,所以我认为最简单的方法是搜索 Mat 的相同函数并找到正确的。
    • docs.opencv.org/modules/objdetect/doc/… 例如:这是代替 cvHaarDetectObjects
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-05
    • 2016-12-04
    • 2013-03-26
    • 2016-05-14
    相关资源
    最近更新 更多