2013-07-22 73 views
0

這是我的代碼,我從這個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 [email protected] $(LIBS) 

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

感謝提前。

回答

4

使用這個代替showImage 的這是很容易

// Open the window 
cv::namedWindow("foo"); 

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

而且cvxxxx_xxx之前的功能函數名的一部分,你不應該刪除它們。

所有以cv開頭的功能都是舊的,並且在新版本的openCV中它們都替代了它們,對於某些情況甚至更快。

,你可以在這裏看到完整的diffrences:

http://opencv.willowgarage.com/documentation/index.html OpenCV的2.0

http://docs.opencv.org/index.html OpenCV的2.4

+0

感謝您的幫助。你能看看我提供的鏈接嗎?該代碼具有從Cvxxx_xxx開始的功能。我想知道如果這是由於命名空間,如果函數名稱本身必須以Cv開頭?謝謝。 –

+2

@LakshmiNarayanan'CvxXxxxx'適用於OpenCV的C接口的函數和類型。 C++的東西都住在'cv'命名空間中。 – juanchopanza

+1

我編輯了答案 – Khashayar