YDYD
9th July 2014, 09:16
Hi all,
I am getting some problem with my code,
I can compile and RUN, but it is very laggy.
My RAM seems not enough for my programme
If i leave the programme running for a few minutes, it will force close itself without any error msg.
and, if I quit the programme manually, there is a error messange.
Below if a part of my code and error msg.
I think the part have problem is the cvRelease part, and IplImage to QImage part.
void Dialog::createCam()
{
timer = new QTimer(this);
cam = cvCaptureFromCAM(-1);
if(cam==NULL)
qDebug()<<"error";
timer->start(0);
connect(timer,SIGNAL(timeout()),this,SLOT(getFrame ()));
connect(timer,SIGNAL(timeout()),this,SLOT(prcFrame ()));
}
void Dialog::getFrame()
{
frame = cvQueryFrame(cam);
QImage image = QImage ((const uchar*)frame->imageData,frame->width,frame->height,QImage::Format_RGB888).rgbSwapped();//rgbSwapped() make color better
ui->original->setPixmap(QPixmap::fromImage(image));
}
void Dialog::prcFrame() //threshold,not used yet
{
/*IplImage *imgHSV= cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,3);
cvCvtColor(frame,imgHSV,CV_BGR2HSV);
IplImage *imgFilter= cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,1);
//threshed , get value from slider value*/
cvCloneImage(frame);
cvCvtColor(frame,frame,CV_BGR2HSV);
IplImage *imgFilter= cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,1);
cvInRangeS(frame,cvScalar(ui->hueSlide1->value(),ui->satSlide1->value(),ui->lumSlide1->value(),0),cvScalar(ui->hueSlide2->value(),ui->satSlide2->value(),ui->lumSlide2->value(),0),imgFilter);
QImage imgThresdhed = QImage ((const uchar*)imgFilter->imageData,imgFilter->width,imgFilter->height,QImage::Format_Indexed8).rgbSwapped();
ui->filter->setPixmap(QPixmap::fromImage(imgThresdhed));
}
Dialog::~Dialog()
{
timer->stop();
cvReleaseCapture(&cam);
cvReleaseImage(&imgFilter);
delete ui;
}
ERROR Msg:
OpenCV Error: Bad argument (unrecognized or unsupported array type) in cvReleaseData, file /home/pi/OpenCV-2.4.2/modules/core/src/array.cpp, line 996
terminate called after throwing an instance of 'cv::Exception'
what(): /home/pi/OpenCV-2.4.2/modules/core/src/array.cpp:996: error: (-5) unrecognized or unsupported array type in function cvReleaseData
The program has unexpectedly finished.
/home/pi/qt/getCam/getCam exited with code 0
PLEASE ADVISE, thank you
I am getting some problem with my code,
I can compile and RUN, but it is very laggy.
My RAM seems not enough for my programme
If i leave the programme running for a few minutes, it will force close itself without any error msg.
and, if I quit the programme manually, there is a error messange.
Below if a part of my code and error msg.
I think the part have problem is the cvRelease part, and IplImage to QImage part.
void Dialog::createCam()
{
timer = new QTimer(this);
cam = cvCaptureFromCAM(-1);
if(cam==NULL)
qDebug()<<"error";
timer->start(0);
connect(timer,SIGNAL(timeout()),this,SLOT(getFrame ()));
connect(timer,SIGNAL(timeout()),this,SLOT(prcFrame ()));
}
void Dialog::getFrame()
{
frame = cvQueryFrame(cam);
QImage image = QImage ((const uchar*)frame->imageData,frame->width,frame->height,QImage::Format_RGB888).rgbSwapped();//rgbSwapped() make color better
ui->original->setPixmap(QPixmap::fromImage(image));
}
void Dialog::prcFrame() //threshold,not used yet
{
/*IplImage *imgHSV= cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,3);
cvCvtColor(frame,imgHSV,CV_BGR2HSV);
IplImage *imgFilter= cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,1);
//threshed , get value from slider value*/
cvCloneImage(frame);
cvCvtColor(frame,frame,CV_BGR2HSV);
IplImage *imgFilter= cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,1);
cvInRangeS(frame,cvScalar(ui->hueSlide1->value(),ui->satSlide1->value(),ui->lumSlide1->value(),0),cvScalar(ui->hueSlide2->value(),ui->satSlide2->value(),ui->lumSlide2->value(),0),imgFilter);
QImage imgThresdhed = QImage ((const uchar*)imgFilter->imageData,imgFilter->width,imgFilter->height,QImage::Format_Indexed8).rgbSwapped();
ui->filter->setPixmap(QPixmap::fromImage(imgThresdhed));
}
Dialog::~Dialog()
{
timer->stop();
cvReleaseCapture(&cam);
cvReleaseImage(&imgFilter);
delete ui;
}
ERROR Msg:
OpenCV Error: Bad argument (unrecognized or unsupported array type) in cvReleaseData, file /home/pi/OpenCV-2.4.2/modules/core/src/array.cpp, line 996
terminate called after throwing an instance of 'cv::Exception'
what(): /home/pi/OpenCV-2.4.2/modules/core/src/array.cpp:996: error: (-5) unrecognized or unsupported array type in function cvReleaseData
The program has unexpectedly finished.
/home/pi/qt/getCam/getCam exited with code 0
PLEASE ADVISE, thank you