Merge branch 'master' into new

This commit is contained in:
xinyang
2019-05-04 14:06:04 +08:00
committed by GitHub
2 changed files with 47 additions and 45 deletions

View File

@@ -27,66 +27,68 @@ using namespace std;
int state = ARMOR_STATE; int state = ARMOR_STATE;
float curr_yaw=0, curr_pitch=0; float curr_yaw = 0, curr_pitch = 0;
float mark_yaw=0, mark_pitch=0; float mark_yaw = 0, mark_pitch = 0;
int mark = 0; int mark = 0;
void uartReceive(Uart* uart); void uartReceive(Uart *uart);
int main(int argc, char *argv[]){ int main(int argc, char *argv[]) {
process_options(argc, argv); process_options(argc, argv);
Uart uart; Uart uart;
thread receive(uartReceive, &uart); thread receive(uartReceive, &uart);
bool flag = true; bool flag = true;
while (flag){ while (flag) {
int ally_color = ALLY_RED; int ally_color = ALLY_RED;
int energy_part_rotation = CLOCKWISE; int energy_part_rotation = CLOCKWISE;
int from_camera = 1; int from_camera = 1;
if(!run_with_camera) { if (!run_with_camera) {
cout << "Input 1 for camera, 0 for video files" << endl; cout << "Input 1 for camera, 0 for video files" << endl;
cin >> from_camera; cin >> from_camera;
} }
WrapperHead *video_armor; WrapperHead *video_armor;
WrapperHead *video_energy; WrapperHead *video_energy;
if(from_camera) { if (from_camera) {
video_armor = new CameraWrapper(0); video_armor = new CameraWrapper(0);
// video_energy = new CameraWrapper(1); video_energy = new CameraWrapper(1);
}else { } else {
video_armor = new VideoWrapper("/home/xinyang/Desktop/Video.mp4"); video_armor = new VideoWrapper("/home/xinyang/Desktop/Video.mp4");
video_energy = new VideoWrapper("/home/xinyang/Desktop/Video.mp4"); video_energy = new VideoWrapper("/home/xinyang/Desktop/Video.mp4");
} }
if (video_armor->init()) { if (video_armor->init()) {
cout << "Video source initialization successfully." << endl; cout << "Video source initialization successfully." << endl;
} }
Mat energy_src, armor_src; Mat energy_src, armor_src;
ArmorFinder armorFinder(ENEMY_BLUE, uart, PROJECT_DIR"/tools/para/");
ArmorFinder armorFinder(ENEMY_BLUE, uart, PROJECT_DIR"/tools/para/");
Energy energy(uart); Energy energy(uart);
energy.setAllyColor(ally_color); energy.setAllyColor(ally_color);
energy.setRotation(energy_part_rotation); energy.setRotation(energy_part_rotation);
bool ok=true; bool ok = true;
while (ok){ while (ok) {
CNT_TIME(WORD_LIGHT_CYAN, "Total", { CNT_TIME(WORD_LIGHT_CYAN, "Total", {
ok = video_armor->read(energy_src) && video_armor->read(armor_src);
if (show_origin) {
imshow("enery src", energy_src);
imshow("armor src", armor_src);
}
if (state == ENERGY_STATE) { if (state == ENERGY_STATE) {
ok = video_energy->read(energy_src);
if (show_origin) {
imshow("energy src", energy_src);
}
if (from_camera == 0) { if (from_camera == 0) {
energy.extract(energy_src); energy.extract(energy_src);
} }
energy.run(energy_src); energy.run(energy_src);
} else { } else {
ok = video_armor->read(armor_src);
if (show_origin) {
imshow("armor src", armor_src);
}
CNT_TIME(WORD_LIGHT_BLUE, "Armor Time", { CNT_TIME(WORD_LIGHT_BLUE, "Armor Time", {
armorFinder.run(armor_src); armorFinder.run(armor_src);
}); });
} }
if (waitKey(1) == 'q') { if (waitKey(1) == 'q') {
@@ -94,41 +96,41 @@ int main(int argc, char *argv[]){
break; break;
} }
}); });
} }
delete video_armor; delete video_armor;
cout << "Program fails. Restarting" << endl; cout << "Program fails. Restarting" << endl;
} }
return 0; return 0;
} }
#define RECEIVE_LOG_LEVEL LOG_NOTHING #define RECEIVE_LOG_LEVEL LOG_NOTHING
void uartReceive(Uart* uart){ void uartReceive(Uart *uart) {
char buffer[100]; char buffer[100];
int cnt=0; int cnt = 0;
while(true){ while (true) {
char data; char data;
while((data=uart->receive()) != '\n'){ while ((data = uart->receive()) != '\n') {
buffer[cnt++] = data; buffer[cnt++] = data;
if(cnt >= 100){ if (cnt >= 100) {
LOG(RECEIVE_LOG_LEVEL, "data receive over flow!"); LOG(RECEIVE_LOG_LEVEL, "data receive over flow!");
cnt = 0; cnt = 0;
} }
} }
if(cnt == 10){ if (cnt == 10) {
if(buffer[8] == 'e'){ if (buffer[8] == 'e') {
state = ENERGY_STATE; state = ENERGY_STATE;
LOG(RECEIVE_LOG_LEVEL, "Energy state"); LOG(RECEIVE_LOG_LEVEL, "Energy state");
}else if(buffer[8] == 'a'){ } else if (buffer[8] == 'a') {
state = ARMOR_STATE; state = ARMOR_STATE;
LOG(RECEIVE_LOG_LEVEL, "Armor state"); LOG(RECEIVE_LOG_LEVEL, "Armor state");
} }
memcpy(&curr_yaw, buffer, 4); memcpy(&curr_yaw, buffer, 4);
memcpy(&curr_pitch, buffer+4, 4); memcpy(&curr_pitch, buffer + 4, 4);
LOG(RECEIVE_LOG_LEVEL, "Get yaw:%f pitch:%f", curr_yaw, curr_pitch); LOG(RECEIVE_LOG_LEVEL, "Get yaw:%f pitch:%f", curr_yaw, curr_pitch);
if(buffer[9] == 1){ if (buffer[9] == 1) {
if(mark == 0){ if (mark == 0) {
mark = 1; mark = 1;
mark_yaw = curr_yaw; mark_yaw = curr_yaw;
mark_pitch = curr_pitch; mark_pitch = curr_pitch;

View File

@@ -41,7 +41,7 @@ CONV2_OUTPUT_CHANNELS = 10
FC1_OUTPUT_NODES = 16 FC1_OUTPUT_NODES = 16
# 第二层全连接宽度(输出标签类型数) # 第二层全连接宽度(输出标签类型数)
FC2_OUTPUT_NODES = 6 FC2_OUTPUT_NODES = 8
# 输出标签类型数 # 输出标签类型数
OUTPUT_NODES = FC2_OUTPUT_NODES OUTPUT_NODES = FC2_OUTPUT_NODES