Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
cv::Mat tmp(qImage.height(), qImage.width(), CV_8UC4, (void*) qImage.bits(), qImage.bytesPerLine());
cv::cvtColor(tmp, cvImage, CV_RGBA2RGB);

This code worked for me to convert QImage to 8UC4 cv::Mat, hope it helps.

cv::Mat tmp(qImage.height(), qImage.width(), CV_8UC4, (void*) qImage.bits(), qImage.bytesPerLine());
cv::cvtColor(tmp, cvImage, CV_RGBA2RGB);

This code worked for me to convert QImage to 8UC4 cv::Mat, hope it helps.helps. And reversing from Mat to QImage,

QImage tmp((unsigned char*) cvImage.data, cvImage.size().width, cvImage.size().height, cvImage.step, QImage::Format_RGB888);

qImage = tmp.rgbSwapped().convertToFormat(QImage::Format_ARGB32_Premultiplied);

Edited: Conversion from 8UC4 to QImage

cv::Mat tmp(qImage.height(), qImage.width(), CV_8UC4, (void*) qImage.bits(), qImage.bytesPerLine());
cv::cvtColor(tmp, cvImage, CV_RGBA2RGB);

This code worked for me to convert QImage to 8UC4 cv::Mat, hope it helps. And reversing from Mat to QImage,

QImage tmp((unsigned char*) cvImage.data, cvImage.size().width, cvImage.size().height, cvImage.step, QImage::Format_RGB888);
qImage = tmp.rgbSwapped().convertToFormat(QImage::Format_ARGB32_Premultiplied);

qImage = tmp.rgbSwapped().convertToFormat(QImage::Format_ARGB32_Premultiplied);

Edited: Conversion from 8UC4 to QImage