2011-10-18 126 views
2
void detect_eye_in_image() 
{ 
    CvRect *face = (CvRect*)cvGetSeqElem(faces, 0); 

printf("\nIn detect_eye_in_image() %d %d %d %d\n\n",imgcpy->height,imgcpy->width,face->width,face->height); 
     cvSetImageROI(
     imgcpy,     /* the source image */ 
     cvRect(
      face->x,   /* x = start from leftmost */ 
      face->y , /* y = a few pixels from the top */ 
      face->width,  /* width = same width with the face */ 
      face->height/3 /* height = 1/3 of face height */ 
     ) 
    ); 

printf("\nIn detect_eye_in_image()"); 
     CvSeq *eyes = cvHaarDetectObjects(
     imgcpy,   /* the source image, with the 
          estimated location defined */ 
     cascade,  /* the eye classifier */ 
     storage,  /* memory buffer */ 
     1.15, 3, 0,  /* tune for your app */ 
     cvSize(25,25) /* minimum detection scale */ 
    ); 
    printf("\nIn detect_eye_in_image()"); 
    /* draw a rectangle for each detected eye */ 
    // for(i = 0; i < (eyes ? eyes->total : 0); i++) 
    { 
     /* get one eye */ 
     CvRect *eye = (CvRect*)cvGetSeqElem(eyes, 0); 
     /* draw a red rectangle */ 
     cvRectangle(
      imgcpy, 
      cvPoint(eye->x, eye->y), 
      cvPoint(eye->x + eye->width, eye->y + eye->height), 
      CV_RGB(255, 0, 0), 
      1, 8, 0 
     ); 
    } 
printf("\nIn detect_eye_in_image()"); 
    Show_Image(imgcpy); 

cvResetImageROI(imgcpy); 
} 

在上面的函數我不斷收到以下的輸出:OpenCV的錯誤:斷言失敗

In detect_eye_in_image() 154 154 154 154

OpenCV Error: Assertion failed (rect.width >= 0 && rect.height >= 0 && rect.x < image->width && rect.y < image->height && rect.x + rect.width>= (int)(rect.widt h > 0) && rect.y + rect.height >= (int)(rect.height > 0)) in unknown function, f ile ........\ocv\opencv\src\cxcore\cxarray.cpp, line 3000

如何解決這個問題?

回答

4

您可能正在圖像尺寸之外工作。您傳遞給cvSetImageROI函數的任何值是否位於圖像邊界之外?

相關問題