Files
2024-12-13 23:33:37 +08:00

83 lines
2.2 KiB
C++

/*************************************************************************
*
* deepCam Shenzhen CONFIDENTIAL
* FILE: <tag>
*
* [2016] - [2019] DeepCam Shenzhen
* All Rights Reserved.
NOTICE:
* All information contained herein is, and remains the property of DeepCam Shenzhen.
* The intellectual and technical concepts contained herein are proprietary to DeepCam
* Shenzhen and may be covered by China and Foreign Patents,patents in process, and
* are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* DeepCam Shenzhen.
*
*
* Written: Jing.Yi 2019-11-01
* Updated:
**************************************************************************/
#include "anchor.h"
F32 IOU(RectLite <F32> rect0,RectLite <F32> rect1)
{
F32 w;
F32 h;
F32 iou;
F32 inter_x1;
F32 inter_y1;
F32 inter_x2;
F32 inter_y2;
F32 inter_area;
F32 area_1;
F32 area_2;
inter_x1 = std::max(rect0[AxisX0], rect1[AxisX0]);
inter_y1 = std::max(rect0[AxisY0], rect1[AxisY0]);
inter_x2 = std::min(rect0[AxisX1], rect1[AxisX1]);
inter_y2 = std::min(rect0[AxisY1], rect1[AxisY1]);
w = std::max((inter_x2 - inter_x1 + 1), 0.0F);
h = std::max((inter_y2 - inter_y1 + 1), 0.0F);
inter_area = w * h;
area_1 = rect0.area();
area_2 = rect1.area();
iou = inter_area / (area_1 + area_2 - inter_area);
return iou;
}
void nms_cpu(std::vector<Anchor>& boxes, float threshold, std::vector<Anchor>& filterOutBoxes)
{
S32 sInt0;
S32 sInt1;
S32 good_idx;
F32 iou;
std::vector<size_t> Idx;
std::vector<size_t> tmpIdx;
filterOutBoxes.clear();
if (boxes.size() == 0)return;
Idx.resize(boxes.size());
for (sInt0 = 0; sInt0 < Idx.size(); sInt0++)Idx[sInt0] = sInt0;
//descending sort
sort(boxes.begin(), boxes.end(), std::greater<Anchor>());
while (Idx.size() > 0){
good_idx = Idx[0];
filterOutBoxes.push_back(boxes[good_idx]);
tmpIdx = Idx;
Idx.clear();
for (sInt0 = 1; sInt0 < tmpIdx.size(); sInt0++){
sInt1 = tmpIdx[sInt0];
iou = IOU(boxes[good_idx].finalbox,boxes[sInt1].finalbox);
if (iou <= threshold)Idx.push_back(sInt1);
}
}
}