更新监视脚本绑定方式。
This commit is contained in:
@@ -57,7 +57,7 @@ void ArmorFinder::run(cv::Mat &src) {
|
||||
}
|
||||
}
|
||||
|
||||
#define FOCUS_PIXAL (0.36/0.48*640)
|
||||
#define FOCUS_PIXAL (800)
|
||||
|
||||
bool ArmorFinder::sendBoxPosition() {
|
||||
static int dx_add = 0;
|
||||
@@ -68,6 +68,7 @@ bool ArmorFinder::sendBoxPosition() {
|
||||
double dy = rect.y + rect.height/2 - 240 - 30;
|
||||
double yaw = atan(dx / FOCUS_PIXAL) * 180 / 3.14159265459;
|
||||
double pitch = atan(dy / FOCUS_PIXAL) * 180 / 3.14159265459;
|
||||
cout << yaw << endl;
|
||||
uart.sendTarget(yaw, -pitch, 0);
|
||||
return true;
|
||||
}
|
||||
49
main.cpp
49
main.cpp
@@ -15,7 +15,7 @@
|
||||
#include <options/options.h>
|
||||
#include <thread>
|
||||
|
||||
//#define DO_NOT_CNT_TIME
|
||||
#define DO_NOT_CNT_TIME
|
||||
#include <log.h>
|
||||
|
||||
#define PROJECT_DIR PATH
|
||||
@@ -26,7 +26,7 @@ using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
|
||||
int state = ENERGY_STATE;
|
||||
int state = ARMOR_STATE;
|
||||
float curr_yaw = 0, curr_pitch = 0;
|
||||
float mark_yaw = 0, mark_pitch = 0;
|
||||
int mark = 0;
|
||||
@@ -36,7 +36,7 @@ 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) {
|
||||
@@ -52,18 +52,17 @@ int main(int argc, char *argv[]){
|
||||
WrapperHead *video_armor;
|
||||
WrapperHead *video_energy;
|
||||
if (from_camera) {
|
||||
// video_armor = new CameraWrapper(0);
|
||||
video_energy = new CameraWrapper(1);
|
||||
video_armor = new CameraWrapper(0);
|
||||
// video_energy = new CameraWrapper(1, "energy");
|
||||
} else {
|
||||
video_armor = new VideoWrapper("r_l_640.avi");
|
||||
video_energy = new VideoWrapper("r_l_640.avi");
|
||||
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_energy->init()) {
|
||||
if (video_armor->init()) {
|
||||
cout << "Video source initialization successfully." << endl;
|
||||
}
|
||||
|
||||
Mat energy_src, armor_src;
|
||||
|
||||
ArmorFinder armorFinder(ENEMY_BLUE, uart, PROJECT_DIR"/tools/para/");
|
||||
|
||||
Energy energy(uart);
|
||||
@@ -73,37 +72,39 @@ int main(int argc, char *argv[]){
|
||||
bool ok = true;
|
||||
|
||||
while (ok) {
|
||||
// CNT_TIME(WORD_LIGHT_CYAN, "Total", {
|
||||
// ok = video_energy->read(energy_src) && video_energy->read(armor_src);
|
||||
CNT_TIME(WORD_LIGHT_CYAN, "Total", {
|
||||
if (state == ENERGY_STATE) {
|
||||
ok = video_energy->read(energy_src);
|
||||
if (show_origin) {
|
||||
imshow("enery src", energy_src);
|
||||
imshow("armor src", armor_src);
|
||||
imshow("energy src", energy_src);
|
||||
}
|
||||
if (state == ENERGY_STATE) {
|
||||
if (from_camera == 0) {
|
||||
energy.extract(energy_src);
|
||||
}
|
||||
energy.run(energy_src);
|
||||
} else {
|
||||
// CNT_TIME(WORD_LIGHT_BLUE, "Armor Time", {
|
||||
// armorFinder.run(armor_src);
|
||||
// });
|
||||
ok = video_armor->read(armor_src);
|
||||
if (show_origin) {
|
||||
imshow("armor src", armor_src);
|
||||
}
|
||||
CNT_TIME(WORD_LIGHT_BLUE, "Armor Time", {
|
||||
armorFinder.run(armor_src);
|
||||
});
|
||||
}
|
||||
if (waitKey(1) == 'q') {
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
// });
|
||||
});
|
||||
}
|
||||
delete video_energy;
|
||||
delete video_armor;
|
||||
cout << "Program fails. Restarting" << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define RECEIVE_LOG_LEVEL LOG_MSG
|
||||
#define RECEIVE_LOG_LEVEL LOG_NOTHING
|
||||
|
||||
void uartReceive(Uart *uart) {
|
||||
char buffer[100];
|
||||
@@ -120,21 +121,21 @@ void uartReceive(Uart* uart){
|
||||
if (cnt == 10) {
|
||||
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");
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "$1/tools/monitor.sh \"$2/run --run-with-camera\" &" > $2/monitor-run
|
||||
echo "#!/bin/bash" > $2/monitor-run
|
||||
echo "$1/tools/monitor.sh \"$2/run --run-with-camera\"" >> $2/monitor-run
|
||||
chmod +x $2/monitor-run
|
||||
|
||||
Reference in New Issue
Block a user