opencv Mat 与 Qt QImage之间的转换

    xiaoxiao2026-05-05  2

    opencv Mat 与 Qt QImage 之间的转换,下面是两个例子,其他可相似处理

    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; }

    转载请注明原文地址: https://ju.6miu.com/read-1309379.html
    最新回复(0)