c++ - 在Qt中显示浮点图像

标签 c++ qt opencv

我得到一个 0 到 1 范围内的浮点图像。我试图在 Qt 中使用标签显示这个浮点图像,但它没有用。 我检查了 QImage 格式,发现 Qt 不支持 float 图像。现在我正在以这种方式尝试..

            QVector<QRgb> colorTable;
            for (int i = 0; i < 256; i++) 
            colorTable.push_back(qRgb(i, i, i));
             Mat img2;
            DepthImg.convertTo(img2, CV_8UC1);
            assert(img2.isContinuous());
            QImage image = QImage((unsigned char*)(img2.data), DepthImg.cols, DepthImg.rows, QImage::Format_Indexed8);
            image.setColorTable(colorTable);
            ui.ThreeD->setPixmap(QPixmap::fromImage(image, Qt::AutoColor));
            ui.ThreeD->setScaledContents(true);
            qApp->processEvents();
            this->ui.ThreeD->show();

这里的“DepthImage”是一个 float 图像。

 Mat img2;
 DepthImg.convertTo(img2, CV_8UC1);
 assert(img2.isContinuous());
 QImage image = QImage((unsigned char*)img2.data, img2.cols, img2.rows, img2.cols*3, QImage::Format_RGB888);
 ui.ThreeD->setPixmap(QPixmap::fromImage(image, Qt::AutoColor));
 ui.ThreeD->setScaledContents(true);
 qApp->processEvents();
 this->ui.ThreeD->show();

以两种方式执行后,我只得到一个黑色图像。 任何人都可以帮助我解决这个问题吗?

最佳答案

您需要按因子 255 缩放图像。 你可以通过改变来做到这一点

DepthImg.convertTo(img2, CV_8UC1);

DepthImg.convertTo(img2, CV_8UC1, 255.0);

关于c++ - 在Qt中显示浮点图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22618300/

相关文章:

c++ - 如何将地址转换为函数指针以调用方法

c++ - 如何更改 QToolButton 的 IconSize

python - PyQt:如何在子类 QWidget 中接收键盘事件?

c++ - "Could not demultiplex stream"在加载Opencv的VideoWriter录制的视频

python - 角优化方法 CORNER_REFINE_SUBPIX,来自 AcUro,使用 Python 和 OpenCV

c++ - 如何配置我的 CMake 文件以使用 Google Test 和 CTest?

c++ - QStyledItemDelegate中如何根据qStylesheet进行绘画

c++ - std::condition_variable 内存写入可见性

c++ - QGraphicsItem重绘

c++ - 为什么这行不通; opencv Mat_<float>