删除不必要代码。
This commit is contained in:
@@ -84,7 +84,6 @@ public:
|
|||||||
double lengthDistanceRatio() const;
|
double lengthDistanceRatio() const;
|
||||||
double getBoxDistance() const;
|
double getBoxDistance() const;
|
||||||
BoxOrientation getOrientation() const;
|
BoxOrientation getOrientation() const;
|
||||||
// double
|
|
||||||
|
|
||||||
bool operator<(const ArmorBox &box) const;
|
bool operator<(const ArmorBox &box) const;
|
||||||
};
|
};
|
||||||
@@ -108,10 +107,6 @@ private:
|
|||||||
NORMAL, ANTI_TOP
|
NORMAL, ANTI_TOP
|
||||||
} AntiTopState;
|
} AntiTopState;
|
||||||
|
|
||||||
typedef enum{
|
|
||||||
INCREASE, DECREASE, NOCHANGE
|
|
||||||
} BoxRatioChangeType;
|
|
||||||
|
|
||||||
systime frame_time; // 当前帧对应时间;
|
systime frame_time; // 当前帧对应时间;
|
||||||
const uint8_t &enemy_color; // 敌方颜色,引用外部变量,自动变化
|
const uint8_t &enemy_color; // 敌方颜色,引用外部变量,自动变化
|
||||||
State state; // 自瞄状态对象实例
|
State state; // 自瞄状态对象实例
|
||||||
@@ -119,7 +114,7 @@ private:
|
|||||||
int anti_switch_cnt; // 防止乱切目标计数器
|
int anti_switch_cnt; // 防止乱切目标计数器
|
||||||
cv::Ptr<cv::Tracker> tracker; // tracker对象实例
|
cv::Ptr<cv::Tracker> tracker; // tracker对象实例
|
||||||
Classifier classifier; // CNN分类器对象实例,用于数字识别
|
Classifier classifier; // CNN分类器对象实例,用于数字识别
|
||||||
int contour_area; // 装甲区域亮点个数,用于数字识别未启用时判断是否跟丢(已弃用)
|
int contour_area; // 装甲区域亮点个数,用于数字识别未启用时判断是否跟丢(已弃用)
|
||||||
int tracking_cnt; // 记录追踪帧数,用于定时退出追踪
|
int tracking_cnt; // 记录追踪帧数,用于定时退出追踪
|
||||||
Serial &serial; // 串口对象,引用外部变量,用于和能量机关共享同一个变量
|
Serial &serial; // 串口对象,引用外部变量,用于和能量机关共享同一个变量
|
||||||
const uint8_t &use_classifier; // 标记是否启用CNN分类器,引用外部变量,自动变化
|
const uint8_t &use_classifier; // 标记是否启用CNN分类器,引用外部变量,自动变化
|
||||||
@@ -135,12 +130,11 @@ private:
|
|||||||
bool stateTrackingTarget(cv::Mat &src); // tracking state主函数
|
bool stateTrackingTarget(cv::Mat &src); // tracking state主函数
|
||||||
bool stateStandBy(); // stand by state主函数(已弃用)
|
bool stateStandBy(); // stand by state主函数(已弃用)
|
||||||
|
|
||||||
void antiTop(); // 反小陀螺
|
void antiTop(); // 反小陀螺
|
||||||
BoxRatioChangeType getRatioChangeType(RoundQueue<double, 5> &vec);
|
|
||||||
|
|
||||||
|
bool sendBoxPosition(uint16_t shoot); // 和主控板通讯
|
||||||
public:
|
public:
|
||||||
void run(cv::Mat &src); // 自瞄主函数
|
void run(cv::Mat &src); // 自瞄主函数
|
||||||
bool sendBoxPosition(uint16_t shoot); // 和主控板通讯
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _ARMOR_FINDER_H_ */
|
#endif /* _ARMOR_FINDER_H_ */
|
||||||
|
|||||||
@@ -6,13 +6,6 @@
|
|||||||
#include <additions.h>
|
#include <additions.h>
|
||||||
#include <log.h>
|
#include <log.h>
|
||||||
|
|
||||||
static double boxDistance(const cv::Rect2d &a, const cv::Rect2d &b) {
|
|
||||||
cv::Point2d centerA(a.x + a.width / 2, a.y + a.height / 2);
|
|
||||||
cv::Point2d centerB(b.x + b.width / 2, b.y + b.height / 2);
|
|
||||||
auto dist = centerA - centerB;
|
|
||||||
return sqrt(dist.x * dist.x + dist.y * dist.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<int length>
|
template<int length>
|
||||||
static double mean(RoundQueue<double, length> &vec) {
|
static double mean(RoundQueue<double, length> &vec) {
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
@@ -22,63 +15,6 @@ static double mean(RoundQueue<double, length> &vec) {
|
|||||||
return sum / length;
|
return sum / length;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArmorFinder::BoxRatioChangeType ArmorFinder::getRatioChangeType(RoundQueue<double, 5> &vec) {
|
|
||||||
auto d = (vec[0] - vec[1] + vec[3] + vec[4]);
|
|
||||||
if (d > 0.15) {
|
|
||||||
return INCREASE;
|
|
||||||
} else if (d < -0.15) {
|
|
||||||
return DECREASE;
|
|
||||||
} else {
|
|
||||||
return NOCHANGE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
void ArmorFinder::antiTop() {
|
|
||||||
if (target_box.rect == cv::Rect2d()) return;
|
|
||||||
uint16_t shoot_delay = 0;
|
|
||||||
auto interval = getTimeIntervalms(frame_time, last_front_time);
|
|
||||||
box_ratioes.push(target_box.rect.width / target_box.rect.height);
|
|
||||||
auto change_type = getRatioChangeType(box_ratioes);
|
|
||||||
auto orientation = target_box.getOrientation();
|
|
||||||
if (interval > 700) {
|
|
||||||
anti_top_cnt = 0;
|
|
||||||
if (anti_top_state == ANTI_TOP) {
|
|
||||||
anti_top_state = NORMAL;
|
|
||||||
LOGM(STR_CTR(WORD_YELLOW, "switch to normal"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (change_type == INCREASE && last_ratio_type != change_type) {
|
|
||||||
last_front_time = frame_time;
|
|
||||||
if (150 < interval && interval < 700) {
|
|
||||||
if (anti_top_state == ANTI_TOP) {
|
|
||||||
top_periodms.push(interval);
|
|
||||||
LOGM(STR_CTR(WORD_LIGHT_GREEN, "top period: %.1lf ms"), interval);
|
|
||||||
systime curr_time;
|
|
||||||
getsystime(curr_time);
|
|
||||||
auto calculate_time = getTimeIntervalms(curr_time, frame_time);
|
|
||||||
shoot_delay = mean(top_periodms) - calculate_time;
|
|
||||||
} else if (anti_top_state == NORMAL) {
|
|
||||||
if (++anti_top_cnt > 4) {
|
|
||||||
anti_top_state = ANTI_TOP;
|
|
||||||
LOGM(STR_CTR(WORD_CYAN, "switch to anti-top"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (change_type != NOCHANGE) {
|
|
||||||
last_ratio_type = change_type;
|
|
||||||
}
|
|
||||||
if (anti_top_state == ANTI_TOP) {
|
|
||||||
if (orientation == ArmorBox::FRONT) {
|
|
||||||
sendBoxPosition(shoot_delay);
|
|
||||||
}
|
|
||||||
} else if (anti_top_state == NORMAL) {
|
|
||||||
sendBoxPosition(shoot_delay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void ArmorFinder::antiTop() {
|
void ArmorFinder::antiTop() {
|
||||||
if (target_box.rect == cv::Rect2d()) return;
|
if (target_box.rect == cv::Rect2d()) return;
|
||||||
uint16_t shoot_delay = 0;
|
uint16_t shoot_delay = 0;
|
||||||
|
|||||||
@@ -8,10 +8,6 @@
|
|||||||
#include <log.h>
|
#include <log.h>
|
||||||
|
|
||||||
bool ArmorFinder::stateSearchingTarget(cv::Mat &src) {
|
bool ArmorFinder::stateSearchingTarget(cv::Mat &src) {
|
||||||
// if(anti_switch_cnt >= 3){
|
|
||||||
// last_box = ArmorBox();
|
|
||||||
// anti_switch_cnt = 0;
|
|
||||||
// }
|
|
||||||
if (findArmorBox(src, target_box)) {
|
if (findArmorBox(src, target_box)) {
|
||||||
if (last_box.rect != cv::Rect2d() &&
|
if (last_box.rect != cv::Rect2d() &&
|
||||||
(getPointLength(last_box.getCenter() - target_box.getCenter()) > last_box.rect.height * 2.0) &&
|
(getPointLength(last_box.getCenter() - target_box.getCenter()) > last_box.rect.height * 2.0) &&
|
||||||
|
|||||||
Reference in New Issue
Block a user