3

I get 0xC000001D: Illegal Instruction when running cvHaarDetectObject. Below is my code

int main() {

IplImage* img;
img = cvLoadImage( "lena.jpg",1);

CvMemStorage* storage = cvCreateMemStorage(0);
CvHaarClassifierCascade* cascade = (CvHaarClassifierCascade*)cvLoad( "haarcascade_frontalface_alt2.xml" );


static CvScalar colors[] = { {{0,0,255}}, {{0,128,255}}, {{0,255,255}}, 
{{0,255,0}}, {{255,128,0}}, {{255,255,0}}, {{255,0,0}}, {{255,0,255}} };

// Detect objects
cvClearMemStorage( storage );
CvSeq* objects = cvHaarDetectObjects( img, cascade, storage, 1.1, 2, 0, cvSize(40, 40) );

CvRect* r;
// Loop through objects and draw boxes
for( int i = 0; i < (objects ? objects->total : 0 ); i++ ){
    r = ( CvRect* )cvGetSeqElem( objects, i );
    cvRectangle( img, cvPoint( r->x, r->y ), cvPoint( r->x + r->width, r->y + r->height ),
        colors[i%8]);
}

cvNamedWindow( "Output" );
cvShowImage( "Output", img );
cvWaitKey();


cvReleaseImage( &img );

return 0;
}

Is it something wrong with setup? I can compile the code, but when i run it, i get illegal instruction error, when the program run until cvHaarDetectObjects.

I have included all the lib files and place image inside the same directory of my project.

I'm using VS2010, Opencv2.4.3

Thanks and Best Regards

4

1 回答 1

2

今天早上我正在处理这个确切的例子,刚刚修复了这个错误。

首先,我的存储出错了,所以我把它变大了(64MB 而不是默认值,我想记得查找的是 64KB)。这解决了我的第一个分配错误,但 cvHaarDetectObjects() 仍然发生。请注意,您可能/可能不必这样做。

接下来,我复制粘贴了在 cvHaarDetectObjects() 调用上方显示图像的部分:

cvNamedWindow( "Output" );
cvShowImage( "Output", img );
cvWaitKey();

// Detect objects
cvClearMemStorage( storage );
CvSeq* objects = cvHaarDetectObjects( img, cascade, storage, 1.1, 2, 0, cvSize(40, 40) );

它表明我的图像没有加载!一旦我确定我在那里显示的图像,我将它移回并作为一个整体运行代码 - 它就像一个魅力。

如果这没有帮助,我建议对进入 cvHaarDetectObjects() 的每个变量进行类似的跟踪,以查看哪个变量未正确分配。

于 2012-11-30T19:54:55.020 回答