This commit is contained in:
JiatongSun
2019-05-14 19:19:58 +08:00
4 changed files with 43 additions and 22 deletions

View File

@@ -1,7 +1,7 @@
//
// Created by xinyang on 19-3-27.
//
#define LOG_LEVEL LOG_NONE
//#define LOG_LEVEL LOG_NONE
#include <log.h>
#include <options/options.h>
#include <show_images/show_images.h>
@@ -19,6 +19,7 @@ ArmorFinder::ArmorFinder(EnemyColor color, Uart &u, string paras_folder, const b
}
void ArmorFinder::run(cv::Mat &src) {
static int tracking_cnt = 0;
cv::Mat src_use;
src_use = src.clone();
cv::cvtColor(src_use, src_gray, CV_RGB2GRAY);
@@ -42,12 +43,13 @@ void ArmorFinder::run(cv::Mat &src) {
tracker = TrackerToUse::create();
tracker->init(src_use, armor_box);
state = TRACKING_STATE;
tracking_cnt = 0;
LOGM(STR_CTR(WORD_LIGHT_CYAN, "into track"));
}
}
break;
case TRACKING_STATE:
if(!stateTrackingTarget(src_use)){
if(++tracking_cnt>100 || !stateTrackingTarget(src_use)){
state = SEARCHING_STATE;
LOGM(STR_CTR(WORD_LIGHT_YELLOW ,"into search!"));
}

View File

@@ -117,10 +117,10 @@ static bool findArmorBoxes(LightBlobs &light_blobs, std::vector<cv::Rect2d> &arm
cv::Rect2d rect_left = light_blobs.at(static_cast<unsigned long>(i)).rect.boundingRect();
cv::Rect2d rect_right = light_blobs.at(static_cast<unsigned long>(j)).rect.boundingRect();
double min_x, min_y, max_x, max_y;
min_x = fmin(rect_left.x, rect_right.x);
max_x = fmax(rect_left.x + rect_left.width, rect_right.x + rect_right.width);
min_y = fmin(rect_left.y, rect_right.y) - 3;
max_y = fmax(rect_left.y + rect_left.height, rect_right.y + rect_right.height) + 3;
min_x = fmin(rect_left.x, rect_right.x) - 4;
max_x = fmax(rect_left.x + rect_left.width, rect_right.x + rect_right.width) + 4;
min_y = fmin(rect_left.y, rect_right.y) - 4;
max_y = fmax(rect_left.y + rect_left.height, rect_right.y + rect_right.height) + 4;
if (min_x < 0 || max_x > 640 || min_y < 0 || max_y > 480) {
continue;
}

View File

@@ -30,14 +30,14 @@ int state = ENERGY_STATE;
float curr_yaw = 0, curr_pitch = 0;
float mark_yaw = 0, mark_pitch = 0;
int mark = 0;
bool use_classifier = false;
bool use_classifier = true;
void uartReceive(Uart *uart);
int main(int argc, char *argv[]) {
process_options(argc, argv);
Uart uart;
thread receive(uartReceive, &uart);
// thread receive(uartReceive, &uart);
bool flag = true;
while (flag) {
@@ -53,24 +53,25 @@ 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;
delete video_energy;
cout << "Program fails. Restarting" << endl;
continue;
}
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);
@@ -79,7 +80,7 @@ int main(int argc, char *argv[]) {
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", {

View File

@@ -7,27 +7,45 @@
#include <options/options.h>
#include <log.h>
using std::cout;
using std::cerr;
using std::clog;
using std::dec;
using std::endl;
using std::hex;
using namespace std;
GMAngle_t aim;
string get_uart_dev_name(){
FILE* ls = popen("ls /dev/ttyUSB* --color=never", "r");
char name[20] = {0};
fscanf(ls, "%s", name);
return name;
}
Uart::Uart(){
if(wait_uart){
while((fd = open("/dev/ttyUSB0", O_RDWR)) < 0);
string name;
do{
name = get_uart_dev_name();
if(name == ""){
continue;
}
}while((fd=open(name.data(), O_RDWR)) < 0);
}else{
fd = open("/dev/ttyUSB0", O_RDWR);
string name = get_uart_dev_name();
if(name == ""){
cerr<<"open port error"<<endl;
return;
}
fd = open(name.data(), O_RDWR);
if(fd < 0) {
cerr<<"open port error"<<endl;
return;
}
}
// fd = open("/dev/ttyUSB1", O_RDWR);
// if(fd < 0) {
// cerr<<"open port error"<<endl;
// return;
// }
if(set_opt(fd, 115200, 8, 'N', 1) < 0 )
{
cerr<<"set opt error"<<endl;