在C ++中优化两个向量之间的距离

时间:2019-04-09 12:23:58

标签: c++ math optimization least-squares

我有两个带有坐标的矢量,它们存储为OpenCV的浮点数:
a) dstpoints 是具有OpenCV点的向量-std::vector<cv::Point2f>(我的示例中有162个点,它们没有变化),
b) ppts 也是std::vector<cv::Point2f>,其大小与dstpoints相同:
std::vector<cv::Point2f> ppts = project_keypoints(params, input);
但是 ppts 依赖于其他两个向量:
- input 的长度为2 * 162 = 324,并且没有变化,
- params 长189,应该更改其值以获取变量 suma 的最小值,如下所示:

    double suma = 0.0;
    for (int i=0; i<dstpoints_size; i++)
    {
        suma += pow(dstpoints[i].x - ppts[i].x, 2);
        suma += pow(dstpoints[i].y - ppts[i].y, 2);
    }

我正在寻找 params 向量,该向量将为我提供 suma 变量的最小值。最小二乘算法似乎是解决它的一个不错的选择: https://en.wikipedia.org/wiki/Least_squares
我尝试了dlib版本:
http://dlib.net/dlib/optimization/optimization_least_squares_abstract.h.html#solve_least_squares
 但恐怕对我的情况不利。
我认为,我在dlib版本中遇到的问题是,对于每个不同的 params 向量,我都会得到不同的 ppts 向量,不仅是单个值,而且我不知道 dlib中的resolve_least_squares 函数可以匹配我的示例。
我正在寻找可以帮助解决问题的C ++解决方案(可能与优化程序一起使用)。

0 个答案:

没有答案