【问题标题】:To display float point image in Qt在 Qt 中显示浮点图像
【发布时间】:2014-03-24 19:01:55
【问题描述】:

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

            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”是一个浮点图像。

 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();

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

【问题讨论】:

    标签: c++ qt opencv


    【解决方案1】:

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

    DepthImg.convertTo(img2, CV_8UC1);
    

    与

    DepthImg.convertTo(img2, CV_8UC1, 255.0);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-06
      • 1970-01-01
      • 1970-01-01
      • 2012-02-25
      • 1970-01-01
      • 1970-01-01
      • 2018-11-24
      相关资源
      最近更新 更多