• 大小: 6KB
    文件类型: .cpp
    金币: 1
    下载: 0 次
    发布日期: 2021-05-23
  • 语言: C/C++
  • 标签: c++  moravec  opencv  

资源简介

用c++配置opencv库实现的提取点特征的moravec算子,自己编写,完全可用

资源截图

代码片段和文件信息

// M算子.cpp: 定义控制台应用程序的入口点。
//

#include “stdafx.h“
#include  
#include“opencv2/highgui/highgui.hpp“    
#include  
#include  
#include  


using namespace std;
using namespace cv;

uchar getpix(Mat& src int x int y)
{
uchar* pt = src.ptr(y);
return pt[x];
}
void setMatpix(Mat& dst int x int y float value)
{
uchar* pt = dst.ptr(y);
pt[x] = value;
}
/*
src:输入图像
kernel:移动的窗口的大小
threshold:设置的阀值大小
*/
void Moravec(Mat& src int kernal float threshold vector* corPoint)
{
int halfKernal = kernal / 2;
//float moveValue[4] = { 0 };  
float minValue;
Mat dst(src.size() CV_8UC1 Scalar(0));
//遍历图像时候,没有对图像的边缘进行处理(边缘是窗口大小一半)  
for (int y = halfKernal; y < src.rows - halfKernal; y++)
{

for (int x = halfKernal; x < src.cols - halfKernal; x++)
{
float moveValue[4] = { 0 };
//对图像的每一个点在 0°、45°、90°135°的变化量  
for (int win = -halfKernal; win < halfKernal; win++)
{
moveValue[0] += pow(getpix(src x + win y) - getpix(src x + win + 1 y) 2);//0°方向变化量  
moveValue[1] += pow(getpix(src x + win y + win) - getpix(src x + win + 1 y + win + 1) 2);//45°方向变化量  
moveValue[2] += pow(getpix(src x y + win) - getpix(src x y + win + 1) 2);//90°方向变化量  
moveValue[3] += pow(getpix(src x - win y + win) - getpix(src x - win - 1 y + win + 1) 2);//135°方向变化量  

}
//计算四个方向移动的最小值  
minValue = moveValue[0];
minValue = minValue > moveValue[1] ? moveValue[1] : minValue;
minValue = minV

评论

共有 条评论