Let's suppose I have the following three vectors:
std::vector<int> classIds;
std::vector<float> confidences;
std::vector<Rect> boxes;
The data is pushed into these vectors as follows:
for (iterate over candidates)
{
// compute classIdPoint
if (confidence > confidence_Threshold)
{
// compute left, top, width, and height
classIds.push_back(classIdPoint.x);
confidences.push_back((float)confidence);
boxes.push_back(Rect(left, top, width, height));
}
}
The order at which the data is pushed in ties these vectors together. For instance, the confidence value in confidences.at(0)
corresponds to the class ID at classIds.at(0)
.
Now I want to sort the confidences
vector in descending order, which is easy to do
sort(confidences.begin(), confidences.end(), greater<float>());
But now I need the same sorting to be applied to the other two vectors (classIds
and boxes
) in order to maintain the relationship between the vectors. What would be a good way of doing this?