比如在缺陷检测中,一般情况下会对检测目标进行排序,以边更好的进行操作;
下面贴上相关的代码以及效果图:
void sort_box(vector<Rect> &boxes)
{
int size = boxes.size();
for(int t = 0; t < size - 1; t++)
{
for(int j = i; j < size; j++)
{
int x = boxes[j].x;
int y = boxes[j].y;
if(y < boxes[i].y)
{
Rect temp = boxes[i];
boxes[i] = boxes[j];
boxes[j] = temp;
}
}
}
}