C++实现Forster点特征提取
前言
该算子由德国伯恩大学摄影测量系主任、教授 Forster1984年提出的。本文介绍如何使用C++实现该算子
一、原理
计算各像素的Robert’s梯度和像素(c,r)为中心的一个窗口的灰度协方差矩阵,在影像中寻找具有尽可能小而接近圆的误差椭圆的点作为特征点
二、使用步骤
1.实现步骤
step1: 计算各个像素的Robert梯度
step2:窗口中灰度的协方差矩阵
step3:兴趣值q和权w的计算公式
step4: 阈值的选定
step5: 确定待选点
step6: 选取极值点
(阈值范围:)

2.C++代码
// forstner.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include<string>
#include<cmath>
#include<vector>
#include<gdal.h>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/opencv.hpp>
#include "cpl_conv.h"
#include<cstring>
using namespace std;
using namespace cv;
void Forstner(Mat img,Mat img2,string str2)
{
/*
step1:计算各个像素的Robert梯度
f_x = f(x + 1, y + 1) - f(x, y)
f_y = f(x + 1, y) - f(x, y + 1)
*/
int gu=0, gv=0;//xy方向梯度
int r, c;
int add;
int rows = img.rows - 1;
int cols = img.cols - 1;
// Mat G(rows + 1, cols + 1, CV_32FC3, Scalar::all(0));//计算各像素的Robert梯度
Mat GU(rows + 1, cols + 1, CV_32FC1, Scalar::all(0));//用来存放gu的矩阵
Mat GV(rows + 1, cols + 1, CV_32FC1, Scalar::all(0));//用来存放gv的矩阵
for ( r = 0; r < rows +1; r++)
{
for ( c = 0; c < cols +1; c++)
{
add = 1;//des=1;
//if (c == 0 || r == 0) des = 0;
if (r == rows || c == cols) add = 0;
GU.at<float>(r, c)=

本文详细介绍了如何使用C++实现Forster点特征提取算法,包括计算像素的Robert梯度、协方差矩阵、兴趣值q和权w的计算,以及阈值选定和极值点选取过程。通过实例代码展示了具体实现步骤,并给出了运行结果,展示了特征点的提取效果。
最低0.47元/天 解锁文章
986

被折叠的 条评论
为什么被折叠?



