更新通信协议。
This commit is contained in:
@@ -16,7 +16,7 @@ typedef enum{
|
|||||||
|
|
||||||
class ArmorFinder{
|
class ArmorFinder{
|
||||||
public:
|
public:
|
||||||
ArmorFinder(EnemyColor color, Uart &u, string paras_folder);
|
ArmorFinder(EnemyColor color, Uart &u, string paras_folder, const bool &use);
|
||||||
~ArmorFinder() = default;
|
~ArmorFinder() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -36,6 +36,7 @@ private:
|
|||||||
|
|
||||||
int contour_area;
|
int contour_area;
|
||||||
Uart &uart;
|
Uart &uart;
|
||||||
|
const bool &use_classifier;
|
||||||
|
|
||||||
bool stateSearchingTarget(cv::Mat &src);
|
bool stateSearchingTarget(cv::Mat &src);
|
||||||
bool stateTrackingTarget(cv::Mat &src);
|
bool stateTrackingTarget(cv::Mat &src);
|
||||||
|
|||||||
@@ -8,12 +8,13 @@
|
|||||||
#include <opencv2/highgui.hpp>
|
#include <opencv2/highgui.hpp>
|
||||||
#include <armor_finder/armor_finder.h>
|
#include <armor_finder/armor_finder.h>
|
||||||
|
|
||||||
ArmorFinder::ArmorFinder(EnemyColor color, Uart &u, string paras_folder) :
|
ArmorFinder::ArmorFinder(EnemyColor color, Uart &u, string paras_folder, const bool &use) :
|
||||||
uart(u),
|
uart(u),
|
||||||
enemy_color(color),
|
enemy_color(color),
|
||||||
state(STANDBY_STATE),
|
state(STANDBY_STATE),
|
||||||
classifier(std::move(paras_folder)),
|
classifier(std::move(paras_folder)),
|
||||||
contour_area(0)
|
contour_area(0),
|
||||||
|
use_classifier(use)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ void ArmorFinder::run(cv::Mat &src) {
|
|||||||
case SEARCHING_STATE:
|
case SEARCHING_STATE:
|
||||||
if(stateSearchingTarget(src_use)){
|
if(stateSearchingTarget(src_use)){
|
||||||
if((armor_box & cv::Rect2d(0, 0, 640, 480)) == armor_box) {
|
if((armor_box & cv::Rect2d(0, 0, 640, 480)) == armor_box) {
|
||||||
if(!classifier){
|
if(!classifier && use_classifier){
|
||||||
cv::Mat roi = src_use.clone()(armor_box), roi_gray;
|
cv::Mat roi = src_use.clone()(armor_box), roi_gray;
|
||||||
cv::cvtColor(roi, roi_gray, CV_RGB2GRAY);
|
cv::cvtColor(roi, roi_gray, CV_RGB2GRAY);
|
||||||
cv::threshold(roi_gray, roi_gray, 180, 255, cv::THRESH_BINARY);
|
cv::threshold(roi_gray, roi_gray, 180, 255, cv::THRESH_BINARY);
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ bool ArmorFinder::stateSearchingTarget(cv::Mat &src) {
|
|||||||
showArmorBoxVector("boxes", split, armor_boxes);
|
showArmorBoxVector("boxes", split, armor_boxes);
|
||||||
cv::waitKey(1);
|
cv::waitKey(1);
|
||||||
}
|
}
|
||||||
if(classifier){
|
if(classifier && use_classifier){
|
||||||
for(auto box : armor_boxes){
|
for(auto box : armor_boxes){
|
||||||
cv::Mat roi = src(box).clone();
|
cv::Mat roi = src(box).clone();
|
||||||
cv::resize(roi, roi, cv::Size(48, 36));
|
cv::resize(roi, roi, cv::Size(48, 36));
|
||||||
|
|||||||
14
main.cpp
14
main.cpp
@@ -30,6 +30,7 @@ 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;
|
||||||
|
bool use_classifier = false;
|
||||||
|
|
||||||
void uartReceive(Uart *uart);
|
void uartReceive(Uart *uart);
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ int main(int argc, char *argv[]) {
|
|||||||
// video_energy->read(armor_src);
|
// video_energy->read(armor_src);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArmorFinder armorFinder(ENEMY_BLUE, uart, PROJECT_DIR"/tools/para/");
|
ArmorFinder armorFinder(ENEMY_BLUE, uart, PROJECT_DIR"/tools/para/", use_classifier);
|
||||||
|
|
||||||
Energy energy(uart);
|
Energy energy(uart);
|
||||||
energy.setAllyColor(ally_color);
|
energy.setAllyColor(ally_color);
|
||||||
@@ -114,6 +115,7 @@ int main(int argc, char *argv[]) {
|
|||||||
void uartReceive(Uart *uart) {
|
void uartReceive(Uart *uart) {
|
||||||
char buffer[100];
|
char buffer[100];
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
|
LOGM("data receive start!");
|
||||||
while (true) {
|
while (true) {
|
||||||
char data;
|
char data;
|
||||||
while ((data = uart->receive()) != '\n') {
|
while ((data = uart->receive()) != '\n') {
|
||||||
@@ -123,7 +125,8 @@ void uartReceive(Uart *uart) {
|
|||||||
cnt = 0;
|
cnt = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cnt == 10) {
|
// LOGM("%d", cnt);
|
||||||
|
if (cnt == 11) {
|
||||||
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");
|
||||||
@@ -131,6 +134,13 @@ void uartReceive(Uart *uart) {
|
|||||||
state = ARMOR_STATE;
|
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!");
|
||||||
|
} else if(buffer[10] == 1){
|
||||||
|
use_classifier = true;
|
||||||
|
LOG(RECEIVE_LOG_LEVEL, "Classifier on!");
|
||||||
|
}
|
||||||
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);
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ stop:
|
|||||||
CameraGetExposureTime(h_camera, &t);
|
CameraGetExposureTime(h_camera, &t);
|
||||||
LOGM("Exposure time: %lfms", t/1000.0);
|
LOGM("Exposure time: %lfms", t/1000.0);
|
||||||
// 模拟增益4
|
// 模拟增益4
|
||||||
CameraSetAnalogGain(h_camera, 60);
|
CameraSetAnalogGain(h_camera, 63);
|
||||||
// 使用预设LUT表
|
// 使用预设LUT表
|
||||||
CameraSetLutMode(h_camera, LUTMODE_PRESET);
|
CameraSetLutMode(h_camera, LUTMODE_PRESET);
|
||||||
// 抗频闪
|
// 抗频闪
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
echo "#!/bin/bash" > $2/monitor-run
|
echo "#!/bin/bash" > $2/monitor-run
|
||||||
echo "$1/tools/monitor.sh \"$2/run --run-with-camera\"" >> $2/monitor-run
|
echo "$1/tools/monitor.sh \"$2/run --run-with-camera --show-armor-box\"" >> $2/monitor-run
|
||||||
chmod +x $2/monitor-run
|
chmod +x $2/monitor-run
|
||||||
|
|||||||
Reference in New Issue
Block a user