some refactor
This commit is contained in:
@@ -4,10 +4,12 @@
|
||||
#ifndef CONSTANT_H
|
||||
#define CONSTANT_H
|
||||
|
||||
#include "additions/additions.h"
|
||||
|
||||
#define d2r (CV_PI / 180.0)
|
||||
|
||||
const int ALLY_BLUE = 123;
|
||||
const int ALLY_RED = 456;
|
||||
const int ALLY_BLUE = ENEMY_RED;
|
||||
const int ALLY_RED = ENEMY_BLUE;
|
||||
const int SRC_WIDTH_CAMERA = 640;
|
||||
const int SRC_HEIGHT_CAMERA = 480;
|
||||
const int SRC_WIDTH = 320;
|
||||
|
||||
@@ -15,12 +15,13 @@
|
||||
#include "energy/constant.h"
|
||||
#include "energy/param_struct_define.h"
|
||||
#include "serial/serial.h"
|
||||
#include "additions/additions.h"
|
||||
|
||||
using std::vector;
|
||||
|
||||
class Energy {
|
||||
public:
|
||||
Energy(Serial &u, int &ally_color);
|
||||
Energy(Serial &u, uint8_t &enemy_color);
|
||||
~Energy();
|
||||
int run(cv::Mat &src);
|
||||
|
||||
@@ -28,7 +29,7 @@ public:
|
||||
clock_t start;
|
||||
Serial &serial;
|
||||
|
||||
void setAllyColor(int color);
|
||||
// void setAllyColor(int color);
|
||||
void setRotation(int rotation);
|
||||
|
||||
void extract(cv::Mat &src);
|
||||
@@ -51,7 +52,7 @@ private:
|
||||
double last_target_position;
|
||||
double last_hit_position;
|
||||
float target_armor;
|
||||
int &ally_color_;
|
||||
uint8_t &ally_color;
|
||||
int energy_part_rotation;
|
||||
float attack_distance;
|
||||
int send_cnt;
|
||||
|
||||
@@ -28,10 +28,10 @@ void Energy::imagePreprocess(cv::Mat &src) {
|
||||
if(src.type() == CV_8UC1)
|
||||
{
|
||||
splitBayerBG(src, src_blue, src_red);
|
||||
if(ally_color_ == ALLY_RED)
|
||||
if(ally_color == ALLY_RED)
|
||||
{
|
||||
src = src_red - src_blue;
|
||||
}else if(ally_color_ == ALLY_BLUE){
|
||||
}else if(ally_color == ALLY_BLUE){
|
||||
src = src_blue - src_red;
|
||||
}
|
||||
}
|
||||
@@ -44,11 +44,11 @@ void Energy::imagePreprocess(cv::Mat &src) {
|
||||
resize(channels.at(0), src_blue, Size(SRC_WIDTH, SRC_HEIGHT));
|
||||
resize(channels.at(1), src_green, Size(SRC_WIDTH, SRC_HEIGHT));
|
||||
resize(channels.at(2), src_red, Size(SRC_WIDTH, SRC_HEIGHT));
|
||||
if(ally_color_ == ALLY_RED)
|
||||
if(ally_color == ALLY_RED)
|
||||
{
|
||||
src = src_red-src_blue;
|
||||
//src=src_red;
|
||||
}else if(ally_color_ == ALLY_BLUE){
|
||||
}else if(ally_color == ALLY_BLUE){
|
||||
src = src_blue-src_red;
|
||||
//src=src_blue;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ using std::cout;
|
||||
using std::endl;
|
||||
using std::vector;
|
||||
|
||||
Energy::Energy(Serial &u, int &ally_color):serial(u),ally_color_(ally_color),
|
||||
Energy::Energy(Serial &u, uint8_t &enemy_color):serial(u),ally_color(enemy_color),
|
||||
src_blue(SRC_HEIGHT, SRC_WIDTH, CV_8UC1),
|
||||
src_red(SRC_HEIGHT, SRC_WIDTH, CV_8UC1)
|
||||
{
|
||||
@@ -26,7 +26,7 @@ Energy::Energy(Serial &u, int &ally_color):serial(u),ally_color_(ally_color),
|
||||
target_armor = -1;
|
||||
radius = 0;
|
||||
|
||||
ally_color_ = ALLY_RED;
|
||||
// ally_color = ALLY_RED;
|
||||
energy_part_rotation = CLOCKWISE;
|
||||
attack_distance = ATTACK_DISTANCE;
|
||||
count = 1;
|
||||
@@ -58,11 +58,11 @@ Energy::Energy(Serial &u, int &ally_color):serial(u),ally_color_(ally_color),
|
||||
|
||||
Energy::~Energy() = default;
|
||||
|
||||
|
||||
void Energy::setAllyColor(int color)
|
||||
{
|
||||
ally_color_ = color;
|
||||
}
|
||||
//
|
||||
//void Energy::setAllyColor(int color)
|
||||
//{
|
||||
// ally_color_ = color;
|
||||
//}
|
||||
|
||||
void Energy::setRotation(int rotation){
|
||||
energy_part_rotation = rotation;
|
||||
|
||||
@@ -8,8 +8,9 @@ using std::cout;
|
||||
using std::endl;
|
||||
using std::vector;
|
||||
|
||||
extern float curr_yaw, curr_pitch, mark_yaw, mark_pitch;
|
||||
extern int mark;
|
||||
//extern float curr_yaw, curr_pitch, mark_yaw, mark_pitch;
|
||||
//extern int mark;
|
||||
|
||||
|
||||
int Energy::run(cv::Mat &src){
|
||||
imshow("src",src);
|
||||
@@ -78,11 +79,12 @@ int Energy::run(cv::Mat &src){
|
||||
|
||||
sendTargetByUart(yaw_rotation, pitch_rotation, attack_distance);
|
||||
cout<<"yaw: "<<yaw_rotation<<'\t'<<"pitch: "<<pitch_rotation<<endl;
|
||||
cout<<"curr_yaw: "<<curr_yaw<<'\t'<<"curr_pitch: "<<curr_pitch<<endl;
|
||||
cout<<"mark_yaw: "<<mark_yaw<<'\t'<<"mark_pitch: "<<mark_pitch<<endl;
|
||||
cout<<"curr_yaw: "<<mcuData.curr_yaw<<'\t'<<"curr_pitch: "<<mcuData.curr_pitch<<endl;
|
||||
cout<<"mark_yaw: "<<mcuData.mark_yaw<<'\t'<<"mark_pitch: "<<mcuData.mark_pitch<<endl;
|
||||
|
||||
// cout<<"send_cnt: "<<send_cnt<<endl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user