energy changed
This commit is contained in:
@@ -23,128 +23,150 @@ using std::vector;
|
||||
|
||||
class Energy {
|
||||
public:
|
||||
Energy(Serial &u, uint8_t &color);//构造函数,参数为串口和敌方颜色
|
||||
~Energy();//默认析构函数
|
||||
int runBig(cv::Mat &gimble_src, cv::Mat &chassis_src);
|
||||
Energy(Serial &u, uint8_t &color);//构造函数,参数为串口和敌方颜色
|
||||
~Energy();//默认析构函数
|
||||
int runBig(cv::Mat &gimble_src, cv::Mat &chassis_src);
|
||||
|
||||
int runBig(cv::Mat &gimble_src);
|
||||
|
||||
int runSmall(cv::Mat &gimble_src);
|
||||
Serial &serial;//串口
|
||||
void setEnergyRotationInit();//判断顺逆时针函数
|
||||
void extract(cv::Mat &src);//框取图像中的一块区域进行处理
|
||||
void sendTarget(Serial& serial, float x, float y, char change, char shoot);
|
||||
|
||||
Serial &serial;//串口
|
||||
void setEnergyRotationInit();//判断顺逆时针函数
|
||||
void extract(cv::Mat &src);//框取图像中的一块区域进行处理
|
||||
void sendTarget(Serial &serial, float x, float y, float z);
|
||||
|
||||
|
||||
private:
|
||||
EnergyPartParam energy_part_param_;//能量机关的参数设置
|
||||
EnergyPartParam gimble_energy_part_param_;//云台摄像头能量机关的参数设置
|
||||
EnergyPartParam gimble_energy_part_param_;//云台摄像头能量机关的参数设置
|
||||
EnergyPartParam chassis_energy_part_param_;//底盘摄像头能量机关的参数设置
|
||||
bool isMark;//若操作手正在手动标定,则为true
|
||||
bool isGimble;//同时具有底盘和云台摄像头时,处于云台摄像头对心过程
|
||||
bool isChassis;//同时具有底盘和云台摄像头时,处于底盘摄像头击打过程
|
||||
bool isGuessing;//当前处于发弹到新目标出现的过程,则为true,此时猜测下一个目标
|
||||
bool isPredicting;//当前处于新目标出现到发弹的过程,则为true,此时正常击打
|
||||
int fans_cnt;//图像中的扇叶个数
|
||||
int armors_cnt;//图像中的装甲板个数
|
||||
int centerRs_cnt;//图像中可能的风车中心字母R选区个数
|
||||
int flow_strip_fans_cnt;//图像中的含流动条扇叶个数
|
||||
int flow_strips_cnt;//图像中的流动条个数
|
||||
int last_fans_cnt;//上一帧的扇叶个数
|
||||
int last_armors_cnt;//上一帧的装甲板个数
|
||||
int last_flow_strip_fans_cnt;//上一帧的含流动条扇叶个数
|
||||
int last_flow_strips_cnt;//上一帧的流动条个数
|
||||
double radius;//大风车半径
|
||||
float target_polar_angle;//待击打装甲板的极坐标角度
|
||||
bool isMark;//若操作手正在手动标定,则为true
|
||||
bool isGimble;//同时具有底盘和云台摄像头时,处于云台摄像头对心过程
|
||||
bool isChassis;//同时具有底盘和云台摄像头时,处于底盘摄像头击打过程
|
||||
bool isGuessing;//当前处于发弹到新目标出现的过程,则为true,此时猜测下一个目标
|
||||
bool isPredicting;//当前处于新目标出现到发弹的过程,则为true,此时正常击打
|
||||
// int fans_cnt;//图像中的扇叶个数
|
||||
// int armors_cnt;//图像中的装甲板个数
|
||||
// int centerRs_cnt;//图像中可能的风车中心字母R选区个数
|
||||
// int flow_strip_fans_cnt;//图像中的含流动条扇叶个数
|
||||
// int flow_strips_cnt;//图像中的流动条个数
|
||||
int last_fans_cnt;//上一帧的扇叶个数
|
||||
int last_flow_strip_fans_cnt;//上一帧的含流动条扇叶个数
|
||||
int last_flow_strips_cnt;//上一帧的流动条个数
|
||||
double radius;//大风车半径
|
||||
float target_polar_angle;//待击打装甲板的极坐标角度
|
||||
float last_target_polar_angle;//上一帧待击打装甲板的极坐标角度
|
||||
uint8_t &ally_color;//我方颜色
|
||||
int energy_rotation_direction;//风车旋转方向
|
||||
float attack_distance;//步兵与风车平面距离
|
||||
int send_cnt;//向主控板发送的数据总次数
|
||||
float yaw_rotation;//云台yaw轴应该转到的角度
|
||||
float pitch_rotation;//云台pitch轴应该转到的角度
|
||||
uint8_t last_mark;//用于记录上一帧操作手是否进行标定
|
||||
float guess_polar_angle;//猜测的下一个目标装甲板极坐标角度
|
||||
float last_base_angle;//上一帧的各扇叶在0区(0°~72°)的基础角度
|
||||
uint8_t &ally_color;//我方颜色
|
||||
int energy_rotation_direction;//风车旋转方向
|
||||
float attack_distance;//步兵与风车平面距离
|
||||
int send_cnt;//向主控板发送的数据总次数
|
||||
float yaw_rotation;//云台yaw轴应该转到的角度
|
||||
float pitch_rotation;//云台pitch轴应该转到的角度
|
||||
uint8_t last_mark;//用于记录上一帧操作手是否进行标定
|
||||
double predict_rad;//预测提前角
|
||||
bool energy_rotation_init;//若仍在判断风车旋转方向,则为true
|
||||
int clockwise_rotation_init_cnt;//装甲板顺时针旋转次数
|
||||
int anticlockwise_rotation_init_cnt;//装甲板逆时针旋转次数
|
||||
float red_origin_yaw, red_origin_pitch;//红方的初始云台对心角度设定值
|
||||
float blue_origin_yaw, blue_origin_pitch;//蓝方的初始云台对心角度设定值
|
||||
float origin_yaw, origin_pitch;//初始的云台角度设定值
|
||||
float target_cnt;//用于记录寻找到的装甲板总数,该值变化则立即中断主控板发射进程,防止重复击打已点亮的装甲板
|
||||
bool energy_rotation_init;//若仍在判断风车旋转方向,则为true
|
||||
int clockwise_rotation_init_cnt;//装甲板顺时针旋转次数
|
||||
int anticlockwise_rotation_init_cnt;//装甲板逆时针旋转次数
|
||||
float red_origin_yaw, red_origin_pitch;//红方的初始云台对心角度设定值
|
||||
float blue_origin_yaw, blue_origin_pitch;//蓝方的初始云台对心角度设定值
|
||||
float origin_yaw, origin_pitch;//初始的云台角度设定值
|
||||
float target_cnt;//用于记录寻找到的装甲板总数,该值变化则立即中断主控板发射进程,防止重复击打已点亮的装甲板
|
||||
bool save_new_mark;//若操作手进行过手动标定,则为true
|
||||
bool big_energy_shoot;//大符模式中,若为true,则要求主控板发弹
|
||||
bool small_energy_shoot;//小符模式中,若为true,则要求主控板发弹
|
||||
std::vector<EnergyPart> fans;//图像中所有扇叶
|
||||
std::vector<EnergyPart> armors;//图像中所有装甲板
|
||||
std::vector<EnergyPart> centerRs;//风车中心字母R的可能候选区
|
||||
std::vector<EnergyPart> flow_strips;//图像中所有流动条(理论上只有一个)
|
||||
std::vector<EnergyPart> flow_strip_fans;//图像中所有流动条所在扇叶(理论上只有一个)
|
||||
std::vector<EnergyPart> center_ROI;//风车中心候选区
|
||||
std::vector<EnergyPart> target_armor;//目标装甲板(理论上仅一个)
|
||||
bool shoot;//若为true,则要求主控板发弹
|
||||
int guess_devide;
|
||||
bool startguessing;
|
||||
timeval time_start_guess;
|
||||
std::vector<cv::RotatedRect> fans;//图像中所有扇叶
|
||||
std::vector<cv::RotatedRect> armors;//图像中所有可能装甲板(可能存在误识别)
|
||||
// std::vector<cv::RotatedRect> centerRs;//风车中心字母R的可能候选区
|
||||
// std::vector<cv::RotatedRect> flow_strips;//图像中所有流动条(理论上只有一个)
|
||||
// std::vector<cv::RotatedRect> flow_strip_fans;//图像中所有流动条所在扇叶(理论上只有一个)
|
||||
// std::vector<cv::RotatedRect> center_ROI;//风车中心候选区
|
||||
// std::vector<cv::RotatedRect> target_armor;//目标装甲板(理论上仅一个)
|
||||
cv::RotatedRect centerR;//风车中心字母R的可能候选区
|
||||
cv::RotatedRect flow_strip;//图像中所有流动条(理论上只有一个)
|
||||
cv::RotatedRect flow_strip_fan;//图像中所有流动条所在扇叶(理论上只有一个)
|
||||
cv::RotatedRect center_ROI;//风车中心候选区
|
||||
cv::RotatedRect target_armor;//目标装甲板(理论上仅一个)
|
||||
|
||||
cv::Point circle_center_point;//风车圆心坐标
|
||||
cv::Point target_point;//目标装甲板中心坐标
|
||||
cv::Point last_target_point;//上一帧目标装甲板中心坐标
|
||||
cv::Point predict_point;//预测的击打点坐标
|
||||
std::vector<float>fan_polar_angle;//当前帧所有扇叶的极坐标角度
|
||||
std::vector<float>armor_polar_angle;//当前帧所有装甲板的极坐标角度
|
||||
cv::Point circle_center_point;//风车圆心坐标
|
||||
cv::Point target_point;//目标装甲板中心坐标
|
||||
cv::Point last_target_point;//上一帧目标装甲板中心坐标
|
||||
cv::Point guess_point;
|
||||
cv::Point predict_point;//预测的击打点坐标
|
||||
std::vector<float> fan_polar_angle;//当前帧所有扇叶的极坐标角度
|
||||
std::vector<float> armor_polar_angle;//当前帧所有装甲板的极坐标角度
|
||||
std::vector<cv::Point> all_armor_centers;//记录全部的装甲板中心,用于风车圆心和半径的计算
|
||||
cv::Mat src_blue, src_red, src_green;//通道分离中的三个图像通道
|
||||
cv::Mat src_blue, src_red, src_green;//通道分离中的三个图像通道
|
||||
|
||||
void initEnergy();//能量机关初始化
|
||||
void initEnergyPartParam();//能量机关参数初始化
|
||||
void initRotation();//顺逆时针初始化
|
||||
void initEnergy();//能量机关初始化
|
||||
void initEnergyPartParam();//能量机关参数初始化
|
||||
void initRotation();//顺逆时针初始化
|
||||
|
||||
void changeMode();//猜测模式与击打模式切换
|
||||
bool isGimbleCentered();//判断云台摄像头对心是否完成
|
||||
void clearAll();//清空各vector
|
||||
void initImage(cv::Mat &src);//图像预处理
|
||||
|
||||
int findFan(const cv::Mat src, int &last_fans_cnt);//寻找图中所有扇叶
|
||||
int findArmor(const cv::Mat src, int &last_armors_cnt);//寻找图中所有装甲板
|
||||
int findCenterR(const cv::Mat src);//寻找图中可能的风车中心字母R
|
||||
int findFlowStrip(const cv::Mat src, int &last_flow_strips_cnt);//寻找图中的流动条
|
||||
void findCenterROI(const cv::Mat src);//框取中心R候选区
|
||||
int findFlowStripFan(const cv::Mat src, int &last_flow_strip_fans_cnt);//寻找图中的流动条所在扇叶
|
||||
void startChassis();//从云台摄像头对心状态进入底盘摄像头击打状态
|
||||
|
||||
bool isValidFanContour(const vector<cv::Point> &fan_contour);//扇叶矩形尺寸要求
|
||||
int findFans(const cv::Mat src);//寻找图中所有扇叶
|
||||
int findArmors(const cv::Mat src);//寻找图中所有装甲板
|
||||
bool findCenterR(const cv::Mat src);//寻找图中可能的风车中心字母R
|
||||
bool findFlowStrip(const cv::Mat src);//寻找图中的流动条
|
||||
bool findCenterROI(const cv::Mat src);//框取中心R候选区
|
||||
bool findFlowStripFan(const cv::Mat src);//寻找图中的流动条所在扇叶
|
||||
|
||||
bool isValidFanContour(cv::Mat &src, const vector<cv::Point> &fan_contour);//扇叶矩形尺寸要求
|
||||
bool isValidArmorContour(const vector<cv::Point> &armor_contour);//装甲板矩形尺寸要求
|
||||
bool isValidCenterRContour(const vector<cv::Point> ¢er_R_contour);//风车中心选区尺寸要求
|
||||
bool isValidFlowStripContour(const vector<cv::Point> &flow_strip_contour);//流动条扇叶矩形尺寸要求
|
||||
bool isValidFlowStripFanContour(const vector<cv::Point> &flow_strip_fan_contour);//流动条扇叶矩形尺寸要求
|
||||
bool isValidFlowStripFanContour(cv::Mat &src, const vector<cv::Point> &flow_strip_fan_contour);//流动条扇叶矩形尺寸要求
|
||||
|
||||
void showFanContours(std::string windows_name, const cv::Mat src);//显示扇叶
|
||||
void showArmorContours(std::string windows_name, const cv::Mat src);//显示装甲板
|
||||
void showBothContours(std::string windows_name, const cv::Mat src);//显示扇叶和装甲板
|
||||
void showFanContours(std::string windows_name, const cv::Mat src);//显示扇叶
|
||||
void showArmorContours(std::string windows_name, const cv::Mat src);//显示装甲板
|
||||
void showBothContours(std::string windows_name, const cv::Mat src);//显示扇叶和装甲板
|
||||
void showCenterRContours(std::string windows_name, const cv::Mat src);//显示风车中心候选区R
|
||||
void showFlowStripFanContours(std::string windows_name, const cv::Mat src);//显示流动条所在扇叶
|
||||
void showGuessTarget(std::string windows_name, const cv::Mat src);//显示猜测点位
|
||||
|
||||
void getFanPolarAngle();//获取扇叶极坐标角度
|
||||
void getArmorPolarAngle();//获取装甲板极坐标角度
|
||||
void getAllArmorCenters();//记录所有装甲板中心坐标
|
||||
void getOrigin();//获得云台对心所需角度
|
||||
void getOrigin();//获得云台对心所需角度
|
||||
void guessTarget();//获得猜测击打点位
|
||||
|
||||
void circleLeastFit();//利用所有记录的装甲板中心最小二乘法计算圆心和半径
|
||||
|
||||
void findTargetByPolar();//通过极坐标角度匹配获取目标装甲板的极坐标角度和装甲板中心坐标
|
||||
void findTargetByPolar();//通过极坐标角度匹配获取目标装甲板的极坐标角度和装甲板中心坐标
|
||||
void findTargetByIntersection();//通过面积重合度匹配获取目标装甲板的极坐标角度和装甲板中心坐标
|
||||
bool findTargetInFlowStripFan();//在已发现的流动条区域中寻找待击打装甲板
|
||||
|
||||
void rotate();//获取预测点位
|
||||
void stretch(cv::Point point_1, cv::Point2f &point_2);//将像素差转换为实际距离差
|
||||
void stretch(cv::Point point_1, cv::Point2f &point_2);//将像素差转换为实际距离差
|
||||
double pointDistance(cv::Point point_1, cv::Point point_2);//计算两点距离
|
||||
int devide(float angle);//将极坐标分为五个区域,判断一个角度处于哪个区域
|
||||
int linePointX(const cv::Point2f &p1, const cv::Point2f &p2, int y);//计算直线上一点横坐标
|
||||
double nonZeroRateOfRotateRect(const cv::Mat &bin, const cv::RotatedRect &rotatedRect);//计算旋转矩形内亮点占比
|
||||
|
||||
void writeDownMark();//记录操作手标定的云台初始角度
|
||||
void writeDownMark();//记录操作手标定的云台初始角度
|
||||
|
||||
void getTargetPolarAngle();
|
||||
void getPredictPoint();//获取预测点位
|
||||
void getAimPoint();//通过自瞄逻辑计算点位
|
||||
bool changeTarget();//判断目标是否改变
|
||||
void changeMark();//操作手手动修改标定值
|
||||
bool changeTarget();//判断目标是否改变
|
||||
void changeMark();//操作手手动修改标定值
|
||||
void gimbleRotation();//计算云台旋转角度
|
||||
|
||||
void splitBayerBG(cv::Mat src, cv::Mat &blue, cv::Mat &red);//拜耳阵列分离
|
||||
void imagePreprocess(cv::Mat &src);//图像通道分离
|
||||
void judgeBigShoot();//判断大符模式是否可以发弹
|
||||
void judgeSmallShoot();//判断小符模式是否可以发弹
|
||||
bool is_guessing_timeout();//判断猜测模式是否超时(没打中)
|
||||
|
||||
void splitBayerBG(cv::Mat src, cv::Mat &blue, cv::Mat &red);//拜耳阵列分离
|
||||
void imagePreprocess(cv::Mat &src);//图像通道分离
|
||||
void hsvFilter(cv::Mat &src);//此函数通过HSV颜色空间对图像纯度进行限制,进行滤光
|
||||
|
||||
void StructingElementClose(cv::Mat &src,int length, int width);//闭运算
|
||||
void StructingElementErodeDilate(cv::Mat &src);//腐蚀和膨胀
|
||||
void StructingElementClose(cv::Mat &src, int length, int width);//闭运算
|
||||
void StructingElementErodeDilate(cv::Mat &src);//腐蚀和膨胀
|
||||
void StructingElementDilateErode(cv::Mat &src);//腐蚀和膨胀
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -12,24 +12,6 @@ using std::vector;
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
// 此结构体为能量机关模块的结构体,用于寻找矩形轮廓
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
struct EnergyPart {
|
||||
cv::RotatedRect rect;
|
||||
float angle;
|
||||
vector<cv::Point> contour;
|
||||
|
||||
explicit EnergyPart(vector<cv::Point> &c) : contour(c) {
|
||||
rect = cv::minAreaRect(c);
|
||||
angle = cv::minAreaRect(c).angle;
|
||||
};
|
||||
|
||||
EnergyPart(cv::RotatedRect rect=cv::RotatedRect(), float angle=0, vector<cv::Point> contour=vector<cv::Point>()):rect(rect),angle(angle),contour(contour){};
|
||||
};
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
// 此结构体包括能量机关参数
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
@@ -48,6 +30,8 @@ struct EnergyPartParam {
|
||||
float FAN_CONTOUR_HW_RATIO_MAX;//扇叶长宽比最大值
|
||||
float FAN_CONTOUR_HW_RATIO_MIN;//扇叶长宽比最小值
|
||||
float FAN_CONTOUR_AREA_RATIO_MIN;//装甲板轮廓占旋转矩形面积比最小值
|
||||
double FAN_NON_ZERO_RATE_MAX;//流动条扇叶中亮点占旋转矩形的比值最大值
|
||||
double FAN_NON_ZERO_RATE_MIN;//流动条扇叶中亮点占旋转矩形的比值最大值
|
||||
|
||||
long ARMOR_CONTOUR_AREA_MAX;//装甲板面积最大值
|
||||
long ARMOR_CONTOUR_AREA_MIN;//装甲板面积最小值
|
||||
@@ -78,8 +62,10 @@ struct EnergyPartParam {
|
||||
long FLOW_STRIP_FAN_CONTOUR_WIDTH_MAX;//流动条扇叶(待击打)宽边长度最大值
|
||||
float FLOW_STRIP_FAN_CONTOUR_HW_RATIO_MAX;//流动条扇叶(待击打)长宽比最大值
|
||||
float FLOW_STRIP_FAN_CONTOUR_HW_RATIO_MIN;//流动条扇叶(待击打)长宽比最小值
|
||||
float FLOW_STRIP_FAN_CONTOUR_AREA_RATIO_MAX;//装甲板轮廓占旋转矩形面积比最小值
|
||||
float FLOW_STRIP_FAN_CONTOUR_AREA_RATIO_MIN;//装甲板轮廓占旋转矩形面积比最小值
|
||||
float FLOW_STRIP_FAN_CONTOUR_AREA_RATIO_MAX;//流动条扇叶轮廓占旋转矩形面积比最小值
|
||||
float FLOW_STRIP_FAN_CONTOUR_AREA_RATIO_MIN;//流动条扇叶占旋转矩形面积比最小值
|
||||
double FLOW_STRIP_FAN_NON_ZERO_RATE_MAX;//流动条扇叶中亮点占旋转矩形的比值最大值
|
||||
double FLOW_STRIP_FAN_NON_ZERO_RATE_MIN;//流动条扇叶中亮点占旋转矩形的比值最大值
|
||||
|
||||
long FLOW_STRIP_CONTOUR_AREA_MAX;//流动条(待击打)面积最大值
|
||||
long FLOW_STRIP_CONTOUR_AREA_MIN;//流动条(待击打)面积最小值
|
||||
@@ -89,10 +75,10 @@ struct EnergyPartParam {
|
||||
long FLOW_STRIP_CONTOUR_WIDTH_MAX;//流动条(待击打)宽边长度最大值
|
||||
float FLOW_STRIP_CONTOUR_HW_RATIO_MAX;//流动条(待击打)长宽比最大值
|
||||
float FLOW_STRIP_CONTOUR_HW_RATIO_MIN;//流动条(待击打)长宽比最小值
|
||||
float FLOW_STRIP_CONTOUR_AREA_RATIO_MIN;//装甲板轮廓占旋转矩形面积比最小值
|
||||
float FLOW_STRIP_CONTOUR_AREA_RATIO_MIN;//流动条占旋转矩形面积比最小值
|
||||
float FLOW_STRIP_CONTOUR_INTERSETION_AREA_MIN;//流动条占旋转矩形面积比最小值
|
||||
|
||||
float TWIN_ANGEL_MAX;//扇叶和装甲板匹配时极坐标角度差的最大值
|
||||
float TWIN_ANGEL_MAX;//两个理论上相等的角度在计算时具有的可能最大差值
|
||||
long INTERSETION_CONTOUR_AREA_MIN;//扇叶与装甲板匹配时的最小重合面积
|
||||
|
||||
long TARGET_CHANGE_DISTANCE_MAX;//目标未更改时,目标装甲板中心与原目标装甲板中心的距离变化最大值
|
||||
|
||||
Reference in New Issue
Block a user