删除不必要代码。

This commit is contained in:
xinyang
2019-08-04 17:18:32 +08:00
parent 3b4927d275
commit d0ab4342fd
3 changed files with 3 additions and 77 deletions

View File

@@ -84,7 +84,6 @@ public:
double lengthDistanceRatio() const;
double getBoxDistance() const;
BoxOrientation getOrientation() const;
// double
bool operator<(const ArmorBox &box) const;
};
@@ -108,10 +107,6 @@ private:
NORMAL, ANTI_TOP
} AntiTopState;
typedef enum{
INCREASE, DECREASE, NOCHANGE
} BoxRatioChangeType;
systime frame_time; // 当前帧对应时间;
const uint8_t &enemy_color; // 敌方颜色,引用外部变量,自动变化
State state; // 自瞄状态对象实例
@@ -136,11 +131,10 @@ private:
bool stateStandBy(); // stand by state主函数已弃用
void antiTop(); // 反小陀螺
BoxRatioChangeType getRatioChangeType(RoundQueue<double, 5> &vec);
bool sendBoxPosition(uint16_t shoot); // 和主控板通讯
public:
void run(cv::Mat &src); // 自瞄主函数
bool sendBoxPosition(uint16_t shoot); // 和主控板通讯
};
#endif /* _ARMOR_FINDER_H_ */

View File

@@ -6,13 +6,6 @@
#include <additions.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>
static double mean(RoundQueue<double, length> &vec) {
double sum = 0;
@@ -22,63 +15,6 @@ static double mean(RoundQueue<double, length> &vec) {
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() {
if (target_box.rect == cv::Rect2d()) return;
uint16_t shoot_delay = 0;

View File

@@ -8,10 +8,6 @@
#include <log.h>
bool ArmorFinder::stateSearchingTarget(cv::Mat &src) {
// if(anti_switch_cnt >= 3){
// last_box = ArmorBox();
// anti_switch_cnt = 0;
// }
if (findArmorBox(src, target_box)) {
if (last_box.rect != cv::Rect2d() &&
(getPointLength(last_box.getCenter() - target_box.getCenter()) > last_box.rect.height * 2.0) &&