Search code examples
c++opencvgccnamespacesface-detection

Is this namespace issue


This is my code, I got from this 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);
    }

I am trying this code in my new system, where I installed opencv recently. Previously, when using from my old system, I normally used functions like ShowImage without a cv tag before it. but compiling this code is giving me the following error :

    facedetecthaar.cpp:28:91: error: ‘HaarDetectObjects’ was not declared in this scope
    facedetecthaar.cpp:29:47: error: ‘NamedWindow’ was not declared in this scope

And many more similar to this. If I add Cv infront of these functions, it becomes fine. Any reason why this is required? Is this a problem of namespace not working? Please help me here. This is my Makefile:

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



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

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

Solution

  • Use this instead of showImage This is easy

    // Open the window
    cv::namedWindow("foo");
    
    // Display the image m in this window
    cv::imshow("foo", m);
    

    And the cvxxxx_xxx before the functions are part of the function names, you should not remove them.

    All of this functionality which start with cv are old and there are replacements for all of them in new version of openCV which for some case are even faster.

    you can see the complete diffrences here:

    http://opencv.willowgarage.com/documentation/index.html openCV 2.0

    http://docs.opencv.org/index.html openCV 2.4