C ++ is an effective way to compare vectors

I am currently working with a camera to detect a marker. I use opencv and Aruco Libary.

Only I am stuck with the problem right now. I need to determine if the distance between two markers is less than a certain value. I have a function to calculate the distance, I can compare everything. But I'm looking for the most effective way to track all the markers (about 5/6) and how close they are.

There is a list with markers, but I cannot find an effective way to compare all of them.

I have

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; 
}

Markercontains Point2f, so I can easily compare them.

+4
3

. , , 10 , 5 , 15 , 6 . , , . . , , - , (, A B, B A).

, , . , , , A B , A C A D . , , , , ( " n , n . . , n , ... , , splay trees for " .).

C ++ hypot :

#include <cmath>

double getDistance(cv::Point2f punt1, cv::Point2f punt2)
{
    return std::hypot(punt2.x - punt1.x, punt2.y - punt1.y);
}

, , , .


, , X Y . , , :

const double threshold = ...;
std::vector<cv::Point2f> points;
// populate points
...
for (auto i = points.begin(); i != points.end(); ++i) {
    for (auto j = i + 1; j != points.end(); ++j) {
        double dx = std::abs(i->x - j->x), dy = std::abs(i->y - j->y);
        if (dx > threshold || dy > threshold) {
            continue;
        }
        double distance = std::hypot(dx, dy);
        if (distance > threshold) {
            continue;
        }
        ...
    }
}
+5

- . , , .

+8

If you are dealing with large amounts of data inside your vector, you can think of multithreading with future.

Vector <Marker>can be placed in fragments Xthat are computed asynchronously together and stored internally std::future<>, so using the @Sesame clause will also increase your speed.

+4
source

Source: https://habr.com/ru/post/1543110/


All Articles