How to find the Euclidean distance between the center of gravity of an object in one frame and an adjacent frame
2 answers
I'm going to assume that the camera hasn't moved between captures, so you don't have to worry about registration.
You should have two objects cv::Point
representing the two acquired centroids. Euclidean distance can be calculated as follows:
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;
}
This outputs 5 (i.e. 3-4-5 triangle) ...
Hope it helps!
+5
source to share