diff --git a/energy/include/energy/energy.h b/energy/include/energy/energy.h index 03ff609..29cfcf7 100644 --- a/energy/include/energy/energy.h +++ b/energy/include/energy/energy.h @@ -48,6 +48,7 @@ private: bool isMark; int fans_cnt; int armors_cnt; + int centerRs_cnt; int count; int last_fans_cnt; int last_armors_cnt; @@ -82,6 +83,7 @@ private: std::vector fans; std::vector armors; + std::vector centerRs; // std::vector gimble_zero_points; cv::Point cycle_center; @@ -102,15 +104,17 @@ private: int findFan(const cv::Mat &src, vector &fans, int &last_fans_cnt); int findArmor(const cv::Mat &src, vector &armors, int &last_armors_cnt); - int findGimbleZeroPoint(const cv::Mat &src, vector &gimble_zero_point); + int findCenterR(const cv::Mat src); void showFanContours(std::string windows_name, const cv::Mat &src, const std::vector &fans); void showArmorContours(std::string windows_name, const cv::Mat &src, const std::vector &armors); void showBothContours(std::string windows_name, const cv::Mat &src, const std::vector &fans, const std::vector &armors); + void showCenterRContours(std::string windows_name, const cv::Mat src); bool isValidFanContour(const vector &fan_contour); bool isValidArmorContour(const vector &armor_contour); + bool isValidCenterRContour(const vector center_R_contour); void getFanPosition(std::vector &fanPosition, const std::vector &fans, cv::Point cycle_center, double radius); void getArmorPosition(std::vector &armorPosition, const std::vector &armors, cv::Point cycle_center, double radius); diff --git a/energy/include/energy/param_struct_define.h b/energy/include/energy/param_struct_define.h index dc82c6c..ff49a0a 100644 --- a/energy/include/energy/param_struct_define.h +++ b/energy/include/energy/param_struct_define.h @@ -48,6 +48,15 @@ struct EnergyPartParam { float ARMOR_CONTOUR_HW_RATIO_MAX; float ARMOR_CONTOUR_HW_RATIO_MIN; + long CENTER_R_CONTOUR_AREA_MAX; + long CENTER_R_CONTOUR_AREA_MIN; + long CENTER_R_CONTOUR_LENGTH_MIN; + long CENTER_R_CONTOUR_WIDTH_MIN; + long CENTER_R_CONTOUR_LENGTH_MAX; + long CENTER_R_CONTOUR_WIDTH_MAX; + float CENTER_R_CONTOUR_HW_RATIO_MAX; + float CENTER_R_CONTOUR_HW_RATIO_MIN; + float TWIN_ANGEL_MAX; }; diff --git a/energy/src/energy/find/energy_finder.cpp b/energy/src/energy/find/energy_finder.cpp index 4fcf680..ce8bdca 100644 --- a/energy/src/energy/find/energy_finder.cpp +++ b/energy/src/energy/find/energy_finder.cpp @@ -121,38 +121,42 @@ int Energy::findArmor(const cv::Mat &src, vector &armors, int &last_ return static_cast(armors.size()); } -int Energy::findGimbleZeroPoint(const cv::Mat &src, vector &gimble_zero_points) { +int Energy::findCenterR(const cv::Mat src) { if (src.empty())return 0; static Mat src_bin; src_bin = src.clone(); -// threshold(src, src_bin, energy_part_param_.FAN_GRAY_THRESH, 255, THRESH_BINARY); +// threshold(src, src_bin, energy_part_param_.ARMOR_GRAY_THRESH, 255, THRESH_BINARY); if(src.type() == CV_8UC3){ cvtColor(src_bin, src_bin, CV_BGR2GRAY); } - std::vector > zero_point_contours; + std::vector > center_R_contours; - findContours(src_bin, zero_point_contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); + StructingElementErodeDilate(src_bin); +// imshow("R struct",src_bin); - for (auto &zero_point_contour : zero_point_contours) { + findContours(src_bin, center_R_contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); - double cur_contour_area = contourArea(zero_point_contour); - RotatedRect cur_rect = minAreaRect(zero_point_contour); + for (auto ¢er_R_contour : center_R_contours) { + if (!isValidCenterRContour(center_R_contour)) + { + continue; + } + + RotatedRect cur_rect = minAreaRect(center_R_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; - if(length<10&&width<10&&length>1&&width>1){ - cout<<"zero point center: "<10 && width>5){ +// centerRs.emplace_back(center_R_contour); +// cout<<"center R area: "<(fans.size()); + return static_cast(centerRs.size()); } bool Energy::isValidFanContour(const vector &fan_contour) { @@ -226,3 +230,39 @@ bool Energy::isValidArmorContour(const vector &armor_contour) { return true; } +bool Energy::isValidCenterRContour(const vector center_R_contour) { + double cur_contour_area = contourArea(center_R_contour); +// if (cur_contour_area > energy_part_param_.ARMOR_CONTOUR_AREA_MAX || +// cur_contour_area < energy_part_param_.ARMOR_CONTOUR_AREA_MIN) +// { +// //cout< 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_.CENTER_R_CONTOUR_LENGTH_MIN || width < energy_part_param_.CENTER_R_CONTOUR_WIDTH_MIN) + { + //cout<<"length width min fail."< energy_part_param_.CENTER_R_CONTOUR_LENGTH_MAX||width>energy_part_param_.CENTER_R_CONTOUR_WIDTH_MAX) + { + //cout<<"length width max fail."< energy_part_param_.CENTER_R_CONTOUR_HW_RATIO_MAX || + length_width_ratio < energy_part_param_.CENTER_R_CONTOUR_HW_RATIO_MIN) + { + //cout<<"length width ratio fail."<200)all_armor_centers.clear(); -// if(first_armor_centers.size()>200)first_armor_centers.clear(); -// cout<<"first_armor_centers.size(): "<0||fans_cnt>0) showBothContours("Both",src, fans, armors); + centerRs_cnt = findCenterR(src); + if(centerRs_cnt>0)showCenterRContours("R",src); - if(armors_cnt>=4 && fans_cnt>=3) { + if(armors_cnt>=4 && fans_cnt>=3) { FILE *fp = fopen(PROJECT_DIR"/Mark/mark.txt", "w"); if (fp) { fprintf(fp, "yaw: %f, pitch: %f\n", origin_yaw, origin_pitch); @@ -112,6 +110,8 @@ int Energy::run(cv::Mat &src){ // cout<<"position mode: "< &fans, const std::vector &armors) { if (src.empty())return; diff --git a/main.cpp b/main.cpp index 34fb53c..63392b7 100644 --- a/main.cpp +++ b/main.cpp @@ -29,7 +29,7 @@ using namespace std; mcu_data mcuData = { 0, 0, - ARMOR_STATE, + ENERGY_STATE, 0, 1, ENEMY_RED, @@ -65,8 +65,8 @@ int main(int argc, char *argv[]) { // video_armor = new VideoWrapper(armor_video); // lastVideo(energy_video, PROJECT_DIR"/energy_video/"); // video_energy = new VideoWrapper(energy_video); - video_armor = new VideoWrapper("/home/sjturm/Desktop/valid_video/armor/65.avi"); - video_energy = new VideoWrapper("/home/sjturm/Desktop/valid_video/energy/121.avi"); + video_armor = new VideoWrapper("/home/sun/项目/energy_video/energy_test.avi"); + video_energy = new VideoWrapper("/home/sun/项目/energy_video/energy_test.avi"); } if (video_armor->init()) { LOGM("video_armor source initialization successfully."); @@ -169,7 +169,7 @@ int main(int argc, char *argv[]) { } } // cout<