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,
Qt Code:
  1. QImage qimage;
  2. IplImage* img5=0;
  3. img5=cvLoadImage(ui->textEdit_3->toPlainText().toLatin1(),1);
  4. QImage input=this->IplImageToQImage(img5,false);
  5. while(i<numFrames){
  6. if(i<(SelectedFrame+numofFrames)){
  7. cvGrabFrame(capture);
  8. img2=cvRetrieveFrame(capture);
  9. qimage=this->IplImageToQImage(img2,false);
  10. QPainter p(&qimage);
  11. p.drawImage(xcoordinate, ycoordinate, input , 0,0,-1,-1,Qt::AutoColor);
  12. img3=this->qtToCv(&(qimage));
  13. cvWriteFrame(writer,img3);
  14. i++;
  15. img2=0;
  16. img3=0;
  17. }
  18. else {
  19. cvGrabFrame(capture);
  20. img2=cvRetrieveFrame(capture);
  21. cvWriteFrame(writer,img2);
  22. i++;
  23. img2=0;
  24. }
  25. ui->progressBar_2->setValue(i);
  26. }
To copy to clipboard, switch view to plain text mode 

(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