RANSAC 加Guass-newton拟合曲线

本文介绍了如何结合RANSAC(随机样本一致性)算法与Gauss-Newton算法来拟合一次函数和二次函数。通过参考链接提供了详细步骤和技术解释。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里写图片描述

#include <iostream>
#include <fstream>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <Eigen/Core>
#include <Eigen/Dense>

using namespace std;



vector<int> getRandomSample(int n, int num)
{
    vector<int> sample;
    vector<int> total_set;
    for(int i = 0; i < n; ++i)
        total_set.push_back(i);
    for(int i = 0; i < num; ++i)
    {
        int j = rand()%total_set.size();
        sample.push_back( total_set[j] );
        total_set.erase( total_set.begin()+j );
    }
    return sample;
}

//k次函数
double funcX(double* a, double x, int k)
{
    double xx = 1.0;
    double y = 0;
    for(int i = 0; i < k; i++)
    {
        y = y + a[i]*xx;
        xx *= x;
    }
    return y;
}

vector<int> get_inliners(vector<cv::Point2d>& points, double* a, int k)
{
    double inlier_threshold = 5;
    vector<int> inliers;

    for(int i = 0; i < points.size(); i++)
    {
        cv::Point2d p = points[i];
        double y_predict = funcX(a, p.x, k);
        if( fabs(p.y - y_predict) < inlier_threshold)
            inliers.push_back( i );
    }
    cout << "inliers:" << inliers.size() << "\n";
    return inliers;
}

bool estimateLine(vector<cv::Point2d>& points, vector<int>&active, double* a, int k)
{
    const double learning_rate = 0.1;
    
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值