我得到一个 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/