使用gdal对图像建立金字塔
来源:互联网 发布:黑道圣徒4人物数据 编辑:程序博客网 时间:2024/04/30 09:13
对图像建立金字塔,参考了李民录的博客,给出了一个可以直接粘贴就能运行的代码
// CreatePyramids.cpp : 定义控制台应用程序的入口点。#define _AFXDLL#pragma#include "stdafx.h"#include "gdal.h"#include "gdal_priv.h"#include "afx.h"#pragma comment(lib,"gdal_i.lib")using namespace std;#pragma warning(disable: 4996)/** @brief 进度条基类** 提供进度条基类接口,来反映当前算法的进度值*/class CProcessBase{public: /** * @brief 构造函数 */ CProcessBase() { m_dPosition = 0.0; m_iStepCount = 100; m_iCurStep = 0; m_bIsContinue = true; } /** * @brief 析构函数 */ virtual ~CProcessBase() {} /** * @brief 设置进度信息 * @param pszMsg 进度信息 */ virtual void SetMessage(const char* pszMsg) = 0; /** * @brief 设置进度值 * @param dPosition 进度值 * @return 返回是否取消的状态,true为不取消,false为取消 */ virtual bool SetPosition(double dPosition) = 0; /** * @brief 进度条前进一步,返回true表示继续,false表示取消 * @return 返回是否取消的状态,true为不取消,false为取消 */ virtual bool StepIt() = 0; /** * @brief 设置进度个数 * @param iStepCount 进度个数 */ virtual void SetStepCount(int iStepCount) { ReSetProcess(); m_iStepCount = iStepCount; } /** * @brief 获取进度信息 * @return 返回当前进度信息 */ string GetMessage() { return m_strMessage; } /** * @brief 获取进度值 * @return 返回当前进度值 */ double GetPosition() { return m_dPosition; } /** * @brief 重置进度条 */ void ReSetProcess() { m_dPosition = 0.0; m_iStepCount = 100; m_iCurStep = 0; m_bIsContinue = true; } /*! 进度信息 */ string m_strMessage; /*! 进度值 */ double m_dPosition; /*! 进度个数 */ int m_iStepCount; /*! 进度当前个数 */ int m_iCurStep; /*! 是否取消,值为false时表示计算取消 */ bool m_bIsContinue; }; /*** @brief 控制台进度条类** 提供控制台程序的进度条类接口,来反映当前算法的进度值*/class CConsoleProcess : public CProcessBase{public: /** * @brief 构造函数 */ CConsoleProcess() { m_dPosition = 0.0; m_iStepCount = 100; m_iCurStep = 0; }; /** * @brief 析构函数 */ ~CConsoleProcess() { //remove(m_pszFile); }; /** * @brief 设置进度信息 * @param pszMsg 进度信息 */ void SetMessage(const char* pszMsg) { m_strMessage = pszMsg; printf("%s\n", pszMsg); } /** * @brief 设置进度值 * @param dPosition 进度值 * @return 返回是否取消的状态,true为不取消,false为取消 */ bool SetPosition(double dPosition) { m_dPosition = dPosition; TermProgress(m_dPosition); m_bIsContinue = true; return true; } /** * @brief 进度条前进一步 * @return 返回是否取消的状态,true为不取消,false为取消 */ bool StepIt() { m_iCurStep ++; m_dPosition = m_iCurStep*1.0 / m_iStepCount; TermProgress(m_dPosition); m_bIsContinue = true; return true; }private: void TermProgress(double dfComplete) { static int nLastTick = -1; int nThisTick = (int) (dfComplete * 40.0); nThisTick = MIN(40,MAX(0,nThisTick)); // Have we started a new progress run? if( nThisTick < nLastTick && nLastTick >= 39 ) nLastTick = -1; if( nThisTick <= nLastTick ) return ; while( nThisTick > nLastTick ) { nLastTick++; if( nLastTick % 4 == 0 ) fprintf( stdout, "%d", (nLastTick / 4) * 10 ); else fprintf( stdout, "." ); } if( nThisTick == 40 ) fprintf( stdout, " - done.\n" ); else fflush( stdout ); }};bool CreatePyramids(const char* pszFileName, CProcessBase *pProgress) { if (pProgress != NULL) { pProgress->SetMessage("创建金字塔"); } GDALAllRegister(); CPLSetConfigOption("USE_RRD","YES"); //创建Erdas格式的字塔文件 /* -------------------------------------------------------------------- */ /* Open data file. */ /* -------------------------------------------------------------------- */ GDALDatasetH hDataset; hDataset = GDALOpen( pszFileName, GA_ReadOnly ); GDALDriverH hDriver = GDALGetDatasetDriver(hDataset); const char* pszDriver = GDALGetDriverShortName(hDriver); if (EQUAL(pszDriver, "HFA") || EQUAL(pszDriver, "PCIDSK")) { GDALClose(hDataset); //如果文件是Erdas的img或者PCI的pix格式,创建内金字塔,其他的创建外金字塔 hDataset = GDALOpen( pszFileName, GA_Update ); } if( hDataset == NULL ) { if (pProgress != NULL) pProgress->SetMessage("打开图像失败,请检查图像是否存在或文件是否是图像文件!"); return false ; } /* -------------------------------------------------------------------- */ /* Get File basic infomation */ /* -------------------------------------------------------------------- */ int iWidth = GDALGetRasterXSize(hDataset); int iHeigh = GDALGetRasterYSize(hDataset); int iPixelNum = iWidth * iHeigh; //图像中的总像元个数 int iTopNum = 4096; //顶层金字塔大小,64*64 int iCurNum = iPixelNum / 4; int anLevels[1024] = { 0 }; int nLevelCount = 0; //金字塔级数 do //计算金字塔级数,从第二级到顶层 { anLevels[nLevelCount] = static_cast<int>(pow(2.0, nLevelCount+2)); nLevelCount ++; iCurNum /= 4; } while (iCurNum > iTopNum); const char *pszResampling = "nearest"; //采样方式 GDALProgressFunc pfnProgress = GDALTermProgress;//进度条 /* -------------------------------------------------------------------- */ /* Generate overviews. */ /* -------------------------------------------------------------------- */ if (nLevelCount > 0 && GDALBuildOverviews( hDataset,pszResampling, nLevelCount, anLevels, 0, NULL, pfnProgress, pProgress ) != CE_None ) { if (pProgress != NULL) return true ; } /* -------------------------------------------------------------------- */ /* Cleanup */ /* -------------------------------------------------------------------- */ GDALClose(hDataset); GDALDestroyDriverManager(); if (pProgress != NULL) pProgress->SetMessage("创建金字塔完成!"); return true; } int _tmain(int argc, _TCHAR* argv[]){ CConsoleProcess *pProgress = new CConsoleProcess(); bool f = CreatePyramids("C:\\tiff\\111.tif", pProgress); if (f == true) printf("计算成功/n"); else printf("计算失败/n"); delete pProgress; return 0;}
- 使用gdal对图像建立金字塔
- 使用GDAL建立影像金字塔
- gdal 图像金字塔
- GDAL读取图像文件,建立金字塔
- GDAL读取图像文件,建立金字塔
- GDAL读取图像文件,建立金字塔
- GDAL金字塔
- 使用GDAL创建Erdas格式的金字塔
- [转]使用GDAL创建Erdas格式的金字塔
- gdal使用经验(一)影像读取-生成金字塔
- gdal 工具创建金字塔
- GDAL构建金字塔
- 使用gdal对图像重采样再按指定格式输出
- 如何使用GDAL重采样图像
- 如何使用GDAL进行图像镶嵌
- 如何使用GDAL重采样图像 .
- 使用C#版本GDAL读取复数图像
- Ubuntu的遥感图像库GDAL使用
- 视频会议将是未来即时通讯平台的主流
- 模块及模块间的接口方式
- 【小蒙淘金】11.4金评-非农强势即将来袭,一级战斗准备
- createBitmap时out of memory!!!!!!!
- HTTP与socket的介绍与区别分析
- 使用gdal对图像建立金字塔
- 在Ubuntu10.10下采用Android NDK r6b 编译开源项目ffmpeg0.8.1
- Android SDCard Mount流程分析(一)(二)(三)
- Java的正则表达式(RegularExpressions)
- MongoDB 入门 (一) 安装 部署
- 在类结构中,"is a"和"has a"的不同点
- session.load()和session.get()的区别
- 多单、空单、开仓、平仓、持仓、现货、期货、通货膨胀.......
- 从request获取各种路径总结