参考博客(5条消息) opencv--相关系数法影像匹配(数字摄影测量)_qiulanz的博客-优快云博客_相关系数影像匹配
参考的代码分成了3部分,将3部分代码整合并且由于使用的opencv编译版本不一样,部分opencv自带的函数使用不一样
ZQLImgPro.h #pragma once #include"opencv2\core\core.hpp" using namespace cv; class CZQLImgPro { public: CZQLImgPro(void); ~CZQLImgPro(void); CZQLImgPro(int n_windowsize,float d_sigma);//构造函数重载(设置高斯滤波参数) CZQLImgPro(int i_binaryT); //构造函数重载(设置阈值分割参数) private: int nwindowsize; //高斯滤波器的大小 float sigma; //高斯滤波器方差 Mat Gauss; //高斯滤波器 int binaryT; //二值化阈值 private: void CreatGauss(); //生成高斯滤波器 public: void setGauss(int n_windowsize,float d_sigma); //设置高斯滤波参数 void setBinaryT(int i_binaryT); //设置二值化阈值 void BinaryImg(const Mat srcimg,Mat &result); //阈值分割函数 void Gaussianfilter(const Mat srcimg,Mat &result);//高斯滤波 }; ZQLImgPro.cpp #include"ZQLImgPro.h" #include"math.h" const float PI=4.0*atan(1.0); //默认构造函数 CZQLImgPro::CZQLImgPro(void) { nwindowsize=0; sigma=0; Gauss.create(nwindowsize,nwindowsize,CV_32F); } //析构函数 CZQLImgPro::~CZQLImgPro(void) { } //构造函数重载(设置高斯滤波参数) CZQLImgPro::CZQLImgPro(int n_windowsize,float d_sigma) { nwindowsize=n_windowsize; sigma=d_sigma; Gauss.create(nwindowsize,nwindowsize,CV_32F); } //构造函数重载(设置阈值分割参数) CZQLImgPro::CZQLImgPro(int iBinaryT) { binaryT=iBinaryT; } //设置高斯滤波参数 void CZQLImgPro::setGauss(int n_windowsize,float d_sigma) { nwindowsize=n_windowsize; sigma=d_sigma; Gauss.create(nwindowsize,nwindowsize,CV_32F); } //设置二值化阈值 void CZQLImgPro::setBinaryT(int iBinaryT) { binaryT=iBinaryT; } //阈值分割函数 void CZQLImgPro::BinaryImg(const Mat srcimg,Mat&result) { //给目标影像分配内存 result.create(srcimg.rows,srcimg.cols,srcimg.type()); for (int i=0;i<srcimg.rows;i++) { for (int j=0;j<srcimg.cols;j++) { int graytmp=srcimg.at<uchar>(i,j); if (graytmp>binaryT) //大于阈值赋予255否则赋予0 result.at<uchar>(i,j)=255; else result.at<uchar>(i,j)=0; } } } //生成高斯滤波器 void CZQLImgPro::CreatGauss() { float sum=0; for(int i=0;i<nwindowsize;i++) { for(int j=0;j<nwindowsize;j++) { int x=i-(nwindowsize-1)/2; int y=j-(nwindowsize-1)/2; Gauss.at<float>(i,j)=exp(-(x*x+y*y)/(2*sigma*sigma)) /(2*PI*sigma*sigma);//利用高斯公式计算计算滤波器 //float m=exp(-(x*x+