OPenCV笔记-Mat转Base64(使用Qt进行转换)
Posted IT1995
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OPenCV笔记-Mat转Base64(使用Qt进行转换)相关的知识,希望对你有一定的参考价值。
关键代码如下:
std::vector<uint8_t> buffer;
cv::imencode(".png", mat, buffer);
QByteArray byteArray = QByteArray::fromRawData((const char*)buffer.data(), buffer.size());
QString base64Image(byteArray.toBase64());
qDebug() << base64Image;
打印如下:
"iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAL+0lEQVR4AeXBUa0kUAhEwdNOEIEYJCIGEThhHdz56Ewmm1clTFN7GLJDPEzt8ZAd4mFqD0N2iIepPR6yQzxM7WHIDmEQpqk9DNkhHqb2eMgO8TC1hyE7xMPUHg/ZIR6m9jBkhzAI09QehuwQD1N7PGSHeJjaw5Ad4mFqj4fsEA9TexiyQxiEaWoPQ3aIh6k9HrJDPEztYcgO8TC1x0N2iIepPQzZIQzCNLWHITvEw9QeD9khHqb2MGSHeJja4yE7xMPUHobsEAZhmtrDkB3iYWqPh+wQD1N7GLJDPEzt8ZAd4mFqD0N2CIMwTe1hyA7xMLXHQ3aIh6k9DNkhHqb2eMgO8TC1hyE7hEGYpvYwZId4mNrjITvEw9QehuwQD1N7PGSHeJjaw5AdwiBMU3sYskMYpvZ4yA5hmNrjITuEYWoPQ3YIgzBN7WHIDmGY2uMhO4Rhao+H7BCGqT0M2SEMwjS1hyE7hGFqj4fsEIapPR6yQxim9jBkhzAI09QehuwQhqk9HrJDGKb2eMgOYZjaw5AdwiBMU3sYskMYpvZ4yA5hmNrjITuEYWoPQ3YIgzBN7WHIDmGY2uMhO4Rhao+H7BCGqT0M2SEMwjS1hyE7hGFqj4fsEIapPR6yQxim9jBkhzAI09QehuwQhqk9HrJDGKb2eMgOYZjaw5AdwiA+mNrDkB3CMLXHQ3aIH5ra4yE7hGFqD0N2iAfxwdQehuwQhqk9HrJD/NDUHg/ZIQxTexiyQzyID6b2MGSH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Y1B5flB3CIExTe3xRdoj/2NQeX5QdwiBMU3t8UXaI/9jUHl+UHcIgTFN7fFF2iP/Y1B5flB3CIExTe3xRdoj/2NQeX5QdwiBMU3t8UXaI/9jUHl+UHcIgTFN7fFF2iP/Y1B5flB3C8A9omeDb88dvAAAAAABJRU5ErkJggg=="
这里我们找个在线解析的来试试:
这里要注意html中img标签使用的规则:
Base64 在HTML中的使用
<img width="40" height="30" src="data:image/jpg;base64,/9j/4QMZRXhpZgAASUkqAAgAAAAL...." />
此时图片正常显示了。
以上是关于OPenCV笔记-Mat转Base64(使用Qt进行转换)的主要内容,如果未能解决你的问题,请参考以下文章
OpenCV在带有C++的iOS上使用base64通过HTTP发送图像
经验分享opencv Mat 转 darknet Image 数据结构