[*]Евклидово расстояние между любыми двумя кругами должно быть меньше 10 единиц в группе. .
[*]круг имеет разницу в размерах (радиусе) более 20 единиц, причем все круги находятся в пределах
указанного порогового значения расстояния в группе.
< /ол>
Код: Выделить всё
struct Circle {
cv::Point2f Center;
double Radius;
};
Код: Выделить всё
std::vector allCircles; // contains all circles to be filtered
std::vector tmpcircles;
std::vector circles;
while (!allCircles.empty()) {
tmpcircles.clear();
// Take the first circle from allCircles and use it as a reference
Circle initialCircle = allCircles.front();
tmpcircles.push_back(initialCircle); // Add it to tmpcircles
allCircles.erase(allCircles.begin()); // Remove the initial circle from allCircles
auto it = allCircles.begin();
while (it != allCircles.end()) {
double dist = std::pow(it->Center.x - initialCircle.Center.x, 2) +
std::pow(it->Center.y - initialCircle.Center.y, 2);
if (dist < 10) {
tmpcircles.push_back(*it);
it = allCircles.erase(it); // Remove the circle from allCircles and move to next
} else {
++it; // Move to next circle
}
}
if (tmpcircles.size() > 1) {
circles.insert(circles.end(), tmpcircles.begin(), tmpcircles.end());
}
}
Код: Выделить всё
Input:
[ Center: 1034,1136, Radius: 595.683]
[ Center: 1039,1137, Radius: 594.781]
[ Center: 1039,1137, Radius: 137.478]
[ Center: 1039,1137, Radius: 136.571]
[ Center: 1039,1137, Radius: 92.1536]
[ Center: 1039,1137, Radius: 91.2505]
[ Center: 1039,1137, Radius: 1280.59]
[ Center: 1034,1135, Radius: 1276.93]
expected output for the group if center distance < 10 and size difference > 20:
[ Center: 1034,1136, Radius: 595.683]
[ Center: 1039,1137, Radius: 137.478]
[ Center: 1039,1137, Radius: 92.1536]
[ Center: 1039,1137, Radius: 1280.59]
Любые предложения или код примеры были бы очень признательны.
Подробнее здесь: https://stackoverflow.com/questions/781 ... ector-in-c