win32 ver

This commit is contained in:
xinyang
2019-05-14 20:03:03 +08:00
parent 601bf2a510
commit 6980145e83
28 changed files with 13037 additions and 395 deletions

View File

@@ -5,7 +5,7 @@
#include <opencv2/core/core.hpp>
#include <energy/energy.h>
#include <uart/uart.h>
#include <serial/serial.h>
#include <energy/param_struct_define.h>
#include <energy/constant.h>
#include <camera/camera_wrapper.h>
@@ -18,7 +18,6 @@
#define DO_NOT_CNT_TIME
#include <log.h>
#define PROJECT_DIR PATH
#define ENERGY_STATE 1
#define ARMOR_STATE 0
@@ -30,18 +29,20 @@ int state = ENERGY_STATE;
float curr_yaw = 0, curr_pitch = 0;
float mark_yaw = 0, mark_pitch = 0;
int mark = 0;
EnemyColor enemy_color = ENEMY_BLUE;
int ally_color = ALLY_RED;
bool use_classifier = true;
void uartReceive(Uart *uart);
void uartReceive(Serial *uart);
int main(int argc, char *argv[]) {
process_options(argc, argv);
Uart uart;
// thread receive(uartReceive, &uart);
Serial uart(3, 115200);
thread receive(uartReceive, &uart);
bool flag = true;
while (flag) {
int ally_color = ALLY_RED;
int energy_part_rotation = CLOCKWISE;
int from_camera = 1;
@@ -53,13 +54,13 @@ int main(int argc, char *argv[]) {
WrapperHead *video_armor;
WrapperHead *video_energy;
if (from_camera) {
video_armor = new CameraWrapper(0/*, "armor"*/);
// video_energy = new CameraWrapper(1, "energy");
video_armor = new CameraWrapper(0, "armor");
video_energy = new CameraWrapper(1, "energy");
} else {
video_armor = new VideoWrapper("/home/xinyang/Desktop/DataSets/video/blue_4.mp4");
video_energy = new VideoWrapper("/home/xinyang/Desktop/DataSets/video/blue_4.mp4");
}
if (video_armor->init()/* && video_energy->init()*/) {
if (video_armor->init() && video_energy->init()) {
cout << "Video source initialization successfully." << endl;
} else {
delete video_armor;
@@ -71,19 +72,19 @@ int main(int argc, char *argv[]) {
Mat energy_src, armor_src;
for(int i=0; i<10; i++){
video_armor->read(armor_src);
// video_energy->read(armor_src);
video_energy->read(armor_src);
}
ArmorFinder armorFinder(ENEMY_BLUE, uart, PROJECT_DIR"/tools/para/", use_classifier);
ArmorFinder armorFinder(enemy_color, uart, PROJECT_DIR"/tools/para/", use_classifier);
Energy energy(uart);
energy.setAllyColor(ally_color);
Energy energy(uart, ally_color);
// energy.setAllyColor(ally_color);
energy.setRotation(energy_part_rotation);
bool ok = video_armor->read(armor_src)/* && video_energy->read(armor_src)*/;
bool ok = video_armor->read(armor_src) && video_energy->read(armor_src);
while (ok) {
CNT_TIME(WORD_LIGHT_CYAN, "Total", {
CNT_TIME("Total", {
if (state == ENERGY_STATE) {
ok = video_energy->read(energy_src);
if (show_origin) {
@@ -95,10 +96,11 @@ int main(int argc, char *argv[]) {
energy.run(energy_src);
} else {
ok = video_armor->read(armor_src);
flip(armor_src, armor_src, 0);
if (show_origin) {
imshow("armor src", armor_src);
}
CNT_TIME(WORD_LIGHT_BLUE, "Armor Time", {
CNT_TIME("Armor Time", {
armorFinder.run(armor_src);
});
}
@@ -116,47 +118,65 @@ int main(int argc, char *argv[]) {
return 0;
}
#define RECEIVE_LOG_LEVEL LOG_MSG
#define RECEIVE_LOG_LEVEL LOG_NOTHING
void uartReceive(Uart *uart) {
char uartReadByte(Serial &uart) {
while (uart.GetBytesInCOM() == 0);
char byte;
if (uart.ReadData((uint8_t*)& byte, 1) == false) {
LOGE("serial error!");
}
return byte;
}
void uartReceive(Serial* uart) {
char buffer[100];
int cnt = 0;
LOGM("data receive start!");
while (true) {
char data;
while ((data = uart->receive()) != '\n') {
while ((data = uartReadByte(*uart)) != '\n') {
buffer[cnt++] = data;
if (cnt >= 100) {
// LOG(RECEIVE_LOG_LEVEL, "data receive over flow!");
LOG(RECEIVE_LOG_LEVEL, "data receive over flow!");
cnt = 0;
}
}
// LOGM("%d", cnt);
if (cnt == 11) {
LOGM("%d", cnt);
if (cnt == 12) {
if (buffer[8] == 'e') {
state = ENERGY_STATE;
// LOG(RECEIVE_LOG_LEVEL, "Energy state");
LOG(RECEIVE_LOG_LEVEL, "Energy state");
} else if (buffer[8] == 'a') {
state = ARMOR_STATE;
// LOG(RECEIVE_LOG_LEVEL, "Armor state");
LOG(RECEIVE_LOG_LEVEL, "Armor state");
}
if (buffer[10] == 0){
use_classifier = false;
// LOG(RECEIVE_LOG_LEVEL, "Classifier off!");
LOG(RECEIVE_LOG_LEVEL, "Classifier off!");
} else if(buffer[10] == 1){
use_classifier = true;
// LOG(RECEIVE_LOG_LEVEL, "Classifier on!");
LOG(RECEIVE_LOG_LEVEL, "Classifier on!");
}
if (buffer[11] == ENEMY_BLUE) {
LOG(RECEIVE_LOG_LEVEL, "ENEMY_BLUE!");
ally_color = ALLY_RED;
enemy_color = ENEMY_BLUE;
} else if (buffer[11] == ENEMY_RED) {
LOG(RECEIVE_LOG_LEVEL, "ENEMY_RED!");
ally_color = ALLY_BLUE;
enemy_color = ENEMY_RED;
}
memcpy(&curr_yaw, buffer, 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 (mark == 0) {
mark = 1;
mark_yaw = curr_yaw;
mark_pitch = curr_pitch;
}
// LOG(RECEIVE_LOG_LEVEL, "Marked");
LOG(RECEIVE_LOG_LEVEL, "Marked");
}
}
cnt = 0;