0

これは私のコードです。このリンクから取得しました

    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)
4

1 に答える 1

4

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

于 2013-07-22T09:28:58.280 に答える