利用opencv读取图像并显示,读取jpg或png等常用格式没问题,但读取tif图像老是失败,各位有知道原因的吗?下面附上代码,试了各种tif图像,有1个波段的、2个波段的、5个波段的,1个波段的能读取,5个的不行。
//cvFileName为"C:\test.tif"
cv::String cvFileName = fileName.toStdString();
Mat srcImg = imread(cvFileName, 4);
if (srcImg.empty())
{
QMessageBox::information(this, "waring", "failed to read the image");
return;
}
Mat imgShow;
cvtColor(srcImg, imgShow, COLOR_BGR2RGB);
QImage qImg = QImage((unsigned char*)(imgShow.data), imgShow.cols,
imgShow.rows, imgShow.cols*imgShow.channels(), QImage::Format_RGB888);
ui.imgLabel->setPixmap(QPixmap::fromImage(qImg.scaled(ui.imgLabel->size(), Qt::KeepAspectRatio)));