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

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

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


/* 2.检测Fast特征点 */
    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<uchar>(x,y)) - double(first_image.at<uchar>(x, y-3));
            delta[0] = panduan(diff[0], threshold);
            diff[8] = double(first_image.at<uchar>(x,y)) - double(first_image.at<uchar>(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<uchar>(x,y)) - double(first_image.at<uchar>(x-3, y));
                delta[12] = panduan(diff[12], threshold);
                diff[4] = double(first_image.at<uchar>(x,y)) - double(first_image.at<uchar>(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<uchar>(x,y)) - double(first_image.at<uchar>(x+1, y-3));
                    delta[1] = panduan(diff[1],threshold);
                    diff[2] = double(first_image.at<uchar>(x,y)) - double(first_image.at<uchar>(x+2, y-2));
                    delta[2] = panduan(diff[2],threshold);
                    diff[3] = double(first_image.at<uchar>(x,y)) - double(first_image.at<uchar>(x+3, y-1));
                    delta[3] = panduan(diff[3],threshold);
                    diff[5] = double(first_image.at<uchar>(x,y)) - double(first_image.at<uchar>(x+3, y+1));
                    delta[5] = panduan(diff[5],threshold);
                    diff[6] = double(first_image.at<uchar>(x,y)) - double(first_image.at<uchar>(x+2, y+2));
                    delta[6] = panduan(diff[6],threshold);
                    diff[7] = double(first_image.at<uchar>(x,y)) - double(first_image.at<uchar>(x+1, y+3));
                    delta[7] = panduan(diff[7],threshold);
                    diff[9] = double(first_image.at<uchar>(x,y)) - double(first_image.at<uchar>(x-1, y+3));
                    delta[9] = panduan(diff[9],threshold);
                    diff[10] = double(first_image.at<uchar>(x,y)) - double(first_image.at<uchar>(x-2, y+2));
                    delta[10] = panduan(diff[10],threshold);
                    diff[11] = double(first_image.at<uchar>(x,y)) - double(first_image.at<uchar>(x-3, y+1));
                    delta[11] = panduan(diff[11],threshold);
                    diff[13] = double(first_image.at<uchar>(x,y)) - double(first_image.at<uchar>(x-3, y-1));
                    delta[13] = panduan(diff[13],threshold);
                    diff[14] = double(first_image.at<uchar>(x,y)) - double(first_image.at<uchar>(x-2, y-2));
                    delta[14] = panduan(diff[14],threshold);
                    diff[15] = double(first_image.at<uchar>(x,y))- double(first_image.at<uchar>(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<float>(x, y) = getSum(diff, 16); //差值越大得分越高
                            fastImg.at<uchar>(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<threshold)
    {
        delta = 0 ;
    }
    return delta;
}

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

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值