1 Attachment(s)
OpenCV , Mat image from QByteArray
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:
Attachment 10983
Here the code:
Code:
void Locus
::getImages(QFile* file, Mat
& matImg
) {
if(file->exists())
{
//get byteArray from raw data file
file
->open
(QFile::ReadOnly);
imagesData = file->readAll();
file->close();
//Create qimage
QImage img
((const uchar
*)imagesData.
data(),WIDTH,HEIGHT,
QImage::Format_RGB16);
//create mat image from qimage
matImg = this->qImage2Mat(img);
imshow("window",matImg);
waitKey();
}
}
Mat Locus::qImage2Mat(const QImage& src)
{
Mat tmp(src.height(),src.width(), CV_8UC3,(uchar*)src.bits(),src.bytesPerLine());
Mat res;
cvtColor(tmp, res,CV_RGB2GRAY);
return res;
}
Any help?
ps: i think the problem is the image format, but i've tried many ways help me xD.
Re: OpenCV , Mat image from QByteArray
The problem was the format, it's not CV_8UC3 but CV_16UC1(16 bit - 1 channel ).
This is just my case ,for this specific problem , but when you work on image processing you must keep in your mind that the format convertions are very important.
Re: OpenCV , Mat image from QByteArray
You can create a Mat image directly from QByteArray without the need of creating a QImage
Mat img = Mat(WIDTH,HEIGHT, CV_8UC1, imagesData.data());
Regards