Merge branch 'master' of /home/sjturm/Desktop/RM_auto-aim with conflicts.

This commit is contained in:
xinyang
2019-08-04 08:17:38 +08:00
parent a68a051ce7
commit cbadab7f83
5 changed files with 558 additions and 512 deletions

View File

@@ -13,7 +13,7 @@ static double boxDistance(const cv::Rect2d &a, const cv::Rect2d &b) {
return sqrt(dist.x * dist.x + dist.y * dist.y); 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;
for (int i = 0; i < vec.size(); i++) { for (int i = 0; i < vec.size(); i++) {
@@ -33,13 +33,14 @@ ArmorFinder::BoxRatioChangeType ArmorFinder::getRatioChangeType(RoundQueue<doubl
} }
} }
/*
void ArmorFinder::antiTop() { void ArmorFinder::antiTop() {
if (armor_box.rect == cv::Rect2d()) return; if (target_box.rect == cv::Rect2d()) return;
uint16_t shoot_delay = 0; uint16_t shoot_delay = 0;
auto interval = getTimeIntervalms(frame_time, last_front_time); auto interval = getTimeIntervalms(frame_time, last_front_time);
box_ratioes.push(armor_box.rect.width / armor_box.rect.height); box_ratioes.push(target_box.rect.width / target_box.rect.height);
auto change_type = getRatioChangeType(box_ratioes); auto change_type = getRatioChangeType(box_ratioes);
auto orientation = armor_box.getOrientation(); auto orientation = target_box.getOrientation();
if (interval > 700) { if (interval > 700) {
anti_top_cnt = 0; anti_top_cnt = 0;
if (anti_top_state == ANTI_TOP) { if (anti_top_state == ANTI_TOP) {
@@ -76,4 +77,42 @@ void ArmorFinder::antiTop() {
sendBoxPosition(shoot_delay); sendBoxPosition(shoot_delay);
} }
} }
*/
void ArmorFinder::antiTop() {
if (target_box.rect == cv::Rect2d()) return;
uint16_t shoot_delay = 0;
auto interval = getTimeIntervalms(frame_time, last_front_time);
if (anti_top_state == ANTI_TOP && interval > 500) {
anti_top_state = NORMAL;
LOGM(STR_CTR(WORD_YELLOW, "switch to normal"));
}
if (last_box.rect != cv::Rect2d() &&
getPointLength(last_box.getCenter() - target_box.getCenter()) > last_box.rect.height * 1.0) {
LOGM("switch! %lf", getPointLength(last_box.getCenter() - target_box.getCenter()) / last_box.rect.height);
if (150 < interval && interval < 500) {
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;
sendBoxPosition(shoot_delay);
} else {
if (++anti_top_cnt > 4) {
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.10) {
sendBoxPosition(0);
}
last_box = target_box;
}

View File

@@ -324,7 +324,7 @@ int Classifier::operator()(const cv::Mat &image) {
// cout << result << "==============" <<endl; // cout << result << "==============" <<endl;
MatrixXd::Index minRow, minCol; MatrixXd::Index minRow, minCol;
result.maxCoeff(&minRow, &minCol); result.maxCoeff(&minRow, &minCol);
if(result(minRow, minCol) > 0.90){ if(result(minRow, minCol) > 0.50){
return minRow; return minRow;
}else{ }else{
return 0; return 0;

View File

@@ -53,9 +53,9 @@ void Energy::ArmorStruct(cv::Mat &src) {
// imshow("dilate_1", src); // imshow("dilate_1", src);
erode(src,src, element_erode_1); erode(src,src, element_erode_1);
// imshow("erode_1", src); // imshow("erode_1", src);
erode(src,src, element_erode_2); // erode(src,src, element_erode_2);
// imshow("erode_2", src); // imshow("erode_2", src);
erode(src,src, element_erode_3); // erode(src,src, element_erode_3);
// imshow("erode_3", src); // imshow("erode_3", src);
// dilate(src, src, element_dilate_2); // dilate(src, src, element_dilate_2);

View File

@@ -54,7 +54,12 @@ void Energy::findTargetByIntersection() {
// 此函数在流动条区域内寻找装甲板 // 此函数在流动条区域内寻找装甲板
// --------------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------------
bool Energy::findTargetInFlowStripFan() { bool Energy::findTargetInFlowStripFan() {
// Mat draw(480,640,CV_8UC3,Scalar(0,0,0));
for (auto &candidate_flow_strip_fan: flow_strip_fans) { for (auto &candidate_flow_strip_fan: flow_strip_fans) {
// Point2f vertices[4]; //定义矩形的4个顶点
// candidate_flow_strip_fan.points(vertices); //计算矩形的4个顶点
// for (int i = 0; i < 4; i++)
// line(draw, vertices[i], vertices[(i + 1) % 4], Scalar(0, 0, 255), 2);
int i = 0; int i = 0;
for (i = 0; i < armors.size(); ++i) { for (i = 0; i < armors.size(); ++i) {
std::vector<cv::Point2f> intersection; std::vector<cv::Point2f> intersection;
@@ -67,9 +72,11 @@ bool Energy::findTargetInFlowStripFan() {
} }
} }
} }
// imshow("draw",draw);
// waitKey();
// cout << "target armor cnt: " << target_armors.size() << endl; // cout << "target armor cnt: " << target_armors.size() << endl;
if (target_armors.empty()) { if (target_armors.empty()) {
if (show_info)cout << "find target armor false" << endl; if (show_info)cout << "t6find target armor false" << endl;
return false; return false;
} else { } else {
return true; return true;