diff --git a/energy/include/energy/energy.h b/energy/include/energy/energy.h index 3a6da62..45d26b8 100644 --- a/energy/include/energy/energy.h +++ b/energy/include/energy/energy.h @@ -132,6 +132,7 @@ private: bool findFlowStrip(const cv::Mat src);//寻找图中的流动条 bool findCenterROI(const cv::Mat src);//框取中心R候选区 bool findFlowStripFan(const cv::Mat src);//寻找图中的流动条所在扇叶 + bool findFlowStripWeak(const cv::Mat src);//弱识别寻找图中的流动条 bool isValidFanContour(cv::Mat &src, const vector &fan_contour);//扇叶矩形尺寸要求 bool isValidArmorContour(const vector &armor_contour);//装甲板矩形尺寸要求 @@ -143,6 +144,7 @@ private: void showArmors(std::string windows_name, const cv::Mat src);//显示装甲板 void showBoth(std::string windows_name, const cv::Mat src);//显示扇叶和装甲板 void showCenterR(std::string windows_name, const cv::Mat src);//显示风车中心候选区R + void showFlowStrip(std::string windows_name, const cv::Mat src);//显示流动条 void showFlowStripFan(std::string windows_name, const cv::Mat src);//显示流动条所在扇叶 void showGuessTarget(std::string windows_name, const cv::Mat src);//显示猜测点位 diff --git a/energy/include/energy/param_struct_define.h b/energy/include/energy/param_struct_define.h index 8b2faf9..9e0fa7f 100644 --- a/energy/include/energy/param_struct_define.h +++ b/energy/include/energy/param_struct_define.h @@ -83,6 +83,9 @@ struct EnergyPartParam { long TARGET_CHANGE_DISTANCE_MAX;//目标未更改时,目标装甲板中心与原目标装甲板中心的距离变化最大值 long TWIN_POINT_MAX;//两个点相同时距离最大值 + + long STRIP_ARMOR_DISTANCE_MIN;//流动条中心和目标装甲板中心距离最小值 + long STRIP_ARMOR_DISTANCE_MAX;//流动条中心和目标装甲板中心距离最大值 }; diff --git a/energy/src/energy/clear/energy_init.cpp b/energy/src/energy/clear/energy_init.cpp index f485825..16e0b22 100644 --- a/energy/src/energy/clear/energy_init.cpp +++ b/energy/src/energy/clear/energy_init.cpp @@ -71,7 +71,6 @@ void Energy::initEnergy() { all_target_armor_centers.clear(); while(!recent_target_armor_centers.empty())recent_target_armor_centers.pop(); - } @@ -81,7 +80,7 @@ void Energy::initEnergy() { void Energy::initEnergyPartParam() { // gimbal_energy_part_param_.GRAY_THRESH = 120;//home // gimbal_energy_part_param_.GRAY_THRESH = 200;//official - gimbal_energy_part_param_.GRAY_THRESH = 180; + gimbal_energy_part_param_.GRAY_THRESH = 180;//game gimbal_energy_part_param_.SPLIT_GRAY_THRESH = 180; gimbal_energy_part_param_.FAN_GRAY_THRESH = 75; gimbal_energy_part_param_.ARMOR_GRAY_THRESH = 80; @@ -100,8 +99,8 @@ void Energy::initEnergyPartParam() { // gimbal_energy_part_param_.FAN_NON_ZERO_RATE_MAX = 0.3; // gimbal_energy_part_param_.FAN_NON_ZERO_RATE_MIN = 0.16; - gimbal_energy_part_param_.ARMOR_CONTOUR_AREA_MAX = 100000; - gimbal_energy_part_param_.ARMOR_CONTOUR_AREA_MIN = 0; + gimbal_energy_part_param_.ARMOR_CONTOUR_AREA_MAX = 500; + gimbal_energy_part_param_.ARMOR_CONTOUR_AREA_MIN = 180; gimbal_energy_part_param_.ARMOR_CONTOUR_LENGTH_MIN = 16; gimbal_energy_part_param_.ARMOR_CONTOUR_LENGTH_MAX = 32; gimbal_energy_part_param_.ARMOR_CONTOUR_WIDTH_MIN = 5; @@ -109,42 +108,41 @@ void Energy::initEnergyPartParam() { gimbal_energy_part_param_.ARMOR_CONTOUR_HW_RATIO_MAX = 3; gimbal_energy_part_param_.ARMOR_CONTOUR_HW_RATIO_MIN = 1; - gimbal_energy_part_param_.CENTER_R_CONTOUR_AREA_MAX = 100000; - gimbal_energy_part_param_.CENTER_R_CONTOUR_AREA_MIN = 0; - gimbal_energy_part_param_.CENTER_R_CONTOUR_LENGTH_MIN = 8; - gimbal_energy_part_param_.CENTER_R_CONTOUR_LENGTH_MAX = 45; - gimbal_energy_part_param_.CENTER_R_CONTOUR_WIDTH_MIN = 8; - gimbal_energy_part_param_.CENTER_R_CONTOUR_WIDTH_MAX = 45; - gimbal_energy_part_param_.CENTER_R_CONTOUR_HW_RATIO_MAX = 3; + gimbal_energy_part_param_.CENTER_R_CONTOUR_AREA_MAX = 200; + gimbal_energy_part_param_.CENTER_R_CONTOUR_AREA_MIN = 40; + gimbal_energy_part_param_.CENTER_R_CONTOUR_LENGTH_MIN = 6; + gimbal_energy_part_param_.CENTER_R_CONTOUR_LENGTH_MAX = 20; + gimbal_energy_part_param_.CENTER_R_CONTOUR_WIDTH_MIN = 6; + gimbal_energy_part_param_.CENTER_R_CONTOUR_WIDTH_MAX = 20; + gimbal_energy_part_param_.CENTER_R_CONTOUR_HW_RATIO_MAX = 2; gimbal_energy_part_param_.CENTER_R_CONTOUR_HW_RATIO_MIN = 1; - gimbal_energy_part_param_.CENTER_R_CONTOUR_AREA_RATIO_MIN = 0.3; + gimbal_energy_part_param_.CENTER_R_CONTOUR_AREA_RATIO_MIN = 0.6; gimbal_energy_part_param_.CENTER_R_CONTOUR_INTERSETION_AREA_MIN = 10; - gimbal_energy_part_param_.FLOW_STRIP_FAN_CONTOUR_AREA_MAX = 3000; - gimbal_energy_part_param_.FLOW_STRIP_FAN_CONTOUR_AREA_MIN = 1000; + gimbal_energy_part_param_.FLOW_STRIP_FAN_CONTOUR_AREA_MAX = 2000; + gimbal_energy_part_param_.FLOW_STRIP_FAN_CONTOUR_AREA_MIN = 500; gimbal_energy_part_param_.FLOW_STRIP_FAN_CONTOUR_LENGTH_MIN = 60; gimbal_energy_part_param_.FLOW_STRIP_FAN_CONTOUR_LENGTH_MAX = 100; gimbal_energy_part_param_.FLOW_STRIP_FAN_CONTOUR_WIDTH_MIN = 20; gimbal_energy_part_param_.FLOW_STRIP_FAN_CONTOUR_WIDTH_MAX = 52; - gimbal_energy_part_param_.FLOW_STRIP_FAN_CONTOUR_HW_RATIO_MAX = 3; - gimbal_energy_part_param_.FLOW_STRIP_FAN_CONTOUR_HW_RATIO_MIN = 1; - gimbal_energy_part_param_.FLOW_STRIP_FAN_CONTOUR_AREA_RATIO_MAX = 0.65; + gimbal_energy_part_param_.FLOW_STRIP_FAN_CONTOUR_HW_RATIO_MAX = 2.8; + gimbal_energy_part_param_.FLOW_STRIP_FAN_CONTOUR_HW_RATIO_MIN = 1.2; + gimbal_energy_part_param_.FLOW_STRIP_FAN_CONTOUR_AREA_RATIO_MAX = 0.58; gimbal_energy_part_param_.FLOW_STRIP_FAN_CONTOUR_AREA_RATIO_MIN = 0.34; - gimbal_energy_part_param_.FLOW_STRIP_FAN_NON_ZERO_RATE_MAX = 0.65; + gimbal_energy_part_param_.FLOW_STRIP_FAN_NON_ZERO_RATE_MAX = 0.58; gimbal_energy_part_param_.FLOW_STRIP_FAN_NON_ZERO_RATE_MIN = 0.34; // gimbal_energy_part_param_.FLOW_STRIP_FAN_NON_ZERO_RATE_MAX = 0.2; // gimbal_energy_part_param_.FLOW_STRIP_FAN_NON_ZERO_RATE_MIN = 0.08; - gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_AREA_MAX = 100000; - gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_AREA_MIN = 0; - gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_LENGTH_MIN = 30; + gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_AREA_MAX = 700; + gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_AREA_MIN = 100; + gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_LENGTH_MIN = 32; gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_LENGTH_MAX = 55; gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_WIDTH_MIN = 4; gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_WIDTH_MAX = 20; - gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_HW_RATIO_MAX = 12; -// gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_HW_RATIO_MIN = 4; - gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_HW_RATIO_MIN = 1.5; - gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_AREA_RATIO_MIN = 0.5; + gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_HW_RATIO_MAX = 7; + gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_HW_RATIO_MIN = 3; + gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_AREA_RATIO_MIN = 0.6; gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_INTERSETION_AREA_MIN = 100; gimbal_energy_part_param_.TWIN_ANGEL_MAX = 10; @@ -153,6 +151,9 @@ void Energy::initEnergyPartParam() { gimbal_energy_part_param_.TARGET_CHANGE_DISTANCE_MAX = 20; gimbal_energy_part_param_.TWIN_POINT_MAX = 20; + gimbal_energy_part_param_.STRIP_ARMOR_DISTANCE_MIN = 28; + gimbal_energy_part_param_.STRIP_ARMOR_DISTANCE_MAX = 52; + chassis_energy_part_param_.GRAY_THRESH = 120;//home diff --git a/energy/src/energy/find/energy_finder.cpp b/energy/src/energy/find/energy_finder.cpp index a397ec0..c81a34f 100644 --- a/energy/src/energy/find/energy_finder.cpp +++ b/energy/src/energy/find/energy_finder.cpp @@ -14,7 +14,7 @@ using std::vector; // 此函数用于寻找图像内所有的大风车扇叶 // --------------------------------------------------------------------------------------------------------------------- int Energy::findFans(const cv::Mat src) { - if (src.empty()){ + if (src.empty()) { if (show_info) cout << "empty!" << endl; return 0; } @@ -62,7 +62,7 @@ int Energy::findFans(const cv::Mat src) { // 此函数用于寻找图像内所有的大风车装甲板模块 // --------------------------------------------------------------------------------------------------------------------- int Energy::findArmors(const cv::Mat src) { - if (src.empty()){ + if (src.empty()) { if (show_info) cout << "empty!" << endl; return 0; } @@ -77,40 +77,44 @@ int Energy::findArmors(const cv::Mat src) { ArmorStruct(src_bin);//图像膨胀,防止图像断开并更方便寻找 findContours(src_bin, armor_contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE); if (show_process)imshow("armor struct", src_bin); -// findContours(src_bin, armor_contours_external, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); -// for (int i = 0; i < armor_contours_external.size(); i++)//去除外轮廓 -// { -// unsigned long external_contour_size = armor_contours_external[i].size(); -// for (int j = 0; j < armor_contours.size(); j++) { -// unsigned long all_size = armor_contours[j].size(); -// if (external_contour_size == all_size) { -// swap(armor_contours[j], armor_contours[armor_contours.size() - 1]); -// armor_contours.pop_back(); -// break; -// } -// } -// } + findContours(src_bin, armor_contours_external, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); + for (int i = 0; i < armor_contours_external.size(); i++)//去除外轮廓 + { + unsigned long external_contour_size = armor_contours_external[i].size(); + for (int j = 0; j < armor_contours.size(); j++) { + unsigned long all_size = armor_contours[j].size(); + if (external_contour_size == all_size) { + swap(armor_contours[j], armor_contours[armor_contours.size() - 1]); + armor_contours.pop_back(); + break; + } + } + } + for (auto &armor_contour : armor_contours) { if (!isValidArmorContour(armor_contour)) { continue; } armors.emplace_back(cv::minAreaRect(armor_contour)); + // RotatedRect cur_rect = minAreaRect(armor_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 > 5 && width > 5) { -// armors.emplace_back(cv::minAreaRect(armor_contour)); -// cout << "armor area: " << length << '\t' << width << '\t' << cur_rect.center << endl; -// } +// double cur_contour_area = contourArea(armor_contour); +// float length_width_ratio = length / width; +// cout << "area: " << cur_contour_area << '\t' << endl; +// cout << "length: " << length << '\t' << "width: " << width << '\t' << cur_rect.center << endl; +// cout << "HW: " << length_width_ratio << '\t' << cur_rect.center << endl; +// cout << "area ratio: " << cur_contour_area / cur_size.area() << '\t' << cur_rect.center << endl; +// cout<(armors.size()); } @@ -120,7 +124,7 @@ int Energy::findArmors(const cv::Mat src) { // 此函数用于寻找图像内大风车中心字母“R” // --------------------------------------------------------------------------------------------------------------------- bool Energy::findCenterR(const cv::Mat src) { - if (src.empty()){ + if (src.empty()) { if (show_info) cout << "empty!" << endl; return false; } @@ -147,22 +151,18 @@ bool Energy::findCenterR(const cv::Mat src) { // 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 < 10 || width < 5 || length>19) { -// continue; -// } -// std::vector intersection; -// if (rotatedRectangleIntersection(cur_rect, center_ROI, intersection) != 0 && -// contourArea(intersection) > energy_part_param_.CENTER_R_CONTOUR_INTERSETION_AREA_MIN) { -// centerR = cv::minAreaRect(center_R_contour); -// cout << "center R area: " << length << '\t' << width << '\t' << cur_rect.center << endl; -// cout << "R intersection: " << contourArea(intersection) << endl; -// return true; -// } -// cout << cur_rect.center << endl; +// double cur_contour_area = contourArea(center_R_contour); +// float length_width_ratio = length / width; +// cout << "area: " << cur_contour_area << '\t' << endl; +// cout << "length: " << length << '\t' << "width: " << width << '\t' << cur_rect.center << endl; +// cout << "HW: " << length_width_ratio << '\t' << cur_rect.center << endl; +// cout << "area ratio: " << cur_contour_area / cur_size.area() << '\t' << cur_rect.center << endl; +// cout< cur_size.width ? cur_size.height : cur_size.width; // float width = cur_size.height < cur_size.width ? cur_size.height : cur_size.width; // double cur_contour_area = contourArea(flow_strip_fan_contour); -// if (length > 40 && width > 30 && length < 110 && width < 100) { -// cout << cur_rect.center< 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_width_ratio = length / width;//计算矩形长宽比 // double cur_contour_area = contourArea(flow_strip_contour); +// float length_width_ratio = length / width; +// cout << "area: " << cur_contour_area << '\t' << endl; // cout << "length: " << length << '\t' << "width: " << width << '\t' << cur_rect.center << endl; // cout << "HW: " << length_width_ratio << '\t' << cur_rect.center << endl; // cout << "area ratio: " << cur_contour_area / cur_size.area() << '\t' << cur_rect.center << endl; - -// RotatedRect cur_rect = minAreaRect(flow_strip_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 / width > 2.5 && width > 7 && width<40) { -// cout << cur_rect.center << endl; -// flow_strip = cv::minAreaRect(flow_strip_contour); -// cout << "flow strip area: " << length << '\t' << width << endl; -// } -// cout << cur_rect.center << endl; +// cout< candidate_armors = armors; + for (auto &candidate_armor: candidate_armors) { + Point2f vertices[4]; + candidate_armor.size.height *= 1.3; + candidate_armor.size.width *= 1.3; + candidate_armor.points(vertices); //计算矩形的4个顶点 + for (int i = 0; i < 4; i++) { + line(src_bin, vertices[i], vertices[(i + 1) % 4], Scalar(0, 0, 0), 20); + } + } + + cvtColor(src_bin, src_bin, CV_BGR2GRAY);//若读取三通道视频文件,需转换为单通道 + + FlowStripStruct(src_bin);//图像膨胀,防止图像断开并更方便寻找 + if (show_process)imshow("weak struct", src_bin); +// waitKey(0); + + std::vector > flow_strip_contours; + findContours(src_bin, flow_strip_contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); + + for (auto &flow_strip_contour : flow_strip_contours) { + if (!isValidFlowStripContour(flow_strip_contour)) { + continue; + } + + flow_strips.emplace_back(cv::minAreaRect(flow_strip_contour)); + +// RotatedRect cur_rect = minAreaRect(flow_strip_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; +// double cur_contour_area = contourArea(flow_strip_contour); +// float length_width_ratio = length / width; +// cout << "area: " << cur_contour_area << '\t' << endl; +// cout << "length: " << length << '\t' << "width: " << width << '\t' << cur_rect.center << endl; +// cout << "HW: " << length_width_ratio << '\t' << cur_rect.center << endl; +// cout << "area ratio: " << cur_contour_area / cur_size.area() << '\t' << cur_rect.center << endl; +// cout << endl; + + } +// cout << "size: " << flow_strips.size() << endl; + + if (flow_strips.empty()) { + if (show_info)cout << "weak flow strip false!" << endl; +// waitKey(0); + return false; + } else { + for (const auto &candidate_flow_strip: flow_strips) { + for (const auto &candidate_armor: armors) { + if (pointDistance(candidate_flow_strip.center, candidate_armor.center) < + energy_part_param_.STRIP_ARMOR_DISTANCE_MIN || + pointDistance(candidate_flow_strip.center, candidate_armor.center) > + energy_part_param_.STRIP_ARMOR_DISTANCE_MAX) { + continue; + } + float angle_armor = candidate_armor.size.width > candidate_armor.size.height ? candidate_armor.angle : + candidate_armor.angle - 90; + float angle_strip = candidate_flow_strip.size.width > candidate_flow_strip.size.height ? + candidate_flow_strip.angle: candidate_flow_strip.angle - 90; + + if (abs(angle_armor - angle_strip) < 60 || abs(angle_armor - angle_strip) > 120) { + continue; + } + target_armor = candidate_armor; + target_point = candidate_armor.center; + flow_strip = candidate_flow_strip; + return true; + } + } + if (show_info)cout << "weak flow strip false!" << endl; +// waitKey(0); + return false; + } +} + //---------------------------------------------------------------------------------------------------------------------- // 此函数用于框取中心R的寻找范围 // --------------------------------------------------------------------------------------------------------------------- diff --git a/energy/src/energy/judge/judge_contour.cpp b/energy/src/energy/judge/judge_contour.cpp index 60172a5..6f43747 100644 --- a/energy/src/energy/judge/judge_contour.cpp +++ b/energy/src/energy/judge/judge_contour.cpp @@ -100,8 +100,8 @@ bool Energy::isValidArmorContour(const vector &armor_contour) { // --------------------------------------------------------------------------------------------------------------------- bool Energy::isValidCenterRContour(const vector ¢er_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) { + if (cur_contour_area > energy_part_param_.CENTER_R_CONTOUR_AREA_MAX || + cur_contour_area < energy_part_param_.CENTER_R_CONTOUR_AREA_MIN) { //cout<init()) { - LOGM("video_gimbal source initialization successfully."); - } else { - LOGW("video_gimbal source unavailable!"); + if (mcuData.state == BIG_ENERGY_STATE) {//大能量机关模式 + if (last_state != BIG_ENERGY_STATE) {//若上一帧不是大能量机关模式,即刚往完成切换,则需要初始化 + LOGM(STR_CTR(WORD_BLUE, "Start Big Energy!")); + destroyAllWindows(); + if (from_camera) { + delete video_gimbal; + video_gimbal = new CameraWrapper(ENERGY_CAMERA_GAIN, 2/*, "armor"*/); + if (video_gimbal->init()) { + LOGM("video_gimbal source initialization successfully."); + } else { + LOGW("video_gimbal source unavailable!"); + } } + checkReconnect(video_chassis->read(chassis_src)); + energy.setBigEnergyInit(); } - checkReconnect(video_chassis->read(chassis_src)); - energy.setBigEnergyInit(); - } - last_state = mcuData.state;//更新上一帧状态 - ok = checkReconnect(video_gimbal->read(gimbal_src)); - video_chassis->read(chassis_src); + last_state = mcuData.state;//更新上一帧状态 + ok = checkReconnect(video_gimbal->read(gimbal_src)); + video_chassis->read(chassis_src); #ifdef GIMBAL_FLIP_MODE - flip(gimbal_src, gimbal_src, GIMBAL_FLIP_MODE); + flip(gimbal_src, gimbal_src, GIMBAL_FLIP_MODE); #endif #ifdef CHASSIS_FLIP_MODE - flip(chassis_src, chassis_src, CHASSIS_FLIP_MODE); + flip(chassis_src, chassis_src, CHASSIS_FLIP_MODE); #endif - if (!from_camera) extract(gimbal_src, chassis_src); - if (save_video) saveVideos(gimbal_src, chassis_src);//保存视频 - if (show_origin) showOrigin(gimbal_src, chassis_src);//显示原始图像 -// energy.runBig(gimbal_src, chassis_src); - energy.runBig(gimbal_src); - } else if (mcuData.state == SMALL_ENERGY_STATE) { - if (last_state != SMALL_ENERGY_STATE) { - LOGM(STR_CTR(WORD_GREEN, "Start Small Energy!")); - destroyAllWindows(); - if (from_camera) { - delete video_gimbal; - video_gimbal = new CameraWrapper(ENERGY_CAMERA_GAIN, 2/*, "armor"*/); - if (video_gimbal->init()) { - LOGM("video_gimbal source initialization successfully."); - } else { - LOGW("video_gimbal source unavailable!"); + if (!from_camera) extract(gimbal_src, chassis_src); + if (save_video) saveVideos(gimbal_src, chassis_src);//保存视频 + if (show_origin) showOrigin(gimbal_src, chassis_src);//显示原始图像 +// energy.runBig(gimbal_src, chassis_src); + energy.runBig(gimbal_src); + if (show_energy || show_process) waitKey(1); + } else if (mcuData.state == SMALL_ENERGY_STATE) { + if (last_state != SMALL_ENERGY_STATE) { + LOGM(STR_CTR(WORD_GREEN, "Start Small Energy!")); + destroyAllWindows(); + if (from_camera) { + delete video_gimbal; + video_gimbal = new CameraWrapper(ENERGY_CAMERA_GAIN, 2/*, "armor"*/); + if (video_gimbal->init()) { + LOGM("video_gimbal source initialization successfully."); + } else { + LOGW("video_gimbal source unavailable!"); + } + } + energy.setSmallEnergyInit(); + } + last_state = mcuData.state;//更新上一帧状态 + ok = checkReconnect(video_gimbal->read(gimbal_src)); +#ifdef GIMBAL_FLIP_MODE + flip(gimbal_src, gimbal_src, GIMBAL_FLIP_MODE); +#endif + if (!from_camera) extract(gimbal_src); + if (save_video) saveVideos(gimbal_src);//保存视频 + if (show_origin) showOrigin(gimbal_src);//显示原始图像 + energy.runSmall(gimbal_src); + if (show_energy || show_process) waitKey(1); + } else { // 自瞄模式 + if (last_state != ARMOR_STATE) { + LOGM(STR_CTR(WORD_RED, "Start Armor!")); + destroyAllWindows(); + if (from_camera) { + delete video_gimbal; + video_gimbal = new CameraWrapper(ARMOR_CAMERA_GAIN, 2/*, "armor"*/); + if (video_gimbal->init()) { + LOGM("video_gimbal source initialization successfully."); + } else { + LOGW("video_gimbal source unavailable!"); + } } } - energy.setSmallEnergyInit(); - } - last_state = mcuData.state;//更新上一帧状态 - ok = checkReconnect(video_gimbal->read(gimbal_src)); + last_state = mcuData.state; + CNT_TIME(STR_CTR(WORD_GREEN, "read img"), { + if (!checkReconnect(video_gimbal->read(gimbal_src))) continue; + }); #ifdef GIMBAL_FLIP_MODE - flip(gimbal_src, gimbal_src, GIMBAL_FLIP_MODE); -#endif - if (!from_camera) extract(gimbal_src); - if (save_video) saveVideos(gimbal_src);//保存视频 - if (show_origin) showOrigin(gimbal_src);//显示原始图像 - energy.runSmall(gimbal_src); - } else { // 自瞄模式 - if (last_state != ARMOR_STATE) { - LOGM(STR_CTR(WORD_RED, "Start Armor!")); - destroyAllWindows(); - if (from_camera) { - delete video_gimbal; - video_gimbal = new CameraWrapper(ARMOR_CAMERA_GAIN, 2/*, "armor"*/); - if (video_gimbal->init()) { - LOGM("video_gimbal source initialization successfully."); - } else { - LOGW("video_gimbal source unavailable!"); - } - } - } - last_state = mcuData.state; - CNT_TIME(STR_CTR(WORD_GREEN, "read img"), { - if(!checkReconnect(video_gimbal->read(gimbal_src))) continue; - }); -#ifdef GIMBAL_FLIP_MODE - flip(gimbal_src, gimbal_src, GIMBAL_FLIP_MODE); + flip(gimbal_src, gimbal_src, GIMBAL_FLIP_MODE); #endif // CNT_TIME("something whatever", { if (!from_camera) extract(gimbal_src); if (save_video) saveVideos(gimbal_src); if (show_origin) showOrigin(gimbal_src); // }); - CNT_TIME(STR_CTR(WORD_CYAN, "Armor Time"), { - armorFinder.run(gimbal_src); - }); - } + CNT_TIME(STR_CTR(WORD_CYAN, "Armor Time"), { + armorFinder.run(gimbal_src); + }); + } // cv::waitKey(0); }); } while (ok); diff --git a/others/include/config/setconfig.h b/others/include/config/setconfig.h index cf35c9e..f831bbd 100644 --- a/others/include/config/setconfig.h +++ b/others/include/config/setconfig.h @@ -29,25 +29,37 @@ #define ARMOR_CAMERA_GAIN (30) #endif #ifndef ENERGY_CAMERA_GAIN - #define ENERGY_CAMERA_GAIN (30) + #define ENERGY_CAMERA_GAIN (20) #endif -#ifndef YAW_AIM_KD - #define YAW_AIM_KD (0) +#ifndef SMALL_YAW_AIM_KD + #define SMALL_YAW_AIM_KD (1.5) #endif -#ifndef YAW_AIM_KP - #define YAW_AIM_KP (6) +#ifndef SMALL_YAW_AIM_KP + #define SMALL_YAW_AIM_KP (2.5) #endif -#ifndef YAW_AIM_KI - #define YAW_AIM_KI (0.1) +#ifndef SMALL_PITCH_AIM_KD + #define SMALL_PITCH_AIM_KD (1.3) #endif -#ifndef PITCH_AIM_KD - #define PITCH_AIM_KD (0) +#ifndef SMALL_PITCH_AIM_KP + #define SMALL_PITCH_AIM_KP (2.4) #endif -#ifndef PITCH_AIM_KP - #define PITCH_AIM_KP (6) +#ifndef BIG_YAW_AIM_KD + #define BIG_YAW_AIM_KD (0.7) #endif -#ifndef PITCH_AIM_KI - #define PITCH_AIM_KI (0.1) +#ifndef BIG_YAW_AIM_KP + #define BIG_YAW_AIM_KP (4.5) +#endif +#ifndef BIG_YAW_AIM_KI + #define BIG_YAW_AIM_KI (0.1) +#endif +#ifndef BIG_PITCH_AIM_KD + #define BIG_PITCH_AIM_KD (0.7) +#endif +#ifndef BIG_PITCH_AIM_KP + #define BIG_PITCH_AIM_KP (4.5) +#endif +#ifndef BIG_PITCH_AIM_KI + #define BIG_PITCH_AIM_KI (0.1) #endif #ifndef COMPENSATE_YAW #define COMPENSATE_YAW (5)