结合 deepseek,通义千问的答案理解opencv 估计刚体变换矩阵(Ransac)

cpp 复制代码
/*
 * Compute
 *  x    c -s    X    t1
 *    =       *     +
 *  y    s  c    Y    t2
 *
 *  - every element in _m1 contains (X,Y), which are called source points
 *  - every element in _m2 contains (x,y), which are called destination points
 *  - _model is of size 2x3, which contains
 *    c  -s  t1
 *    s   c  t2
 */
class AffinePartial2DEstimatorCallback : public Affine2DEstimatorCallback
{
public:
    int runKernel( InputArray _m1, InputArray _m2, OutputArray _model ) const CV_OVERRIDE
    {
        Mat m1 = _m1.getMat(), m2 = _m2.getMat();
        const Point2f* from = m1.ptr<Point2f>();
        const Point2f* to   = m2.ptr<Point2f>();
        _model.create(2, 3, CV_64F);
        Mat M_mat = _model.getMat();
        double *M = M_mat.ptr<double>();

        // we need only 2 points to estimate transform
        double x1 = from[0].x;
        double y1 = from[0].y;
        double x2 = from[1].x;
        double y2 = from[1].y;

        double X1 = to[0].x;
        double Y1 = to[0].y;
        double X2 = to[1].x;
        double Y2 = to[1].y;

        /*
        we are solving AS = B
            | x1 -y1 1 0 |
            | y1  x1 0 1 |
        A = | x2 -y2 1 0 |
            | y2  x2 0 1 |
        B = (X1, Y1, X2, Y2).t()
        we solve that analytically
        */
        double d = 1./((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));

        // solution vector
        //a=S0 Scalexcos(theta)=|V|.|v|.cos(theta)/(|V|.|v|.cos(0))
        double S0 = d * ( (X1-X2)*(x1-x2) + (Y1-Y2)*(y1-y2) );
        //b=Scalexsin(theta)=|V|x|v|.sin(theta)/(|V|.|v|.cos(0))
        double S1 = d * ( (Y1-Y2)*(x1-x2) - (X1-X2)*(y1-y2) );
        //S2=tx=X1−(ax1−by1),a,b带入验证
        double S2 = d * ( (Y1-Y2)*(x1*y2 - x2*y1) - (X1*y2 - X2*y1)*(y1-y2) - (X1*x2 - X2*x1)*(x1-x2) );
        //S3=ty=Y1−(bx1+ay1),a,b带入验证
        double S3 = d * (-(X1-X2)*(x1*y2 - x2*y1) - (Y1*x2 - Y2*x1)*(x1-x2) - (Y1*y2 - Y2*y1)*(y1-y2) );

        // set model, rotation part is antisymmetric
        M[0] = M[4] = S0;
        M[1] = -S1;
        M[2] = S2;
        M[3] = S1;
        M[5] = S3;
        return 1;
    }
};

个人感觉deepseek的答案确实更好,但代码注释中的验证理解还是靠自己的仅有的一点数学知识得以完成,特别是S2,S3,虽然AI 都给出了代入方程验证的提示

相关推荐
新加坡内哥谈技术4 分钟前
大型语言模型Claude的“思维模式”最近被公开解剖
人工智能·语言模型·自然语言处理
Mostcow18 分钟前
数据分析_Data-Formulator-0.1.7调用Ollama-0.5问题记录
人工智能·数据挖掘·数据分析
Hali_Botebie1 小时前
【蒸馏用损失】NCEloss介绍,大规模分类任务的损失函数
人工智能·分类·数据挖掘
阿里云云原生1 小时前
RAG 调优指南:Spring AI Alibaba 模块化 RAG 原理与使用
java·人工智能·spring
蚍蜉撼树谈何易1 小时前
机器学习的定义及分类
人工智能·机器学习·分类
城电科技2 小时前
城电科技|零碳美丽示范村建设方案 能源+景观+教育
人工智能·科技·生活·能源
opentrending7 小时前
Github 热点项目 awesome-mcp-servers MCP 服务器合集,3分钟实现AI模型自由操控万物!
服务器·人工智能·github
lisw057 小时前
DeepSeek原生稀疏注意力(Native Sparse Attention, NSA)算法介绍
人工智能·深度学习·算法
whaosoft-1438 小时前
51c深度学习~合集4
人工智能
逢生博客8 小时前
阿里 FunASR 开源中文语音识别大模型应用示例(准确率比faster-whisper高)
人工智能·python·语音识别·funasr