#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
typedef struct Bbox
{
float x;
float y;
float w;
float h;
float score;
}Bbox;
typedef struct BBox
{
float x;
float y;
float w;
float h;
float score;
int indx;
}BBox;
bool sort_score(BBox box1, BBox box2)
{
return (box1.score > box2.score);
}
float iou(BBox box1, BBox box2)
{
float x1 = std::max(box1.x, box2.x);
float y1 = std::max(box1.y, box2.y);
float x2 = std::min((box1.x + box1.w),
(box2.x + box2.w));
float y2 = std::min((box1.y + box1.h), (box2.y + box2.h));
float over_area = (x2 - x1) * (y2 - y1);
float iou = over_area / (box1.w * box1.h + box2.w * box2.h - over_area);
return iou;
}
int *keep;
vector<Bbox> nms(std::vector<Bbox>& vec_boxs, float threshold)
{
vector<BBox>results;
vector<Bbox>dets;
vector<Bbox>::iterator iter;
vector<BBox>vec_Boxs;
vec_Boxs.resize(vec_boxs.size());
int indx;
for(indx = 0;indx<vec_boxs.size();indx++){
vec_Boxs[indx].x = vec_boxs[indx].x;
vec_Boxs[indx].y = vec_boxs[indx].y;
vec_Boxs[indx].w = vec_boxs[indx].w;
vec_Boxs[indx].h = vec_boxs[indx].h;
vec_Boxs[indx].score = vec_boxs[indx].score;
vec_Boxs[indx].indx = indx;
}
while (vec_Boxs.size() > 0)
{
std::sort(vec_Boxs.begin(), vec_Boxs.end(), sort_score);
results.push_back(vec_Boxs[0]);
for (int i = 1; i <vec_Boxs.size() ; i++)
{
float iou_value = iou(vec_Boxs[0], vec_Boxs[i]);
if (iou_value > threshold)
{
vec_Boxs.erase(vec_Boxs.begin()+i);
i--;
}
}
vec_Boxs.erase(vec_Boxs.begin());
}
dets.resize(results.size());
keep = new int[results.size()];
for (int i = 0;i<results.size();i++){
dets[i].x =results[i].x;
dets[i].y =results[i].y;
dets[i].w =results[i].w;
dets[i].h =results[i].h;
dets[i].score =results[i].score;
keep[i] = results[i].indx;
// cout<<dets[i].score<<"for"<<' '<<keep[i] <<endl;
}
return dets;
}
int main(){
return 0;
}