PDA

View Full Version : Problem with openCV compilation in Qt Creator



mind_freak
22nd February 2011, 12:11
here is the code below:

const char *filename="C://OpenCV2.2//data//haarcascades//haarcascade_frontalface_alt.xml";
cascade = ( CvHaarClassifierCascade* )cvLoad(filename,0,0,0);
if( !cascade )
{
fprintf( stderr, "ERROR: Could not load classifier cascade\n" );
return -1;
}
storage=cvCreateMemStorage(0);
capture=cvCaptureFromCAM(0);
// assert( cascade && storage && capture );
IplImage* frame= cvQueryFrame(capture);
m_i=QImage(QSize(frame->width,frame->height),QImage::Format_RGB888);
ui->frame->setMinimumSize(m_i.width(),m_i.height());
ui->frame->setMaximumSize(ui->frame->minimumSize());

m_opencvimg=cvCreateImageHeader(cvSize(m_i.width() ,m_i.height()),8,3);
m_opencvimg->imageData=(char*)m_i.bits();

if(frame->origin== IPL_ORIGIN_TL)
cvCopy(frame,m_opencvimg,0);
else
cvFlip(frame,m_opencvimg,0);

cvCvtColor(m_opencvimg,m_opencvimg,CV_BGR2RGB);

m_timer=new QTimer(this);
connect(m_timer,SIGNAL(timeout()),this,SLOT(queryF rame()));
m_timer->start(50);


Error's i was getting while compiling this code:

C:/Users/mind_freak/facedetect-build-desktop/../facedetect/widget.cpp:15: error: returning a value from a constructor

i dont know i have given the correct path to the xml file but unable to load.

help me out of this....i am stuck with this....

thanks..

stampede
22nd February 2011, 12:24
if( !cascade )
{
fprintf( stderr, "ERROR: Could not load classifier cascade\n" );
return -1;
}
Error message explains everything - you can't have a value return statement in constructor, this makes no sense. Remove the return -1 line.
Despite that, your constructor is doing a lot of work, this is not good, better create and call an initialization method, then in case of error you can return "false" or something.

mcosta
22nd February 2011, 12:26
C:/Users/mind_freak/facedetect-build-desktop/../facedetect/widget.cpp:15: error: returning a value from a constructor

The problem is the piece of code


cascade = ( CvHaarClassifierCascade* )cvLoad(filename,0,0,0);
if( !cascade )
{
fprintf( stderr, "ERROR: Could not load classifier cascade\n" );
return -1; // <---- This is the line
}


If the code is inside the constructor you cannot return a value