190 lines
3.9 KiB
C++
190 lines
3.9 KiB
C++
#ifndef __ANCHOR_H__
|
|
#define __ANCHOR_H__
|
|
/*************************************************************************
|
|
*
|
|
* 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-08-01
|
|
* Updated:
|
|
**************************************************************************/
|
|
|
|
#include <vector>
|
|
#include <math.h>
|
|
#include <algorithm>
|
|
#include <functional>
|
|
#include "common_def.h"
|
|
|
|
|
|
typedef enum {
|
|
AxisX0 = 0,
|
|
AxisX = 0,
|
|
AxisY0 = 1,
|
|
AxisY = 1,
|
|
AxisX1 = 2,
|
|
AxisY1 = 3
|
|
}CoordinatesID;
|
|
|
|
|
|
typedef struct __SCALE_INF_{
|
|
F32 scaleX;
|
|
F32 scaleY;
|
|
S32 Xpadding;
|
|
S32 Ypadding;
|
|
S32 OriginalWidth;
|
|
S32 OriginalHeight;
|
|
}ScaleInf_t;
|
|
|
|
|
|
template <class Dtype> class PointLite {
|
|
public:
|
|
Dtype m_coordinates[2];
|
|
public:
|
|
PointLite() {
|
|
m_coordinates[AxisX0] = 0;
|
|
m_coordinates[AxisY0] = 0;
|
|
}
|
|
|
|
~PointLite() {
|
|
}
|
|
|
|
PointLite(Dtype x, Dtype y) {
|
|
m_coordinates[AxisX0] = x;
|
|
m_coordinates[AxisY0] = y;
|
|
}
|
|
|
|
Dtype operator[](S32 i) const {
|
|
__ASSERT__((0 <= i) && (i <= 1),LOG_TAG_COMMON,"PointLite::The index : (%d) for coordinates is error!\n",i);
|
|
return m_coordinates[i];
|
|
}
|
|
|
|
Dtype & operator[](S32 i) {
|
|
__ASSERT__((0 <= i) && (i <= 1),LOG_TAG_COMMON,"PointLite::The index : (%d) for coordinates is error!\n",i);
|
|
return m_coordinates[i];
|
|
}
|
|
};
|
|
|
|
|
|
template <class Dtype> class RectLite{
|
|
public:
|
|
Dtype m_coordinates[4];
|
|
public:
|
|
RectLite() {
|
|
m_coordinates[AxisX0] = 0;
|
|
m_coordinates[AxisY0] = 0;
|
|
m_coordinates[AxisX1] = 0;
|
|
m_coordinates[AxisY1] = 0;
|
|
}
|
|
|
|
~RectLite() {
|
|
}
|
|
|
|
RectLite(Dtype x0,Dtype y0,Dtype x1,Dtype y1){
|
|
m_coordinates[AxisX0] = x0;
|
|
m_coordinates[AxisY0] = y0;
|
|
m_coordinates[AxisX1] = x1;
|
|
m_coordinates[AxisY1] = y1;
|
|
}
|
|
|
|
Dtype operator[](S32 i) const {
|
|
__ASSERT__((0 <= i) && (i <= 3),LOG_TAG_COMMON,"RectLite::The index : (%d) for coordinates is error!\n",i);
|
|
return m_coordinates[i];
|
|
}
|
|
|
|
Dtype & operator[](S32 i) {
|
|
__ASSERT__((0 <= i) && (i <= 3),LOG_TAG_COMMON,"RectLite::The index : (%d) for coordinates is error!\n",i);
|
|
return m_coordinates[i];
|
|
}
|
|
|
|
Dtype area() {
|
|
return width()*height();
|
|
}
|
|
|
|
Dtype width() {
|
|
return fabs(m_coordinates[AxisX1] - m_coordinates[AxisX0]);
|
|
}
|
|
|
|
Dtype height() {
|
|
return fabs(m_coordinates[AxisY1] - m_coordinates[AxisY0]);
|
|
}
|
|
};
|
|
|
|
|
|
|
|
class Anchor {
|
|
public:
|
|
RectLite <F32> finalbox;
|
|
PointLite <F32> center;
|
|
F32 score;
|
|
F32 yaw;
|
|
F32 pitch;
|
|
F32 roll;
|
|
F32 quality;
|
|
S32 classId;
|
|
std::vector<PointLite <F32>> pts; // pred pts
|
|
|
|
public:
|
|
Anchor() {
|
|
pts.resize(5);
|
|
pts[0] = PointLite <F32>(0,0);
|
|
pts[1] = PointLite <F32>(0,0);
|
|
pts[2] = PointLite <F32>(0,0);
|
|
pts[3] = PointLite <F32>(0,0);
|
|
pts[4] = PointLite <F32>(0,0);
|
|
yaw = -720;
|
|
pitch = -720;
|
|
roll = -720;
|
|
quality = -1;
|
|
}
|
|
|
|
~Anchor() {
|
|
|
|
}
|
|
|
|
bool operator<(const Anchor &t) const {
|
|
return score < t.score;
|
|
}
|
|
|
|
bool operator>(const Anchor &t) const {
|
|
return score > t.score;
|
|
}
|
|
|
|
F32 operator[](S32 i) const{
|
|
return finalbox[i];
|
|
}
|
|
|
|
F32 & operator[](S32 i) {
|
|
return finalbox[i];
|
|
}
|
|
|
|
F32 width() {
|
|
return finalbox.width();
|
|
}
|
|
|
|
F32 height() {
|
|
return finalbox.height();
|
|
}
|
|
|
|
F32 area() {
|
|
return finalbox.area();
|
|
}
|
|
};
|
|
|
|
extern F32 IOU(RectLite <F32> rect0,RectLite <F32> rect1);
|
|
extern void nms_cpu(std::vector<Anchor>& boxes, float threshold, std::vector<Anchor>& filterOutBoxes);
|
|
|
|
#endif
|