为了账号安全,请及时绑定邮箱和手机立即绑定

如何将opencv cv :: Mat转换为qimage

如何将opencv cv :: Mat转换为qimage

C++
萧十郎 2019-08-19 14:34:34
如何将opencv cv :: Mat转换为qimage我想知道如何将OpenCV C ++标准cv :: Mat类型转换为Qimage。我一直在寻找,但没有运气。我找到了一些将IPlimage转换为Qimage的代码,但这不是我想要的。谢谢
查看完整描述

3 回答

?
呼唤远方

TA贡献1856条经验 获得超11个赞

这是24位RGB和灰度浮点的代码。可轻松调节其他类型。它尽可能高效。

QImage Mat2QImage(const cv::Mat3b &src) {
        QImage dest(src.cols, src.rows, QImage::Format_ARGB32);
        for (int y = 0; y < src.rows; ++y) {
                const cv::Vec3b *srcrow = src[y];
                QRgb *destrow = (QRgb*)dest.scanLine(y);
                for (int x = 0; x < src.cols; ++x) {
                        destrow[x] = qRgba(srcrow[x][2], srcrow[x][1], srcrow[x][0], 255);
                }
        }
        return dest;}QImage Mat2QImage(const cv::Mat_<double> &src){
        double scale = 255.0;
        QImage dest(src.cols, src.rows, QImage::Format_ARGB32);
        for (int y = 0; y < src.rows; ++y) {
                const double *srcrow = src[y];
                QRgb *destrow = (QRgb*)dest.scanLine(y);
                for (int x = 0; x < src.cols; ++x) {
                        unsigned int color = srcrow[x] * scale;
                        destrow[x] = qRgba(color, color, color, 255);
                }
        }
        return dest;}


查看完整回答
反对 回复 2019-08-19
  • 3 回答
  • 0 关注
  • 1435 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信