如何找到一帧中物体质心与相邻帧之间的欧氏距离

How to find the euclidian distance between the centroid of an object in one frame and the adjacent frame

本文关键字:欧氏距离 之间 何找 一帧      更新时间:2023-10-16

我们正在进行一个车辆计数项目(使用OpenCV)。现在我们必须找到从一帧中对象质心到相邻帧的欧氏距离?在我们的项目中,我们已经找到了质心。

我假设相机在拍摄之间没有移动,这样您就不必担心注册了。

应该有两个cv::Point对象来表示两个获取的质心。欧几里得距离可以计算如下:

double euclideanDist(Point p, Point q)
{
    Point diff = p - q;
    return cv::sqrt(diff.x*diff.x + diff.y*diff.y);
}
int main(int /*argc*/, char** /*argv*/)
{
    Point centroid1(0.0, 0.0);
    Point centroid2(3.0, 4.0);
    cout << euclideanDist(centroid1, centroid2) << endl;
    return 0;
}

这输出5(即3-4-5三角形)。。。

希望能有所帮助!

如果pq的类型为int,请确保将(diff.x*diff.x + diff.y*diff.y)项类型转换为doublefloat。这样你就可以得到更精确的欧氏距离。