Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ - Efficient way to compare vectors

At the moment i'm working with a camera to detect a marker. I use opencv and the Aruco Libary.

Only I'm stuck with a problem right now. I need to detect if the distance between 2 marker is less than a specific value. I have a function to calculate the distance, I can compare everything. But I'm looking for the most efficient way to keep track of all the markers (around 5/6) and how close they are together.

There is a list with markers but I cant find a efficient way to compare all of them.

I have a

Vector <Marker> 

I also have a function called getDistance.

double getDistance(cv::Point2f punt1, cv::Point2f punt2)
{
    float xd = punt2.x-punt1.x;
    float yd = punt2.y-punt1.y;
    double Distance = sqrtf(xd*xd + yd*yd);
    return Distance; 
}

The Markers contain a Point2f, so i can compare them easily.

like image 681
Joris Mathijssen Avatar asked Dec 02 '22 19:12

Joris Mathijssen


1 Answers

One way to increase performance is to keep all the distances squared and avoid using the square root function. If you square the specific value you are checking against then this should work fine.

like image 73
Sesame Avatar answered Dec 18 '22 04:12

Sesame