PDA

View Full Version : QPainter/QImage/memory management error



p3l-outrepid
10th May 2010, 12:53
Dear forum,
I am doing an image over video overlaying in Qt with openCV library and I am having some memory issues in the main overlaying/writing loop which goes as follows,


QImage qimage;
IplImage* img5=0;
img5=cvLoadImage(ui->textEdit_3->toPlainText().toLatin1(),1);
QImage input=this->IplImageToQImage(img5,false);
while(i<numFrames){
if(i<(SelectedFrame+numofFrames)){
cvGrabFrame(capture);
img2=cvRetrieveFrame(capture);
qimage=this->IplImageToQImage(img2,false);
QPainter p(&qimage);
p.drawImage(xcoordinate, ycoordinate, input , 0,0,-1,-1,Qt::AutoColor);
img3=this->qtToCv(&(qimage));
cvWriteFrame(writer,img3);
i++;
img2=0;
img3=0;
}
else {
cvGrabFrame(capture);
img2=cvRetrieveFrame(capture);
cvWriteFrame(writer,img2);
i++;
img2=0;
}
ui->progressBar_2->setValue(i);
}


(I am sorry for the code format but I dont know what to do to make the code appear in lines under each other)
what I do is the following, I capture a frame from the captured video and transform it from an IplImage to a QImage to use the QPainter class which is supposedly easier, then after using the QPainter class to paint the image (input) on the captured image (qimage) i change it back to an IplImage and write it using the openCV writer (that is between the inserted number of seconds of the video) but the problem is, after a thousand loops (or so) the memory is overwhelmed and the program could not write anything anymore, now the IplImages are reset in every loop so i am kind of sure that they're not the problem. However, the QImage is not reset ever and I think that's what is taking from the memory, yet if i try to reset the QImage by doing qimage=QImage() the painter issues an error and I don't understand why,
if someone can help me I'd be extremely grateful,
Thanks alot,
p3l