Merge remote-tracking branch 'origin/master'

This commit is contained in:
xinyang
2019-08-05 16:27:53 +08:00
6 changed files with 120 additions and 70 deletions

View File

@@ -51,11 +51,11 @@ extern std::map<string, int> prior_red;
class LightBlob { class LightBlob {
public: public:
cv::RotatedRect rect; //灯条位置 cv::RotatedRect rect; //灯条位置
double areaRatio; double area_ratio;
double length; //灯条长度 double length; //灯条长度
uint8_t blob_color; //灯条颜色 uint8_t blob_color; //灯条颜色
LightBlob(cv::RotatedRect &r, double ratio, uint8_t color) : rect(r), areaRatio(ratio), blob_color(color) { LightBlob(cv::RotatedRect &r, double ratio, uint8_t color) : rect(r), area_ratio(ratio), blob_color(color) {
length = max(rect.size.height, rect.size.width); length = max(rect.size.height, rect.size.width);
}; };
LightBlob() = default; LightBlob() = default;

View File

@@ -173,7 +173,7 @@ bool ArmorFinder::findLightBlobs(const cv::Mat &src, LightBlobs &light_blobs) {
for (int l = 0; l != light_blobs_light.size(); l++) { for (int l = 0; l != light_blobs_light.size(); l++) {
for (int d = 0; d != light_blobs_dim.size(); d++) { for (int d = 0; d != light_blobs_dim.size(); d++) {
if (isSameBlob(light_blobs_light[l], light_blobs_dim[d])) { if (isSameBlob(light_blobs_light[l], light_blobs_dim[d])) {
if (light_blobs_light[l].areaRatio > light_blobs_dim[d].areaRatio) { if (light_blobs_light[l].area_ratio > light_blobs_dim[d].area_ratio) {
dim_to_remove.emplace_back(d); dim_to_remove.emplace_back(d);
} else { } else {
light_to_remove.emplace_back(l); light_to_remove.emplace_back(l);

View File

@@ -44,14 +44,14 @@ WrapperHead *video_chassis = nullptr; // 底盘摄像头视频源
Serial serial(115200); // 串口对象 Serial serial(115200); // 串口对象
uint8_t last_state = INIT_STATE; // 上次状态,用于初始化 uint8_t last_state = INIT_STATE; // 上次状态,用于初始化
// 自瞄主程序对象 // 自瞄主程序对象
ArmorFinder armorFinder(mcu_data.enemy_color, serial, PROJECT_DIR"/tools/para/", mcu_data.use_classifier); ArmorFinder armor_finder(mcu_data.enemy_color, serial, PROJECT_DIR"/tools/para/", mcu_data.use_classifier);
// 能量机关主程序对象 // 能量机关主程序对象
Energy energy(serial, mcu_data.enemy_color); Energy energy(serial, mcu_data.enemy_color);
int box_distance = 0; int box_distance = 0;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
process_options(argc, argv); // 处理命令行参数 processOptions(argc, argv); // 处理命令行参数
thread receive(uartReceive, &serial); // 开启串口接收线程 thread receive(uartReceive, &serial); // 开启串口接收线程
int from_camera = 1; // 根据条件选择视频源 int from_camera = 1; // 根据条件选择视频源
@@ -175,7 +175,7 @@ int main(int argc, char *argv[]) {
if (show_origin) showOrigin(gimbal_src); if (show_origin) showOrigin(gimbal_src);
// }); // });
CNT_TIME(STR_CTR(WORD_CYAN, "Armor Time"), { CNT_TIME(STR_CTR(WORD_CYAN, "Armor Time"), {
armorFinder.run(gimbal_src); armor_finder.run(gimbal_src);
}); });
} }
// cv::waitKey(0); // cv::waitKey(0);

View File

@@ -5,7 +5,11 @@
#ifndef _OPTIONS_H_ #ifndef _OPTIONS_H_
#define _OPTIONS_H_ #define _OPTIONS_H_
#define PROJECT_DIR PATH #ifdef PATH
#define PROJECT_DIR PATH
#else
#define PROJECT_DIR ""
#endif
extern bool show_armor_box; extern bool show_armor_box;
extern bool show_armor_boxes; extern bool show_armor_boxes;
@@ -20,6 +24,6 @@ extern bool show_energy;
extern bool save_mark; extern bool save_mark;
extern bool show_info; extern bool show_info;
void process_options(int argc, char *argv[]); void processOptions(int argc, char **argv);
#endif /* _OPTIONS_H_ */ #endif /* _OPTIONS_H_ */

View File

@@ -26,7 +26,7 @@ extern WrapperHead *video_chassis;
extern Serial serial; extern Serial serial;
extern uint8_t last_state; extern uint8_t last_state;
extern ArmorFinder armorFinder; extern ArmorFinder armor_finder;
extern Energy energy; extern Energy energy;
void uartReceive(Serial *pSerial) { void uartReceive(Serial *pSerial) {

View File

@@ -5,6 +5,7 @@
#include <options.h> #include <options.h>
#include <log.h> #include <log.h>
#include <cstring> #include <cstring>
#include <map>
bool show_armor_box = false; bool show_armor_box = false;
bool show_armor_boxes = false; bool show_armor_boxes = false;
@@ -19,70 +20,115 @@ bool show_energy = false;
bool save_mark = false; bool save_mark = false;
bool show_info = false; bool show_info = false;
void process_options(int argc, char *argv[]) { // 使用map保存所有选项及其描述和操作加快查找速度。
std::map<std::string, std::pair<std::string, void(*)(void)>> options = {
{"--help",{
"show the help information.", [](){
LOG(LOG_MSG, "<HELP>: " STR_CTR(WORD_BLUE, "All options below are for debug use."));
for(const auto &option : options){
LOG(LOG_MSG, "<HELP>: " STR_CTR(WORD_GREEN, "%s: %s"), option.first.data(), option.second.first.data());
}
}
}},
{"--show-armor-box", {
"show the aim box.", []() {
show_armor_box = true;
LOGM("Enable show armor box");
}
}},
{"--show-armor-boxes",{
"show the candidate aim boxes.", [](){
show_armor_boxes = true;
LOGM("Enable show armor boxes");
}
}},
{"--show-light-blobs",{
"show the candidate light blobs.", [](){
show_light_blobs = true;
LOGM("Enable show light blobs");
}
}},
{"--show-origin", {
"show the origin image.", [](){
show_origin = true;
LOGM("Enable show origin");
}
}},
{"--run-with-camera", {
"start the program with camera directly without asking.", []() {
run_with_camera = true;
LOGM("Run with camera!");
}
}},
{"--save-video", {
"save the video.", [](){
save_video = true;
LOGM("Enable save video!");
}
}},
{"--save-labelled-boxes",{
"save the candidate boxes with their id labels.", [](){
save_labelled_boxes = true;
LOGM("labelled armor boxes will be saved!");
}
}},
{"--wait-uart", {
"wait uart until ready before running.", [](){
wait_uart = true;
LOGM("Enable wait uart!");
}
}},
{"--show-process", {
"", [](){
show_process = true;
LOGM("Enable show processed image!");
}
}},
{"--show-energy", {
"",[](){
show_energy = true;
LOGM("Enable show energy part!");
}
}},
{"--save-mark", {
"", [](){
save_mark = true;
LOGM("Write down mark");
}
}},
{"--show-info", {
"", [](){
show_info = true;
LOGM("Show information!");
}
}},
{"--show-all", {
"show all image windows.", [](){
show_armor_box = true;
LOGM("Enable show armor box");
show_armor_boxes = true;
LOGM("Enable show armor boxes");
show_light_blobs = true;
LOGM("Enable show light blobs");
show_origin = true;
LOGM("Enable show origin");
show_process = true;
LOGM("Enable show processed image");
show_energy = true;
LOGM("Enable show energy part");
}
}}
};
void processOptions(int argc, char **argv) {
if (argc >= 2) { if (argc >= 2) {
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--help") == 0) { auto key = options.find(std::string(argv[i])); // 寻找对应选项。
LOGM("--show-armor-box: show the aim box."); if(key != options.end()){
LOGM("--show-armor-boxes: show the candidate aim boxes."); key->second.second();
LOGM("--show-light-blobs: show the candidate light blobs."); }else{
LOGM("--show-origin: show the origin image.");
LOGM("--run-with-camera: start the program with camera directly without asking.");
LOGM("--save-video: save the video.");
LOGM("--save-labelled-boxes: save labelled armor boxes.");
} else if (strcmp(argv[i], "--show-armor-box") == 0) {
show_armor_box = true;
LOGM("Enable show armor box");
} else if (strcmp(argv[i], "--show-armor-boxes") == 0) {
show_armor_boxes = true;
LOGM("Enable show armor boxes");
} else if (strcmp(argv[i], "--show-light-blobs") == 0) {
show_light_blobs = true;
LOGM("Enable show light blobs");
} else if (strcmp(argv[i], "--show-origin") == 0) {
show_origin = true;
LOGM("Enable show origin");
} else if (strcmp(argv[i], "--show-all") == 0) {
show_armor_box = true;
LOGM("Enable show armor box");
show_armor_boxes = true;
LOGM("Enable show armor boxes");
show_light_blobs = true;
LOGM("Enable show light blobs");
show_origin = true;
LOGM("Enable show origin");
show_process = true;
LOGM("Enable show processed image");
show_energy = true;
LOGM("Enable show energy part");
} else if (strcmp(argv[i], "--run-with-camera") == 0) {
run_with_camera = true;
LOGM("Run with camera!");
} else if (strcmp(argv[i], "--save-video") == 0) {
save_video = true;
LOGM("Save video!");
} else if (strcmp(argv[i], "--wait-uart") == 0) {
wait_uart = true;
LOGM("Wait uart until available!");
} else if (strcmp(argv[i], "--save-labelled-boxes") == 0) {
save_labelled_boxes = true;
LOGM("labelled armor boxes will be saved!");
} else if (strcmp(argv[i], "--show-process") == 0) {
show_process = true;
LOGM("Enable show processed image!");
} else if (strcmp(argv[i], "--show-energy") == 0) {
show_energy = true;
LOGM("Enable show energy part!");
} else if (strcmp(argv[i], "--save-mark") == 0) {
save_mark = true;
LOGM("Write down mark");
} else if (strcmp(argv[i], "--show-info") == 0) {
show_info = true;
LOGM("Show information!");
} else {
LOGW("Unknown option: %s. Use --help to see options.", argv[i]); LOGW("Unknown option: %s. Use --help to see options.", argv[i]);
} }
} }
} }
} }