OpenCV 错误:断言失败

Posted

技术标签:

【中文标题】OpenCV 错误:断言失败【英文标题】:OpenCV Error: Assertion failed 【发布时间】:2011-10-18 13:38:08 【问题描述】:
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);

在上述函数中,我不断得到以下输出:

在detect_eye_in_image() 154 154 154 154

(rect.width >= 0 && rect.height >= 0 && rect.x width && rect.y height && rect.x + rect.width>= (int)(rect.widt h > 0) && rect.y + rect.height >= (int )(rect.height > 0)) 在未知函数中,文件 ........\ocv\opencv\src\cxcore\cxarray.cpp,第 3000 行

如何解决这个问题?

【问题讨论】:

【参考方案1】:

您可能在图像尺寸之外工作。您传递给cvSetImageROI 函数的任何值是否位于图像边界之外?

【讨论】:

以上是关于OpenCV 错误:断言失败的主要内容,如果未能解决你的问题,请参考以下文章

为啥我会收到此 OpenCV 错误断言失败?

是啥导致“OpenCV(4.0.1)错误:断言失败(m.dims <= 2)”

OpenCV 错误:断言失败

图像处理 opencv 3.0 断言失败错误

java opencv错误内存不足和断言失败

OpenCV 错误:使用 calcHist 断言失败