diff --git a/energy/include/energy/param_struct_define.h b/energy/include/energy/param_struct_define.h index f222368..dc82c6c 100644 --- a/energy/include/energy/param_struct_define.h +++ b/energy/include/energy/param_struct_define.h @@ -33,7 +33,9 @@ struct EnergyPartParam { long FAN_CONTOUR_AREA_MAX; long FAN_CONTOUR_AREA_MIN; long FAN_CONTOUR_LENGTH_MIN; + long FAN_CONTOUR_LENGTH_MAX; long FAN_CONTOUR_WIDTH_MIN; + long FAN_CONTOUR_WIDTH_MAX; float FAN_CONTOUR_HW_RATIO_MAX; float FAN_CONTOUR_HW_RATIO_MIN; diff --git a/energy/src/energy/calibrate/structing.cpp b/energy/src/energy/calibrate/structing.cpp index 4916b45..da8a130 100644 --- a/energy/src/energy/calibrate/structing.cpp +++ b/energy/src/energy/calibrate/structing.cpp @@ -11,7 +11,7 @@ using std::vector; void Energy::StructingElementClose(cv::Mat &src){ if (src.empty())return; //threshold(src, src, energy_part_param_.CAMERA_GRAY_THRESH, 255, THRESH_BINARY); - Mat element = getStructuringElement(MORPH_RECT, Size(4, 4)); + Mat element = getStructuringElement(MORPH_RECT, Size(10, 10)); morphologyEx(src, src, MORPH_CLOSE, element); } diff --git a/energy/src/energy/find/energy_finder.cpp b/energy/src/energy/find/energy_finder.cpp index a547c84..0b928fb 100644 --- a/energy/src/energy/find/energy_finder.cpp +++ b/energy/src/energy/find/energy_finder.cpp @@ -19,7 +19,7 @@ int Energy::findFan(const cv::Mat &src, vector &fans, int &last_fans std::vector > fan_contours; StructingElementClose(src_bin); -// imshow("fan struct",src_bin); + imshow("fan struct",src_bin); findContours(src_bin, fan_contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); @@ -28,25 +28,26 @@ int Energy::findFan(const cv::Mat &src, vector &fans, int &last_fans continue; } -// double cur_contour_area = contourArea(fan_contour); -// RotatedRect cur_rect = minAreaRect(fan_contour); -// Size2f cur_size = cur_rect.size; + double cur_contour_area = contourArea(fan_contour); + RotatedRect cur_rect = minAreaRect(fan_contour); + Size2f cur_size = cur_rect.size; // // cout<<"cur_contour_area: "< cur_size.width ? cur_size.height : cur_size.width; -// float width = cur_size.height < cur_size.width ? cur_size.height : cur_size.width; + float length = cur_size.height > cur_size.width ? cur_size.height : cur_size.width; + float width = cur_size.height < cur_size.width ? cur_size.height : cur_size.width; -// if(length>5&&width>5){ +// if(length>20&&width>20){ // cout<(fans.size()); return -1; @@ -100,13 +101,14 @@ int Energy::findArmor(const cv::Mat &src, vector &armors, int &last_ float length = cur_size.height > cur_size.width ? cur_size.height : cur_size.width; float width = cur_size.height < cur_size.width ? cur_size.height : cur_size.width; -// if(length>10&&width>10){ +// if(length>10&&width>5){ +// armors.emplace_back(armor_contour); +// cout<<"armor area: "<(armors.size()); @@ -164,7 +166,8 @@ bool Energy::isValidFanContour(const vector &fan_contour) { Size2f cur_size = cur_rect.size; float length = cur_size.height > cur_size.width ? cur_size.height : cur_size.width; float width = cur_size.height < cur_size.width ? cur_size.height : cur_size.width; - if (length < energy_part_param_.FAN_CONTOUR_LENGTH_MIN || width < energy_part_param_.FAN_CONTOUR_WIDTH_MIN) + if (length < energy_part_param_.FAN_CONTOUR_LENGTH_MIN || width < energy_part_param_.FAN_CONTOUR_WIDTH_MIN || + length > energy_part_param_.FAN_CONTOUR_LENGTH_MAX || width > energy_part_param_.FAN_CONTOUR_WIDTH_MAX) { //cout<<"length width min fail."<receive()) != '\n'){ buffer[cnt++] = data; if(cnt >= 100){ - LOGE("data receive over flow!"); +// LOGE("data receive over flow!"); } } if(cnt == 10){ if(buffer[8] == 'e'){ state = ENERGY_STATE; - LOGM("Energy state"); +// LOGM("Energy state"); }else if(buffer[8] == 'a'){ state = ARMOR_STATE; - LOGM("Armor state"); +// LOGM("Armor state"); } memcpy(&curr_yaw, buffer, 4); memcpy(&curr_pitch, buffer+4, 4); - LOGM("Get yaw:%f pitch:%f", curr_yaw, curr_pitch); +// LOGM("Get yaw:%f pitch:%f", curr_yaw, curr_pitch); if(buffer[9] == 1){ - mark_yaw = curr_yaw; - mark_pitch = curr_pitch; - LOGM("Marked"); + if(mark == 0){ + mark = 1; + mark_yaw = curr_yaw; + mark_pitch = curr_pitch; + } + +// LOGM("Marked"); } } cnt = 0;