Hi all ,

I'm trying to show an image with opencv function cv::imshow("windowsName",cv::Mat) starting from QByteArray. The problem is that the image appears duplicated:

Like this:
DuplicatedMat.jpg

Here the code:

Qt Code:
  1. void Locus::getImages(QFile* file, Mat& matImg)
  2. {
  3. QByteArray imagesData;
  4.  
  5. if(file->exists())
  6. {
  7. //get byteArray from raw data file
  8. file->open(QFile::ReadOnly);
  9. imagesData = file->readAll();
  10. file->close();
  11.  
  12. //Create qimage
  13. QImage img((const uchar*)imagesData.data(),WIDTH,HEIGHT,QImage::Format_RGB16);
  14.  
  15. //create mat image from qimage
  16. matImg = this->qImage2Mat(img);
  17.  
  18. imshow("window",matImg);
  19. waitKey();
  20. }
  21. }
  22.  
  23. Mat Locus::qImage2Mat(const QImage& src)
  24. {
  25.  
  26. Mat tmp(src.height(),src.width(), CV_8UC3,(uchar*)src.bits(),src.bytesPerLine());
  27. Mat res;
  28. cvtColor(tmp, res,CV_RGB2GRAY);
  29. return res;
  30. }
To copy to clipboard, switch view to plain text mode 

Any help?
ps: i think the problem is the image format, but i've tried many ways help me xD.