qt中使用opencv时,Qimage图像数据类型转成opencv的Mat类型

274 阅读1分钟

最近qt写代码的时候需要用到opencv,然后QImage转Mat,图像数据转换的时候纠结了挺久的,现在记录一下:

            QImage img;
            QByteArray tempBA;
            tempBA.clear();
            tempBA.resize(img.width()*img.height()*4);
            QBuffer buffer(&tempBA);
            buffer.open(QIODevice::WriteOnly);
            img.save(&buffer,"PNG");
            src = imdecode(vector<char>(tempBA.begin(), tempBA.end()), 1);