What format should I use to convert QImage to cv::Mat?
Unsolved
General and Desktop
-
auto image = this->myLabel->pixmap()->toImage(); this->background = Mat(image.height(), image.width(), CV_8UC3, const_cast<uchar*>(image.bits()), static_cast<unsigned int>(image.bytesPerLine())).clone(); this->myLabel->setPixmap(mat2QPixmap(this->background, QImage::Format_RGB888));
This code does not seem to work.
I guess that this happens because I chose the incorrect format.
-
Hi
Yes could be wrong format.
Try code from here
http://qtandopencv.blogspot.com/2013/08/how-to-convert-between-cvmat-and-qimage.html
Cant promise it works as i never used cv. -
Hi,
Are you sure your cv::Mat object contains RGB data ?
-
RGB, most likely, however it's likely not RGB888. You should check the format of your QImage object. As stated in the QPixmap::toImage documentation, it can be QImage::Format_ARGB32_Premultiplied for pixmaps with an alpha and QImage::Format_RGB32 or QImage::Format_RGB16 for pixmaps without alpha.