Merge remote-tracking branch 'origin/anti-top-test' into anti-top-test

# Conflicts:
#	armor/src/armor_finder/anti_top/anti_top.cpp
This commit is contained in:
xinyang
2019-08-04 12:34:50 +08:00
7 changed files with 50 additions and 34 deletions

View File

@@ -96,19 +96,21 @@ void ArmorFinder::antiTop() {
getsystime(curr_time);
auto calculate_time = getTimeIntervalms(curr_time, frame_time);
shoot_delay = mean(top_periodms) - calculate_time;
sendBoxPosition(shoot_delay);
} else {
if (++anti_top_cnt > 4) {
anti_top_state == ANTI_TOP;
anti_top_state = ANTI_TOP;
LOGM(STR_CTR(WORD_CYAN, "switch to anti-top"));
}
}
}
last_front_time = frame_time;
}
if (anti_top_state == NORMAL) {
sendBoxPosition(0);
} else if (interval < top_periodms[-1] * 0.1){
sendBoxPosition(shoot_delay);
}
last_box = target_box;
}

View File

@@ -155,8 +155,10 @@ bool ArmorFinder::findArmorBox(const cv::Mat &src, ArmorBox &box) {
return a < b;
}
});
if(armor_boxes[0].id != 0){
box = armor_boxes[0];
for(auto &one_box : armor_boxes){
if(one_box.id != 0){
box = one_box;
}
}
if (save_labelled_boxes) {
for (const auto &one_box : armor_boxes) {

View File

@@ -8,17 +8,18 @@
#include <log.h>
bool ArmorFinder::stateSearchingTarget(cv::Mat &src) {
if(anti_switch_cnt >= 3){
last_box = ArmorBox();
}
// 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 * 3.0) &&
(getPointLength(last_box.getCenter() - target_box.getCenter()) > last_box.rect.height * 2.0) &&
anti_switch_cnt++ < 3) {
target_box = ArmorBox();
LOGM("anti-switch!");
return false;
} else {
last_box = target_box;
anti_switch_cnt = 0;
return true;
}
@@ -28,3 +29,14 @@ bool ArmorFinder::stateSearchingTarget(cv::Mat &src) {
return false;
}
}
/*
bool ArmorFinder::stateSearchingTarget(cv::Mat &src) {
if (findArmorBox(src, target_box)) {
return true;
} else {
target_box = ArmorBox();
return false;
}
}
*/

View File

@@ -44,7 +44,7 @@ static bool sendTarget(Serial &serial, double x, double y, double z, uint16_t sh
bool ArmorFinder::sendBoxPosition(uint16_t shoot_delay) {
if (target_box.rect == cv::Rect2d()) return false;
if (shoot_delay) {
LOGM(STR_CTR(WORD_BLUE, "shoot after %dms"), shoot_delay);
LOGM(STR_CTR(WORD_BLUE, "next box %dms"), shoot_delay);
}
auto rect = target_box.rect;
double dx = rect.x + rect.width / 2 - IMAGE_CENTER_X;

View File

@@ -42,25 +42,27 @@ bool ArmorFinder::stateTrackingTarget(cv::Mat &src) {
tracker = TrackerToUse::create();
tracker->init(src, target_box.rect);
}else{
roi = src(pos).clone();
if(classifier){
cv::resize(roi, roi, cv::Size(48, 36));
if(classifier(roi) == 0){
target_box = ArmorBox();
return false;
}
}else{
cv::Mat roi_gray;
cv::cvtColor(roi, roi_gray, CV_RGB2GRAY);
cv::threshold(roi_gray, roi_gray, 180, 255, cv::THRESH_BINARY);
contour_area = cv::countNonZero(roi_gray);
if(abs(cv::countNonZero(roi_gray) - contour_area) > contour_area * 0.3){
target_box = ArmorBox();
return false;
}
}
target_box.rect = pos;
target_box.light_blobs.clear();
// roi = src(pos).clone();
// if(classifier){
// cv::resize(roi, roi, cv::Size(48, 36));
// if(classifier(roi) == 0){
// target_box = ArmorBox();
// return false;
// }
// }else{
// cv::Mat roi_gray;
// cv::cvtColor(roi, roi_gray, CV_RGB2GRAY);
// cv::threshold(roi_gray, roi_gray, 180, 255, cv::THRESH_BINARY);
// contour_area = cv::countNonZero(roi_gray);
// if(abs(cv::countNonZero(roi_gray) - contour_area) > contour_area * 0.3){
// target_box = ArmorBox();
// return false;
// }
// }
// target_box.rect = pos;
// target_box.light_blobs.clear();
target_box = ArmorBox();
return false;
}
return true;
}