Harris、SHI-TOMASI角点检测opencv源码总结

本文介绍了作者在项目中使用opencv进行角点检测的实践,发现内置接口效果不理想后,深入研究了Harris和SHI-TOMASI角点检测的opencv源码,并进行了整理,虽然未能在此基础上进行修改优化,但仍提供了宝贵的理论知识。
摘要由CSDN通过智能技术生成

       最近一个项目需要进行图像的角点检测,但是用opencv提供的各种接口效果并不是很理想,于是想探究一下它们的实现,所以看了其源码并且摘录下来,整理了一下,本想在源码的基础上再修改修改但无耐没有思路。以下使自己的整理:

#include<opencv2/core/core.hpp>  
#include<opencv2/highgui/highgui.hpp>  
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv\cv.h>
#include <iomanip>
#include <math.h>
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace cv;
using namespace std;

#define SHI_TOMASI 0
#define HARRIS     1
template<typename T> struct greaterThanPtr
{
    bool operator()(const T* a, const T* b) const { return *a > *b; }
};

void mycalcMinEigenVal( const Mat& _cov, Mat& _dst )
{
	_dst=Mat(_cov.size(),CV_32FC1);
    int i, j;
    Size size = _cov.size();
    if( _cov.isContinuous() && _dst.isContinuous() )
    {
        size.width *= size.height;
        size.height = 1;
    }

    for( i = 0; i < size.height; i++ )
    {
        const float* cov = (const float*)( _cov.data + _cov.step*i);
        float* dst = (float*)( _dst.data + _dst.step*i);
        j = 0;
        for( ; j < size.width; j++ )
        {
            float a = cov[j*3]*0.5f;
            float b = cov[j*3+1];
            float c = cov[j*3+2]*0.5f;
            dst[j] = (float)((a + c) - std::sqrt((a - c)*(a - c) + b*b));
        }
    }
}
void mycalcHarris( const Mat& _cov, Mat& _dst, double k )
{
	_dst=Mat(_cov.size(),CV_32FC1);
    int i, j;
    Size size = _cov.size();
    if( _cov.isContinuous() && _dst.isContinuous() )
    {
        size.width *= size.height;
        size.height = 1;
    }

    for( i = 0; i < size.height; i++ )
    {
        const float* cov = (const float*)(_cov.data + _cov.step*i);
        float* dst = (float*)(_dst.data + _dst.step*i);
        j = 0;  
        for( ; j < size.width; j++ )
        {
            float a = cov[j*3];
            float b = cov[j*3+1];
            float c = cov[j*3+2];
            dst[j] = (float)(a*c - b*b - k*(a + c)*(a + c));
        }
    }
}
void mycornerDetection(const Mat& src, Mat& eigenv, int block_size,int aperture_size, int op_type, double k,int borderType=BORDER_DEFAULT )
{
	Mat Dx, Dy;
    if( aperture_size > 0 )
    {
        Sobel( src, Dx, C
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值