2014-03-24 62 views
1

我正在從0到1的範圍內獲得浮點圖像。我嘗試使用標籤在Qt中顯示此浮動圖像,但它不起作用。 我檢查了QImage格式,發現Qt不支持浮動圖像。現在我正在嘗試用這種方法..要在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(); 

以兩種方式執行後,我只得到一個黑色的圖像。 任何機構可以幫助我解決這個問題嗎?

回答

0

您需要通過因子255 規模的圖像可以通過改變

DepthImg.convertTo(img2, CV_8UC1); 

DepthImg.convertTo(img2, CV_8UC1, 255.0);