Change the parameters for judgements

This commit is contained in:
wanpiqiu123
2019-07-18 10:45:04 +08:00
parent 7201dacad3
commit f60c3ecc62
4 changed files with 39 additions and 26 deletions

View File

@@ -115,10 +115,10 @@ void Energy::initEnergyPartParam() {
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 = 50;
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.58;
gimbal_energy_part_param_.FLOW_STRIP_FAN_CONTOUR_AREA_RATIO_MAX = 0.62;
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.58;
gimbal_energy_part_param_.FLOW_STRIP_FAN_NON_ZERO_RATE_MIN = 0.34;
@@ -127,13 +127,13 @@ void Energy::initEnergyPartParam() {
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 = 40;
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_LENGTH_MAX = 65;
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_LENGTH_MIN = 38;
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_LENGTH_MAX = 60;
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_WIDTH_MIN = 8;
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_WIDTH_MAX = 20;
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_WIDTH_MAX = 28;
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 = 3;
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_HW_RATIO_MIN = 2.3;
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_AREA_RATIO_MIN = 0.5;
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_INTERSETION_AREA_MIN = 117;

View File

@@ -173,7 +173,6 @@ bool Energy:: findFlowStripFan(const cv::Mat src) {
// imshow("flow strip fan struct", src_bin);
findContours(src_bin, flow_strip_fan_contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
for (auto &flow_strip_fan_contour : flow_strip_fan_contours) {
if (!isValidFlowStripFanContour(src_bin, flow_strip_fan_contour)) {
continue;
@@ -198,6 +197,7 @@ bool Energy:: findFlowStripFan(const cv::Mat src) {
}
// showFlowStripFan("strip fan", src_bin);
cout << "flow strip fan false!" << endl;
// waitKey();
return false;
}
@@ -222,6 +222,7 @@ bool Energy::findFlowStrip(const cv::Mat src) {
if (!isValidFlowStripContour(flow_strip_contour)) {
continue;
}
// cout<<"size: "<<contourArea(flow_strip_contour)<<endl;
flow_strip = cv::minAreaRect(flow_strip_contour);
// RotatedRect cur_rect = minAreaRect(flow_strip_contour);
// Size2f cur_size = cur_rect.size;
@@ -234,8 +235,8 @@ bool Energy::findFlowStrip(const cv::Mat src) {
// }
return true;
}
// waitKey();
cout << "flow strip false!" << endl;
// waitKey();
return false;
}

View File

@@ -138,11 +138,12 @@ bool Energy::isValidFlowStripFanContour(cv::Mat &src, const vector<cv::Point> &f
double cur_contour_area = contourArea(flow_strip_fan_contour);
if (cur_contour_area > energy_part_param_.FLOW_STRIP_FAN_CONTOUR_AREA_MAX ||
cur_contour_area < energy_part_param_.FLOW_STRIP_FAN_CONTOUR_AREA_MIN) {
//cout<<cur_contour_area<<" "<<energy_fan_param_.CONTOUR_AREA_MIN<<" "<<energy_fan_param_.CONTOUR_AREA_MAX<<endl;
// cout<<"area fail."<<endl;
return false;
//选区面积大小不合适
}
// cout<<cur_contour_area<<endl;
RotatedRect cur_rect = minAreaRect(flow_strip_fan_contour);
Size2f cur_size = cur_rect.size;
float length = cur_size.height > cur_size.width ? cur_size.height : cur_size.width;//将矩形的长边设置为长
@@ -151,11 +152,12 @@ bool Energy::isValidFlowStripFanContour(cv::Mat &src, const vector<cv::Point> &f
|| width < energy_part_param_.FLOW_STRIP_FAN_CONTOUR_WIDTH_MIN
|| length > energy_part_param_.FLOW_STRIP_FAN_CONTOUR_LENGTH_MAX
|| width > energy_part_param_.FLOW_STRIP_FAN_CONTOUR_WIDTH_MAX) {
// if(cur_contour_area>1600)
// cout<<"length: "<<length<<"width: "<<width<<endl;
// cout<<"length width fail."<<endl;
return false;
//矩形边长不合适
}
float length_width_ratio = length / width;//计算矩形长宽比
if (length_width_ratio > energy_part_param_.FLOW_STRIP_FAN_CONTOUR_HW_RATIO_MAX ||
length_width_ratio < energy_part_param_.FLOW_STRIP_FAN_CONTOUR_HW_RATIO_MIN) {
@@ -166,6 +168,8 @@ bool Energy::isValidFlowStripFanContour(cv::Mat &src, const vector<cv::Point> &f
// cout << cur_contour_area / cur_size.area() << endl;
if (cur_contour_area / cur_size.area() < energy_part_param_.FLOW_STRIP_FAN_CONTOUR_AREA_RATIO_MIN
|| cur_contour_area / cur_size.area() > energy_part_param_.FLOW_STRIP_FAN_CONTOUR_AREA_RATIO_MAX) {
if(cur_contour_area>1600)
cout<<"size ratio: "<<cur_contour_area / cur_size.area()<<endl;
return false;
}
// 轮廓对矩形的面积占有率不合适
@@ -189,11 +193,19 @@ bool Energy::isValidFlowStripContour(const vector<cv::Point> &flow_strip_contour
if (cur_contour_area > energy_part_param_.FLOW_STRIP_CONTOUR_AREA_MAX ||
cur_contour_area < energy_part_param_.FLOW_STRIP_CONTOUR_AREA_MIN) {
// cout<<"area fail."<<endl;
return false;
//选区面积大小不合适
}
RotatedRect cur_rect = minAreaRect(flow_strip_contour);
std::vector<cv::Point2f> intersection;
if (rotatedRectangleIntersection(cur_rect, flow_strip_fan, intersection) == 0 ||
contourArea(intersection) < energy_part_param_.FLOW_STRIP_CONTOUR_INTERSETION_AREA_MIN) {
// cout<<"Intersection false!"<<endl;
return false;
//面积占比不合适
}
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;//将矩形的短边设置为宽
@@ -201,6 +213,8 @@ bool Energy::isValidFlowStripContour(const vector<cv::Point> &flow_strip_contour
width < energy_part_param_.FLOW_STRIP_CONTOUR_WIDTH_MIN ||
length > energy_part_param_.FLOW_STRIP_CONTOUR_LENGTH_MAX ||
width > energy_part_param_.FLOW_STRIP_CONTOUR_WIDTH_MAX) {
// if(cur_contour_area>600&&cur_contour_area<900)
// cout<<"length: "<<length<<" width: "<<width<<endl;
// cout<<"length width fail."<<endl;
return false;
//矩形边长不合适
@@ -208,16 +222,14 @@ bool Energy::isValidFlowStripContour(const vector<cv::Point> &flow_strip_contour
float length_width_ratio = length / width;//计算矩形长宽比
if (length_width_ratio > energy_part_param_.FLOW_STRIP_CONTOUR_HW_RATIO_MAX ||
length_width_ratio < energy_part_param_.FLOW_STRIP_CONTOUR_HW_RATIO_MIN) {
// if(cur_contour_area>600&&cur_contour_area<900)
// cout<<"length: "<<length<<" width: "<<width<<" hw: "<<length_width_ratio<<endl;
// cout<<"hw fail."<<endl;
return false;
//长宽比不合适
}
if (cur_contour_area / cur_size.area() < energy_part_param_.FLOW_STRIP_CONTOUR_AREA_RATIO_MIN)
return false;//轮廓对矩形的面积占有率不合适
std::vector<cv::Point2f> intersection;
if (rotatedRectangleIntersection(cur_rect, flow_strip_fan, intersection) == 0 ||
contourArea(intersection) < energy_part_param_.FLOW_STRIP_CONTOUR_INTERSETION_AREA_MIN) {
return false;
}
return true;
}

View File

@@ -64,10 +64,10 @@ int main(int argc, char *argv[]) {
video_gimbal = new CameraWrapper(0/*, "armor"*/);
video_chassis = new CameraWrapper(1/*, "energy"*/);
} else {
// video_gimbal = new VideoWrapper("/home/sjturm/Desktop/videos/147.avi");
// video_chassis = new VideoWrapper("/home/sjturm/Desktop/videos/147.avi");
video_gimbal = new VideoWrapper("/home/sjturm/Desktop/dafu/gimble3.avi");
video_chassis = new VideoWrapper("/home/sjturm/Desktop/dafu/chassis3.avi");
video_gimbal = new VideoWrapper("/home/sjturm/Desktop/videos/gimbal84.avi");
video_chassis = new VideoWrapper("/home/sjturm/Desktop/videos/gimbal84.avi");
// video_gimbal = new VideoWrapper("/home/sjturm/Desktop/dafu/gimble3.avi");
// video_chassis = new VideoWrapper("/home/sjturm/Desktop/dafu/chassis3.avi");
}
if (video_gimbal->init()) {
LOGM("video_gimbal source initialization successfully.");
@@ -113,8 +113,8 @@ int main(int argc, char *argv[]) {
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.run(gimbal_src, chassis_src);
// energy.run(gimbal_src);
// energy.run(gimbal_src, chassis_src);
energy.run(gimbal_src);
last_state = mcuData.state;//更新上一帧状态
} else { // 自瞄模式
if (last_state != ARMOR_STATE) {
@@ -133,7 +133,7 @@ int main(int argc, char *argv[]) {
armorFinder.run(gimbal_src);
});
}
cv::waitKey(1);
cv::waitKey(20);
});
} while (ok);
delete video_gimbal;