一、QImage转cv::Mat
QPixmap pixmap = currentImage->pixmap();
QImage image = pixmap.toImage();
//QImage image("d:/dev/test.jpg");
image = image.convertToFormat(QImage::Format_RGB888);//不管image的实际格式是单色图像/黑白图像、灰度图、具有不同深度的彩色图像,都转换为具有8位位深度和3通道的正常图像
cv::Mat mat = cv::Mat(
image.height(),
image.width(),
CV_8UC3,
image.bits(),
image.bytesPerLine());
二、cv::Mat转QImage进一步转为QPixmap
QPixmap::fromImage(
QImage(
mat .data,
mat .cols,
mat .rows,
mat .step,
QImage::Format_RGB888)
.rgbSwapped())
标签:pixmap,mat,image,OpenCV,cv,QImage,Mat From: https://www.cnblogs.com/zdt168/p/17054825.html