如何找到一帧中物体质心与相邻帧之间的欧氏距离
How to find the euclidian distance between the centroid of an object in one frame and the adjacent frame
我们正在进行一个车辆计数项目(使用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三角形)。。。
希望能有所帮助!
如果p
和q
的类型为int
,请确保将(diff.x*diff.x + diff.y*diff.y)
项类型转换为double
或float
。这样你就可以得到更精确的欧氏距离。
相关文章:
- 用C++程序计算圆锥体的体积、球体的体积、八边形的面积和两点之间的距离
- 计算所有对之间的曼哈顿距离
- 如何使用发送数据包所花费的时间计算两个节点之间的距离?
- 两个有符号数字之间的距离
- 计算车辆之间的距离并设置速度,使距离保持不变,例如 5 米
- 计算两个迭代器之间的距离时"Vector Iterators Incompatible"
- 查找彼此之间具有不同最小距离的随机数
- 相同字符之间的最小距离
- 如何排列二进制字符串以最小化它们之间的距离
- 堆和堆栈之间的距离
- 在opencv中,使用垫子类型计算马氏距离太慢了。如何提高效率?
- 如何在OpENCV中的图像中找到像素之间的欧几里得距离
- 欧氏除法中的位补算子
- 两个数组之间的欧氏距离,未声明的标识符
- 计算包含高维向量的两个矩阵之间的最小欧氏距离的最快方法
- 在 SURF 中使用欧氏距离
- 通过带有可变参数列表的函数计算欧氏距离
- 如何找到一帧中物体质心与相邻帧之间的欧氏距离
- 在CUDA中计算2个矩阵之间的欧几里德距离
- 使用 OpenCV 范数函数获得两点的欧氏距离