Dear forum,
I am using this method to change from IplImage captured by OpenCV library to a QImage to use QPainter class on and paint on it another QImage, now the problem is that I am using the method in a while loop which eats up my memory (over 1GB in mere seconds) and I can't find a way around it.
Qt Code:
  1. QImage MainWindow::IplImage2QImage(IplImage *iplImg)
  2. {
  3. this->h = iplImg->height;
  4. this->w = iplImg->width;
  5. this->channels = iplImg->nChannels;
  6. this->qimg = new QImage(w, h, QImage::Format_ARGB32);
  7. this->data = iplImg->imageData;
  8.  
  9. for (int y = 0; y < h; y++, data += iplImg->widthStep)
  10. {
  11. for (int x = 0; x < w; x++)
  12. {
  13. char r, g, b, a = 0;
  14. if (channels == 1)
  15. {
  16. r = data[x * channels];
  17. g = data[x * channels];
  18. b = data[x * channels];
  19. }
  20. else if (channels == 3 || channels == 4)
  21. {
  22. r = data[x * channels + 2];
  23. g = data[x * channels + 1];
  24. b = data[x * channels];
  25. }
  26.  
  27. if (channels == 4)
  28. {
  29. a = data[x * channels + 3];
  30. qimg->setPixel(x, y, qRgba(r, g, b, a));
  31. }
  32. else
  33. {
  34. qimg->setPixel(x, y, qRgb(r, g, b));
  35. }
  36. }
  37. }
  38. return *qimg;
  39. }
To copy to clipboard, switch view to plain text mode 
now that's the method itself and the while loop for looping on frames is the following
Qt Code:
  1. while(i<numFrames){
  2. if(i<(SelectedFrame+numofFrames)){
  3. cvGrabFrame(capture);
  4. img2=cvRetrieveFrame(capture);
  5. qimage=this->IplImage2QImage(img2);
  6. QPainter p(&qimage);
  7. p.drawImage(xcoordinate, ycoordinate, input , 0,0,-1,-1,Qt::AutoColor);
  8. img3=this->qtToCv(&(qimage));
  9. cvWriteFrame(writer,img3);
  10. i++;
  11. img2=0;
  12. img3=0;
  13. p.end();
  14. qimage=QImage();
  15. }
  16. else {
  17. cvGrabFrame(capture);
  18. img2=cvRetrieveFrame(capture);
  19. cvWriteFrame(writer,img2);
  20. i++;
  21. img2=0;
  22. }
  23. ui->progressBar_2->setValue(i);
  24. }
To copy to clipboard, switch view to plain text mode 
now I know that the problem is with the method because I commented everything else and only the calling of the method caused the memory overload. All I need is for another method (or a change in this method) to ensure that not too much memory is used while applying it.
Thanks a lot and best regards,
p3l