栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

2021-10-10 手写fast特征点提取

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

2021-10-10 手写fast特征点提取

** 从网上有查手写的fast特征点提取,但是发现他们的约束条件相对于fast的条件宽松了两个地方,一个是无论大于阈值还是小于阈值视为一类,还有就是,仅计算了16个点中一共有12个或以上的点符合条件,忽略了连续12个点的条件,因此在提取的时候出现了特征点的数目会很多,因此做了一些修改。**

void ComputeFast(const cv::Mat &first_image,cv::Mat &fastImg,cv::Mat &fastScore,vector &keypoints){
    int rows, cols, threshold;
    rows = first_image.rows;
    cols = first_image.cols;
    threshold = 40;



    for(int x = 3; x < rows - 3; x++)
    {
        for(int y = 3; y < cols - 3; y++)
        {
            double delta[16] = {0};
            double diff[16] = {0};
            diff[0] = double(first_image.at(x,y)) - double(first_image.at(x, y-3));
            delta[0] = panduan(diff[0], threshold);
            diff[8] = double(first_image.at(x,y)) - double(first_image.at(x, y+3));
            delta[8] = panduan(diff[8], threshold);
            int p = delta[0]+delta[8];
            if(p != 2 && p != -2)
                continue;
            else
            {
                diff[12] = double(first_image.at(x,y)) - double(first_image.at(x-3, y));
                delta[12] = panduan(diff[12], threshold);
                diff[4] = double(first_image.at(x,y)) - double(first_image.at(x+3, y));
                delta[4] = panduan(diff[4],threshold);
                p = p+delta[12]+delta[4];
                if(p>=-1 && p<=1)
                    continue;
                else
                {
                    diff[1] = double(first_image.at(x,y)) - double(first_image.at(x+1, y-3));
                    delta[1] = panduan(diff[1],threshold);
                    diff[2] = double(first_image.at(x,y)) - double(first_image.at(x+2, y-2));
                    delta[2] = panduan(diff[2],threshold);
                    diff[3] = double(first_image.at(x,y)) - double(first_image.at(x+3, y-1));
                    delta[3] = panduan(diff[3],threshold);
                    diff[5] = double(first_image.at(x,y)) - double(first_image.at(x+3, y+1));
                    delta[5] = panduan(diff[5],threshold);
                    diff[6] = double(first_image.at(x,y)) - double(first_image.at(x+2, y+2));
                    delta[6] = panduan(diff[6],threshold);
                    diff[7] = double(first_image.at(x,y)) - double(first_image.at(x+1, y+3));
                    delta[7] = panduan(diff[7],threshold);
                    diff[9] = double(first_image.at(x,y)) - double(first_image.at(x-1, y+3));
                    delta[9] = panduan(diff[9],threshold);
                    diff[10] = double(first_image.at(x,y)) - double(first_image.at(x-2, y+2));
                    delta[10] = panduan(diff[10],threshold);
                    diff[11] = double(first_image.at(x,y)) - double(first_image.at(x-3, y+1));
                    delta[11] = panduan(diff[11],threshold);
                    diff[13] = double(first_image.at(x,y)) - double(first_image.at(x-3, y-1));
                    delta[13] = panduan(diff[13],threshold);
                    diff[14] = double(first_image.at(x,y)) - double(first_image.at(x-2, y-2));
                    delta[14] = panduan(diff[14],threshold);
                    diff[15] = double(first_image.at(x,y))- double(first_image.at(x-1, y-3));
                    delta[15] = panduan(diff[15],threshold);

                    int sum = 0;
                    for(int i=0;i<5; i++)
                    {
                        for (int j = 0;j<12;j++)
                        {
                            sum += delta[i+j];
                        }
                        if(sum == 12 || sum == -12) {
                            keypoints.push_back(Point(y, x));
                            fastScore.at(x, y) = getSum(diff, 16); //差值越大得分越高
                            fastImg.at(x, y) = 255;
                            break;
                        }
                        else{
                            sum = 0;
                        }
                    }
                }
            }
        }
    }
}



int getSum(double *p, int length)
{
    int sum = 0;
    for (int i = 0; i < length; i++)
    {
        sum += abs(*(p + i));
    }
    return sum;
}




int panduan(double diff,double threshold){
    int delta;
    if (diff > threshold)
    {
        delta = 1;
    }
    else if(diff<-threshold)
    {
        delta = -1;
    }
    else if(diff>-threshold && diff 

仅仅是针对原先条件不准确做的一些修改,刚开始研究一两个月,希望大家可以多多交流。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/311885.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号