how do i save QImage in cv::Mat
can anyone tell me how to save QImage in a cv::Mat variable? QByteArray to cv::Mat would also work.
can anyone tell me how to save QImage in a cv::Mat variable? QByteArray to cv::Mat would also work.
Afaik you need to write it yourself, e.g.:
cv::Mat3b QImage2Mat(const QImage &src) {
unsigned int height = src.height();
unsigned int width = src.width();
cv::Mat3b dest(height, width);
for (unsigned int y = 0; y < height; ++y) {
cv::Vec3b *destrow = dest[y];
for (unsigned int x = 0; x < width; ++x) {
QRgb pxl = src.pixel(x, y);
destrow[x] = cv::Vec3b(qBlue(pxl), qGreen(pxl), qRed(pxl));
}
}
return dest;
}
Hmm from the QByteArray you can get the data via data() or constData(). This you could use to create a matrix-header on top, i.e. : uchar* data = bytearray.data(); cv::Mat3b a(rows, cols, data); Note that you should check first if the layout of the data you get from your byteArray is correct (maybe it is saved as rgb instead of bgr) or otherwise. For QImage it probably won't work since it seems that the data is aligned to 32bit. So is the QByteArray coming from the QImage (then it probably won't work due to the alignment) or did you create it?
I'm using QTcpSocket to receive pictures from a tablet. readAll() gives me a ByteArray. Then i use LoadFromData() for a Pixmap, to display the image in a GUI.
Now i want to change it and save to cv::Mat, to be able to use imageprocessing.
Will see if your char pointer idea solves it.
Asked: 2013-03-13 03:43:32 -0600
Seen: 2,912 times
Last updated: Mar 13 '13
How can I convert cv::Mat of type CV_8UC1 to a QImage in Qt?
OpenCV on Mac OS X 10.8 Mountain Lion
Why doesnt QT get detected when I want to build openCV?
Cannot Parse Libraries In Linux Using Qt Enviornment
Problem with using Qt Functions '"createButton" of OpenCV2
Video On Label OpenCV Qt :: hide cvNamedWindows