QImage mat2QImage(const Mat& mat){ int i = mat.channels(); Mat rgb; switch(i) { case 1: cvtColor(mat,rgb,CV_GRAY2RGB); break; case 2://never happen break; case 3: cvtColor(mat,rgb,CV_BGR2RGB); // for debug //cvShowImage("debug",(IplImage*)mat); break; case 4: cvtColor(mat,rgb,CV_BGRA2RGB); } //防止偏移 return QImage((const unsigned char*)rgb.data,rgb.cols,rgb.rows,rgb.cols*3,QImage::Format_RGB888).copy(0,0,rgb.cols,rgb.rows); } Mat qImage2Mat(const QImage& qimage){ int channel = qimage.bytesPerLine()/qimage.width(); Mat mat; switch (channel) { case 1: mat = Mat(qimage.height(),qimage.width(),CV_8UC1,(uchar*)qimage.bits(),size_t(qimage.bytesPerLine())); cvtColor(mat,mat,CV_GRAY2BGR); break; case 2://ne
Mat 与 QImage相互转换(亲测通过)
最新推荐文章于 2023-01-27 16:58:02 发布