opencv--相关系数法影像匹配

这篇博客介绍了如何使用OpenCV库进行相关系数法的影像匹配,特别是在数字摄影测量中的应用。作者通过整合三部分代码,并针对不同OpenCV编译版本调整了函数用法,实现了影像匹配的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考博客(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+
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值