建设电影网站广告哪里找,莱芜最新钟点工招聘,青岛市黄岛区建设局网站,wordpress应用主题出错程序示例精选 VSQtC GDAL读取tif图像数据显示 如需安装运行环境或远程调试#xff0c;见文章底部个人QQ名片#xff0c;由专业技术人员远程协助#xff01; 前言
这篇博客针对《VSQtC GDAL读取tif图像数据显示》编写代码#xff0c;代码整洁#xff0c;规则#xff0c;… 程序示例精选 VSQtC GDAL读取tif图像数据显示 如需安装运行环境或远程调试见文章底部个人QQ名片由专业技术人员远程协助 前言
这篇博客针对《VSQtC GDAL读取tif图像数据显示》编写代码代码整洁规则易读。 学习与应用推荐首选。 运行结果 文章目录
一、所需工具软件 二、使用步骤 1. 主要代码 2. 运行结果 三、在线协助
一、所需工具软件 1. VS2019, Qt 2. C
二、使用步骤
代码如下示例
#include MainWindow.h
#includeiostream
#include gdal_priv.h
#include cpl_conv.h
#include QApplication
#include QImage
#include QLabel
#include opencv.hpp
using namespace std;
using namespace cv;
//gdal读取tiff图像波段另存为jpg通过opencv显示图像
void MainWindow::On_tiff_File()
{std::cout modelRun std::endl;GDALAllRegister();// 打开TIFF文件GDALDataset* dataset (GDALDataset*)(dd.tiff, GA_ReadOnly);if (dataset NULL) {std::cout 打开文件失败;return;}// 获取影像信息int width dataset-GetRasterXSize();int height dataset-GetRasterYSize();// 读取各波段数据并合成std::vectorcv::Mat bands;for (int i 1; i numBands; i) {GDALRasterBand* band dataset-GetRasterBand(i);cv::Mat bandData(height, width, CV_8U);band-RasterIO(GF_Read, 0, 0, bandData.data, width, height, GDT_Byte, 0, 0);bands.push_back(bandData);}// 合成多波段数据这里简单地将各波段叠加cv::Mat compositeImage(height, width, CV_8U, cv::Scalar(0));for (const auto band : bands) {compositeImage band;}// 将图像保存为JPEG格式std::string imagePath output.jpg; // 保存图像的路径cv::imwrite(imagePath, compositeImage);// 重新打开JPEG图像文件cv::Mat frame cv::imread(imagePath, cv::IMREAD_COLOR);//cvtColor(frame, frame, COLOR_RGB2BGR); //// 设置窗口大小策略允许窗口自由拉伸ui.label-setPixmap(QPixmap::fromImage(img));ui.label-setScaledContents(true);ui.label-update();// 释放资源GDALClose(dataset);
}
运行结果 三、在线协助
如需安装运行环境或远程调试见文章底部个人 QQ 名片由专业技术人员远程协助 1远程安装运行环境代码调试 2Visual Studio, Qt, C, Python编程语言入门指导 3界面美化 4软件制作 当前文章连接https://blog.csdn.net/alicema1111/article/details/132666851 个人博客主页https://blog.csdn.net/alicema1111?typeblog 博主所有文章点这里https://blog.csdn.net/alicema1111?typeblog