1、Mat转换为QImage
{
Mat rgb;
cvtColor(mat, rgb, CV_BGR2RGB);
return QImage((const unsigned char*)(rgb.data), rgb.cols, rgb.rows, QImage::Format_RGB888);
}
2、QImage转换为 Mat
Mat QImage2Mat(const QImage& qimage)
{Mat mat = Mat(qimage.height(), qimage.width(), CV_8UC4, (uchar*)qimage.bits(), qimage.bytesPerLine());
Mat mat2 = Mat(mat.rows, mat.cols, CV_8UC3 );
int from_to[] = { 0,0, 1,1, 2,2 };
mixChannels( &mat, 1, &mat2, 1, from_to, 3 );
return mat2;
}
转自:http://blog.sina.com.cn/s/blog_7559ce850100ydvy.html