Merge remote-tracking branch 'origin/master'

This commit is contained in:
JiatongSun
2019-05-06 21:13:13 +08:00
20 changed files with 20105 additions and 12428 deletions

View File

@@ -13,8 +13,7 @@
void showArmorBoxVector(std::string windows_name, const cv::Mat &src, const std::vector<cv::Rect2d> &armor_box); void showArmorBoxVector(std::string windows_name, const cv::Mat &src, const std::vector<cv::Rect2d> &armor_box);
void showArmorBox(std::string windows_name, const cv::Mat &src, cv::Rect2d armor_box); void showArmorBox(std::string windows_name, const cv::Mat &src, cv::Rect2d armor_box);
void showContours(std::string windows_name, const cv::Mat &src, const std::vector<LightBlob> &light_blobs); void showContours(std::string windows_name, const cv::Mat &src, const std::vector<LightBlob> &light_blobs);
void showArmorBoxClass(std::string window_names, const cv::Mat &src, vector<cv::Rect2d> boxes_one, void showArmorBoxClass(std::string window_names, const cv::Mat &src, vector<cv::Rect2d> boxes[10]);
vector<cv::Rect2d> boxes_two, vector<cv::Rect2d> boxes_three);
#endif /* _SHOW_IMAGES_H_ */ #endif /* _SHOW_IMAGES_H_ */

View File

@@ -1,6 +1,7 @@
// //
// Created by xinyang on 19-3-27. // Created by xinyang on 19-3-27.
// //
#define LOG_LEVEL LOG_NONE
#include <log.h> #include <log.h>
#include <options/options.h> #include <options/options.h>
#include <show_images/show_images.h> #include <show_images/show_images.h>
@@ -40,14 +41,14 @@ void ArmorFinder::run(cv::Mat &src) {
tracker = TrackerToUse::create(); tracker = TrackerToUse::create();
tracker->init(src_use, armor_box); tracker->init(src_use, armor_box);
state = TRACKING_STATE; state = TRACKING_STATE;
LOGW("into track"); LOGM(STR_CTR(WORD_LIGHT_CYAN, "into track"));
} }
} }
break; break;
case TRACKING_STATE: case TRACKING_STATE:
if(!stateTrackingTarget(src_use)){ if(!stateTrackingTarget(src_use)){
state = SEARCHING_STATE; state = SEARCHING_STATE;
//std::cout << "into search!" << std::endl; LOGM(STR_CTR(WORD_LIGHT_YELLOW ,"into search!"));
} }
break; break;
case STANDBY_STATE: case STANDBY_STATE:
@@ -59,11 +60,14 @@ void ArmorFinder::run(cv::Mat &src) {
#define FOCUS_PIXAL (0.36/0.48*640) #define FOCUS_PIXAL (0.36/0.48*640)
bool ArmorFinder::sendBoxPosition() { bool ArmorFinder::sendBoxPosition() {
static int dx_add = 0;
auto rect = armor_box; auto rect = armor_box;
double dx = rect.x + rect.width/2 - 320; double dx = rect.x + rect.width/2 - 320 - 8;
double dy = rect.y + rect.height/2 - 240; dx_add += dx;
dx = dx + dx_add * 0;
double dy = rect.y + rect.height/2 - 240 - 30;
double yaw = atan(dx / FOCUS_PIXAL) * 180 / 3.14159265459; double yaw = atan(dx / FOCUS_PIXAL) * 180 / 3.14159265459;
double pitch = atan(dy / FOCUS_PIXAL) * 180 / 3.14159265459; double pitch = atan(dy / FOCUS_PIXAL) * 180 / 3.14159265459;
uart.sendTarget(yaw, pitch, 0); uart.sendTarget(yaw, -pitch, 0);
return true; return true;
} }

View File

@@ -92,7 +92,7 @@ MatrixXd Classifier::softmax(const MatrixXd &input){
return tmp.array().exp() / tmp.array().exp().sum(); return tmp.array().exp() / tmp.array().exp().sum();
} }
vector<vector<MatrixXd>> max_pool(const vector<vector<MatrixXd>> &input, int size){ vector<vector<MatrixXd>> Classifier::max_pool(const vector<vector<MatrixXd>> &input, int size){
vector<vector<MatrixXd>> output; vector<vector<MatrixXd>> output;
for(int sample=0; sample<input.size(); sample++) { for(int sample=0; sample<input.size(); sample++) {
vector<MatrixXd> sub; vector<MatrixXd> sub;

View File

@@ -31,10 +31,15 @@ static void pipelineLightBlobPreprocess(cv::Mat &src) {
} }
static bool findLightBlobs(const cv::Mat &src, LightBlobs &light_blobs) { static bool findLightBlobs(const cv::Mat &src, LightBlobs &light_blobs) {
// static cv::Mat src_bin; static cv::Mat src_gray, src_bin;
if(src.type() == CV_8UC3){
cvtColor(src, src_gray, CV_BGR2GRAY);
}else if(src.type() == CV_8UC1){
src_gray = src.clone();
}
std::vector<std::vector<cv::Point> > light_contours; std::vector<std::vector<cv::Point> > light_contours;
cv::findContours(src, light_contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); cv::findContours(src_gray, light_contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
for (auto &light_contour : light_contours) { for (auto &light_contour : light_contours) {
cv::RotatedRect rect = cv::minAreaRect(light_contour); cv::RotatedRect rect = cv::minAreaRect(light_contour);
if(isValidLightBlob(rect)){ if(isValidLightBlob(rect)){
@@ -114,8 +119,8 @@ static bool findArmorBoxes(LightBlobs &light_blobs, std::vector<cv::Rect2d> &arm
double min_x, min_y, max_x, max_y; double min_x, min_y, max_x, max_y;
min_x = fmin(rect_left.x, rect_right.x); min_x = fmin(rect_left.x, rect_right.x);
max_x = fmax(rect_left.x + rect_left.width, rect_right.x + rect_right.width); max_x = fmax(rect_left.x + rect_left.width, rect_right.x + rect_right.width);
min_y = fmin(rect_left.y, rect_right.y) - 5; 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); max_y = fmax(rect_left.y + rect_left.height, rect_right.y + rect_right.height) + 3;
if (min_x < 0 || max_x > 640 || min_y < 0 || max_y > 480) { if (min_x < 0 || max_x > 640 || min_y < 0 || max_y > 480) {
continue; continue;
} }
@@ -147,31 +152,42 @@ bool judge_light_color(std::vector<LightBlob> &light, std::vector<LightBlob> &co
} }
bool ArmorFinder::stateSearchingTarget(cv::Mat &src) { bool ArmorFinder::stateSearchingTarget(cv::Mat &src) {
cv::Mat split, pmsrc=src.clone(), src_bin; cv::Mat split, src_bin;
LightBlobs light_blobs, pm_light_blobs, light_blobs_real; LightBlobs light_blobs, light_blobs_, light_blobs_real;
std::vector<cv::Rect2d> armor_boxes, boxes_one, boxes_two, boxes_three; std::vector<cv::Rect2d> armor_boxes, boxes_number[10];
armor_box = cv::Rect2d(0,0,0,0);
// cv::resize(src, pmsrc, cv::Size(320, 240)); cv::cvtColor(src, src_gray, CV_BGR2GRAY);
imageColorSplit(src, split, enemy_color); // pipelineLightBlobPreprocess(src_gray);
cv::threshold(split, src_bin, 130, 255, CV_THRESH_BINARY); cv::threshold(src_gray, src_bin, 120, 255, CV_THRESH_BINARY);
imagePreProcess(src_bin);
// cv::imshow("bin", src_bin);
// cv::resize(split, split, cv::Size(640, 480));
// pipelineLightBlobPreprocess(pmsrc);
// if(!findLightBlobs(pmsrc, pm_light_blobs)){
// return false;
// }
if(!findLightBlobs(src_bin, light_blobs)){ if(!findLightBlobs(src_bin, light_blobs)){
return false; return false;
} }
// if(!judge_light_color(light_blobs, pm_light_blobs, light_blobs_real)){
// return false;
// }
if(show_light_blobs){ if(show_light_blobs){
showContours("blobs", split, light_blobs); showContours("blobs", src_bin, light_blobs);
cv::waitKey(1); cv::waitKey(1);
} }
if(!findArmorBoxes(light_blobs, armor_boxes)){
imageColorSplit(src, split, enemy_color);
imagePreProcess(split);
cv::threshold(split, src_bin, 120, 255, CV_THRESH_BINARY);
if(!findLightBlobs(src_bin, light_blobs_)){
return false;
}
if(show_light_blobs){
showContours("blobs_", src_bin, light_blobs_);
cv::waitKey(1);
}
if(!judge_light_color(light_blobs, light_blobs_, light_blobs_real)){
return false;
}
if(show_light_blobs){
showContours("blobs_real", src, light_blobs_real);
cv::waitKey(1);
}
if(!findArmorBoxes(light_blobs_real, armor_boxes)){
return false; return false;
} }
if(show_armor_boxes){ if(show_armor_boxes){
@@ -183,29 +199,21 @@ bool ArmorFinder::stateSearchingTarget(cv::Mat &src) {
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));
int c = classifier(roi); int c = classifier(roi);
switch(c){ if(c){
case 1: boxes_number[c-1].emplace_back(box);
boxes_one.emplace_back(box);
break;
case 2:
boxes_two.emplace_back(box);
break;
case 3:
boxes_three.emplace_back(box);
break;
} }
} }
if(!boxes_one.empty()){ for(auto box : boxes_number){
armor_box = boxes_one[0]; if(!box.empty()){
}else if(!boxes_two.empty()){ armor_box = box[0];
armor_box = boxes_two[0]; }
}else if(!boxes_three.empty()){ }
armor_box = boxes_three[0];
} else{ if(armor_box == cv::Rect2d(0,0,0,0)){
return false; return false;
} }
if(show_armor_box){ if(show_armor_boxes){
showArmorBoxClass("class", src, boxes_one, boxes_two, boxes_three); showArmorBoxClass("class", src, boxes_number);
} }
}else{ }else{
armor_box = armor_boxes[0]; armor_box = armor_boxes[0];

View File

@@ -18,8 +18,7 @@ void showArmorBoxVector(std::string windows_name, const cv::Mat &src, const std:
imshow(windows_name, image2show); imshow(windows_name, image2show);
} }
void showArmorBoxClass(std::string windows_name, const cv::Mat &src, vector<cv::Rect2d> boxes_one, void showArmorBoxClass(std::string window_names, const cv::Mat &src, vector<cv::Rect2d> boxes[10]){
vector<cv::Rect2d> boxes_two, vector<cv::Rect2d> boxes_three){
static Mat image2show; static Mat image2show;
if (src.type() == CV_8UC1) // 黑白图像 if (src.type() == CV_8UC1) // 黑白图像
{ {
@@ -28,16 +27,17 @@ void showArmorBoxClass(std::string windows_name, const cv::Mat &src, vector<cv::
{ {
image2show = src.clone(); image2show = src.clone();
} }
for (auto &box:boxes_one) { for(int i=0; i<10; i++){
rectangle(image2show, box, Scalar(255, 0, 0), 1); if(!boxes[i].empty()){
for(auto box : boxes[i]){
char buff[2] = {0};
buff[0] = i + '0';
rectangle(image2show, box, Scalar(0, 255, 0), 1);
putText(image2show, buff, Point(box.x+2, box.y+2), cv::FONT_HERSHEY_TRIPLEX, 1, Scalar(255,0,0));
}
}
} }
for (auto &box:boxes_two) { imshow(window_names, image2show);
rectangle(image2show, box, Scalar(0, 255, 0), 1);
}
for (auto &box:boxes_three) {
rectangle(image2show, box, Scalar(0, 0, 255), 1);
}
imshow(windows_name, image2show);
} }
void showArmorBox(std::string windows_name, const cv::Mat &src, cv::Rect2d armor_box) { void showArmorBox(std::string windows_name, const cv::Mat &src, cv::Rect2d armor_box) {

View File

@@ -27,66 +27,68 @@ using namespace std;
int state = ARMOR_STATE; 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;
void uartReceive(Uart* uart); void uartReceive(Uart *uart);
int main(int argc, char *argv[]){ int main(int argc, char *argv[]) {
process_options(argc, argv); process_options(argc, argv);
Uart uart; Uart uart;
thread receive(uartReceive, &uart); thread receive(uartReceive, &uart);
bool flag = true; bool flag = true;
while (flag){ while (flag) {
int ally_color = ALLY_RED; int ally_color = ALLY_RED;
int energy_part_rotation = CLOCKWISE; int energy_part_rotation = CLOCKWISE;
int from_camera = 1; int from_camera = 1;
if(!run_with_camera) { if (!run_with_camera) {
cout << "Input 1 for camera, 0 for video files" << endl; cout << "Input 1 for camera, 0 for video files" << endl;
cin >> from_camera; cin >> from_camera;
} }
WrapperHead *video_armor; WrapperHead *video_armor;
WrapperHead *video_energy; WrapperHead *video_energy;
if(from_camera) { if (from_camera) {
video_armor = new CameraWrapper(0); video_armor = new CameraWrapper(0);
// video_energy = new CameraWrapper(1); video_energy = new CameraWrapper(1);
}else { } else {
video_armor = new VideoWrapper("/home/xinyang/Desktop/Video.mp4"); video_armor = new VideoWrapper("/home/xinyang/Desktop/Video.mp4");
video_energy = new VideoWrapper("/home/xinyang/Desktop/Video.mp4"); video_energy = new VideoWrapper("/home/xinyang/Desktop/Video.mp4");
} }
if (video_armor->init()) { if (video_armor->init()) {
cout << "Video source initialization successfully." << endl; cout << "Video source initialization successfully." << endl;
} }
Mat energy_src, armor_src; Mat energy_src, armor_src;
ArmorFinder armorFinder(ENEMY_BLUE, uart, PROJECT_DIR"/tools/para/");
ArmorFinder armorFinder(ENEMY_BLUE, uart, PROJECT_DIR"/tools/para/");
Energy energy(uart); Energy energy(uart);
energy.setAllyColor(ally_color); energy.setAllyColor(ally_color);
energy.setRotation(energy_part_rotation); energy.setRotation(energy_part_rotation);
bool ok=true; bool ok = true;
while (ok){ while (ok) {
CNT_TIME(WORD_LIGHT_CYAN, "Total", { CNT_TIME(WORD_LIGHT_CYAN, "Total", {
ok = video_armor->read(energy_src) && video_armor->read(armor_src);
if (show_origin) {
imshow("enery src", energy_src);
imshow("armor src", armor_src);
}
if (state == ENERGY_STATE) { if (state == ENERGY_STATE) {
ok = video_energy->read(energy_src);
if (show_origin) {
imshow("energy src", energy_src);
}
if (from_camera == 0) { if (from_camera == 0) {
energy.extract(energy_src); energy.extract(energy_src);
} }
energy.run(energy_src); energy.run(energy_src);
} else { } else {
ok = video_armor->read(armor_src);
if (show_origin) {
imshow("armor src", armor_src);
}
CNT_TIME(WORD_LIGHT_BLUE, "Armor Time", { CNT_TIME(WORD_LIGHT_BLUE, "Armor Time", {
armorFinder.run(armor_src); armorFinder.run(armor_src);
}); });
} }
if (waitKey(1) == 'q') { if (waitKey(1) == 'q') {
@@ -94,41 +96,41 @@ int main(int argc, char *argv[]){
break; break;
} }
}); });
} }
delete video_armor; delete video_armor;
cout << "Program fails. Restarting" << endl; cout << "Program fails. Restarting" << endl;
} }
return 0; return 0;
} }
#define RECEIVE_LOG_LEVEL LOG_NOTHING #define RECEIVE_LOG_LEVEL LOG_NOTHING
void uartReceive(Uart* uart){ void uartReceive(Uart *uart) {
char buffer[100]; char buffer[100];
int cnt=0; int cnt = 0;
while(true){ while (true) {
char data; char data;
while((data=uart->receive()) != '\n'){ while ((data = uart->receive()) != '\n') {
buffer[cnt++] = data; buffer[cnt++] = data;
if(cnt >= 100){ if (cnt >= 100) {
LOG(RECEIVE_LOG_LEVEL, "data receive over flow!"); LOG(RECEIVE_LOG_LEVEL, "data receive over flow!");
cnt = 0; cnt = 0;
} }
} }
if(cnt == 10){ if (cnt == 10) {
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");
}else if(buffer[8] == 'a'){ } else if (buffer[8] == 'a') {
state = ARMOR_STATE; state = ARMOR_STATE;
LOG(RECEIVE_LOG_LEVEL, "Armor state"); LOG(RECEIVE_LOG_LEVEL, "Armor state");
} }
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);
if(buffer[9] == 1){ if (buffer[9] == 1) {
if(mark == 0){ if (mark == 0) {
mark = 1; mark = 1;
mark_yaw = curr_yaw; mark_yaw = curr_yaw;
mark_pitch = curr_pitch; mark_pitch = curr_pitch;

View File

@@ -65,11 +65,14 @@ stop:
tCapability.sResolutionRange.iWidthMax * 3); tCapability.sResolutionRange.iWidthMax * 3);
if(mode == 0){ if(mode == 0){
// 不使用自动曝光 // 不使用自动曝光
CameraSetAeState(h_camera, true); CameraSetAeState(h_camera, false);
// 曝光时间10ms // 曝光时间10ms
// CameraSetExposureTime(h_camera, 10000); CameraSetExposureTime(h_camera, 10000);
double t;
CameraGetExposureTime(h_camera, &t);
LOGM("Exposure time: %lfms", t/1000.0);
// 模拟增益4 // 模拟增益4
CameraSetAnalogGain(h_camera, 64); CameraSetAnalogGain(h_camera, 55);
// 使用预设LUT表 // 使用预设LUT表
CameraSetLutMode(h_camera, LUTMODE_PRESET); CameraSetLutMode(h_camera, LUTMODE_PRESET);
// 抗频闪 // 抗频闪
@@ -90,7 +93,7 @@ stop:
/*其他的相机参数设置 /*其他的相机参数设置
例如 CameraSetExposureTime CameraGetExposureTime 设置/读取曝光时间 例如 CameraSetExposureTime CameraGetExposureTime 设置/读取曝光时间
CameraSetImageResolution CameraGetImageResolution 设置/读取分辨率 CameraSetImageResolution CameraGetImageResolution 设置/读取分辨率
CameraSetGamma、CameraSetConrast、CameraSetGain等设置图像伽马、对比度、RGB数字增益等等。 CameraSetGamma、CameraSetContrast、CameraSetGain等设置图像伽马、对比度、RGB数字增益等等。
CameraGetFriendlyName CameraSetFriendlyName 获取/设置相机名称(该名称可写入相机硬件) CameraGetFriendlyName CameraSetFriendlyName 获取/设置相机名称(该名称可写入相机硬件)
*/ */

View File

@@ -4,6 +4,7 @@
#include <uart/uart.h> #include <uart/uart.h>
#include <energy/param_struct_define.h> #include <energy/param_struct_define.h>
#include <log.h>
using std::cout; using std::cout;
using std::cerr; using std::cerr;
@@ -16,7 +17,6 @@ GMAngle_t aim;
Uart::Uart(){ Uart::Uart(){
fd = open("/dev/ttyUSB0", O_RDWR); fd = open("/dev/ttyUSB0", O_RDWR);
if(fd < 0) if(fd < 0)
{ {
@@ -150,12 +150,8 @@ void Uart::sendTarget(float x, float y, float z) {
} }
// 's' + (x) ( 8bit + 8bit ) + (y) ( 8bit + 8bit ) + (z) ( 8bit + 8bit ) + 'e'
uint8_t Uart::receive() { uint8_t Uart::receive() {
uint8_t data; uint8_t data;
while(read(fd, &data, 1) < 1); while(read(fd, &data, 1) < 1);
return data; return data;
} }

View File

@@ -5,6 +5,7 @@ from tqdm import tqdm
import generate import generate
import forward import forward
import cv2 import cv2
import sys
import numpy as np import numpy as np
print("Finish!") print("Finish!")
@@ -53,7 +54,7 @@ def save_para(folder, paras):
save_bias(fp, paras[7]) save_bias(fp, paras[7])
STEPS = 20000 STEPS = 100000
BATCH = 30 BATCH = 30
LEARNING_RATE_BASE = 0.01 LEARNING_RATE_BASE = 0.01
LEARNING_RATE_DECAY = 0.99 LEARNING_RATE_DECAY = 0.99
@@ -61,8 +62,6 @@ MOVING_AVERAGE_DECAY = 0.99
def train(dataset, show_bar=False): def train(dataset, show_bar=False):
test_images, test_labels = dataset.all_test_sets()
x = tf.placeholder(tf.float32, [None, generate.SRC_ROWS, generate.SRC_COLS, generate.SRC_CHANNELS]) x = tf.placeholder(tf.float32, [None, generate.SRC_ROWS, generate.SRC_COLS, generate.SRC_CHANNELS])
y_= tf.placeholder(tf.float32, [None, forward.OUTPUT_NODES]) y_= tf.placeholder(tf.float32, [None, forward.OUTPUT_NODES])
nodes, vars = forward.forward(x, 0.001) nodes, vars = forward.forward(x, 0.001)
@@ -104,15 +103,10 @@ def train(dataset, show_bar=False):
if i % 100 == 0: if i % 100 == 0:
if i % 1000 == 0: if i % 1000 == 0:
acc = sess.run(accuracy, feed_dict={x: test_images, y_: test_labels}) test_samples, test_labels = dataset.sample_test_sets(5000)
acc = sess.run(accuracy, feed_dict={x: test_samples, y_: test_labels})
bar.set_postfix({"loss": loss_value, "acc": acc}) bar.set_postfix({"loss": loss_value, "acc": acc})
# if show_bar:
# bar.title = "step: %d, loss: %f, acc: %f" % (step, loss_value, acc)
# bar.cursor.restore()
# bar.draw(value=i+1)
# video = cv2.VideoCapture("/home/xinyang/Desktop/Video.mp4") # video = cv2.VideoCapture("/home/xinyang/Desktop/Video.mp4")
# _ = True # _ = True
# while _: # while _:
@@ -148,15 +142,17 @@ def train(dataset, show_bar=False):
# res = sess.run(y, feed_dict={x: im}) # res = sess.run(y, feed_dict={x: im})
# res = res.reshape([forward.OUTPUT_NODES]) # res = res.reshape([forward.OUTPUT_NODES])
# print(np.argmax(res)) # print(np.argmax(res))
test_samples, test_labels = dataset.sample_test_sets(100)
vars_val = sess.run(vars) vars_val = sess.run(vars)
save_para("/home/xinyang/Desktop/AutoAim/tools/para", vars_val) save_para("/home/xinyang/Desktop/AutoAim/tools/para", vars_val)
nodes_val = sess.run(nodes, feed_dict={x:test_images}) nodes_val = sess.run(nodes, feed_dict={x:test_samples})
return vars_val, nodes_val return vars_val, nodes_val, test_samples
if __name__ == "__main__": if __name__ == "__main__":
print("Loading data sets...") print("Loading data sets...")
dataset = generate.DataSet("/home/xinyang/Desktop/DataSets/box") dataset = generate.DataSet("/home/xinyang/Desktop/DataSets")
print("Finish!") print("Finish!")
train(dataset, show_bar=True) train(dataset, show_bar=True)
input("Press any key to end...")

View File

@@ -29,20 +29,19 @@ def max_pool_2x2(x):
CONV1_KERNAL_SIZE = 5 CONV1_KERNAL_SIZE = 5
# 第一层卷积输出通道数 # 第一层卷积输出通道数
CONV1_OUTPUT_CHANNELS = 6 CONV1_OUTPUT_CHANNELS = 8
# 第二层卷积核大小 # 第二层卷积核大小
CONV2_KERNAL_SIZE = 3 CONV2_KERNAL_SIZE = 3
# 第二层卷积输出通道数 # 第二层卷积输出通道数
CONV2_OUTPUT_CHANNELS = 10 CONV2_OUTPUT_CHANNELS = 16
# 第一层全连接宽度 # 第一层全连接宽度
FC1_OUTPUT_NODES = 16 FC1_OUTPUT_NODES = 16
# 第二层全连接宽度(输出标签类型数) # 第二层全连接宽度(输出标签类型数)
FC2_OUTPUT_NODES = 4 FC2_OUTPUT_NODES = 11
# 输出标签类型数 # 输出标签类型数
OUTPUT_NODES = FC2_OUTPUT_NODES OUTPUT_NODES = FC2_OUTPUT_NODES

View File

@@ -67,6 +67,15 @@ class DataSet:
labels.append(self.train_labels[id]) labels.append(self.train_labels[id])
return np.array(samples), np.array(labels) return np.array(samples), np.array(labels)
def sample_test_sets(self, length):
samples = []
labels = []
for i in range(length):
id = random.randint(0, len(self.test_samples)-1)
samples.append(self.test_samples[id])
labels.append(self.test_labels[id])
return np.array(samples), np.array(labels)
def all_train_sets(self): def all_train_sets(self):
return self.train_samples[:], self.train_labels[:] return self.train_samples[:], self.train_labels[:]

52
tools/analysis.py Executable file
View File

@@ -0,0 +1,52 @@
import matplotlib.pyplot as plt
import numpy as np
fsend = open("send.info")
frecv = open("recv.info")
send_lines = fsend.readlines()[:-1]
recv_lines = frecv.readlines()[:-1]
send_infos = [line.split(" ") for line in send_lines]
recv_infos = [line.split(" ") for line in recv_lines]
send_times = [float(info[0]) for info in send_infos]
recv_times = [float(info[0]) for info in recv_infos]
send_yaw = [float(info[1]) for info in send_infos]
TargetAngle= [float(info[1]) for info in recv_infos]
RealAngle = [float(info[2]) for info in recv_infos]
length = min(len(send_times), len(recv_times))
send_times = send_times[:length]
recv_times = recv_times[:length]
send_yaw = send_yaw[:length]
TargetAngle= TargetAngle[:length]
RealAngle = RealAngle[:length]
time_base = min(send_times[0], recv_times[0])
send_times = np.array(send_times) - time_base
recv_times = np.array(recv_times) - time_base
TargetAngle = TargetAngle[:300]
RealAngle = RealAngle[:300]
send_times = send_times[:300]
recv_times = recv_times[:300]
send_yaw = send_yaw[:300]
TargetAngle = np.array(TargetAngle)
TargetAngle -= TargetAngle.mean()
RealAngle = np.array(RealAngle)
RealAngle -= RealAngle.mean()
plt.plot(send_times, send_yaw, label="send-yaw")
plt.plot(recv_times, TargetAngle,label="TargetAngle")
plt.plot(recv_times, RealAngle, label="RealAngle")
plt.scatter(send_times, send_yaw, label="send-yaw")
plt.scatter(recv_times, TargetAngle,label="TargetAngle")
plt.scatter(recv_times, RealAngle, label="RealAngle")
plt.legend()
plt.show()

View File

@@ -1,7 +1,9 @@
6 8
0.6241298 1.4952865
1.1128483 0.71153855
0.92715627 -3.1710217
2.6803706 -0.13555647
-2.4037633 -0.1106117
1.6914424 -0.67361253
0.8526688
-0.5431338

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,17 @@
10 16
2.4876857 -8.03951
-0.2729608 3.4012065
-2.472103 -0.13434531
1.4380744 -2.9315674
0.13707557 -0.19703378
-0.38399124 -1.5522652
-0.10049698 -2.032869
-0.44721037 -3.2706444
-0.24111606 -0.21717867
-0.05031827 -0.19119318
-0.15644628
8.05552
-1.1173456
1.5701971
-0.081088655
-0.1808035

File diff suppressed because it is too large Load Diff

View File

@@ -1,17 +1,17 @@
16 16
6.674671 -3.9457524
-0.4621555 -0.3353631
-0.35395312 -0.53903425
-6.140842 -0.22991405
-0.6383096 8.231101
-0.0026992396 -0.29107538
-0.105528705 -0.20410632
-0.12171911 -0.9607706
-0.039757866 -0.56446344
-4.064281 -0.17112184
-0.36199543 29.32642
-0.06976157 7.855335
-0.042993866 -2.8522294
0.0015301058 -0.097452246
-0.06826296 1.2676659
-0.0050806464 -0.038555548

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,12 @@
4 11
6.171619 4.68946
-1.5262855 2.4254043
-4.09489 -1.1937128
-2.3815227 12.141608
-9.4490185
2.2703283
-5.419338
-7.4511914
0.31088707
-2.521978
-4.9146705

View File

@@ -1,66 +1,178 @@
16 16
4 11
0.70240104 -0.01987104
-0.058500186 0.42782968
-0.23156737 -0.12000261
-0.33127818 -0.22871323
-3.6112761e-34 5.909024e-06
-3.3890292e-34 0.12846695
9.363116e-34 0.34395957
4.0197816e-34 -0.025282092
-0.2575022 -0.2352891
0.69736814 0.060300585
-0.2684227 -0.11231345
-0.08991088 -7.6262363e-34
-0.3760809 -1.1019437e-33
-0.065089576 2.395344e-34
0.45981047 -7.14328e-34
0.008204719 1.12534335e-33
-4.8556375e-34 3.6429394e-34
4.816393e-34 -1.09642895e-33
3.872484e-34 -5.5404825e-35
5.096778e-34 -1.2785976e-34
1.7445673e-19 4.6425433e-34
1.2270845e-33 2.0518196e-34
-2.260416e-25 -3.817569e-34
1.0369542e-20 -1.3871395e-08
4.00948e-34 -8.454291e-34
-5.999333e-34 6.484888e-34
3.7143163e-34 -9.504644e-12
-4.228372e-34 3.8818015e-34
-1.0954501e-34 4.3159157e-34
-2.7085206e-34 -7.718197e-34
8.016929e-34 5.7451056e-34
9.2079354e-35 -4.4890632e-34
-3.945864e-34 -3.9756725e-34
1.98814e-34 7.855176e-34
2.3972646e-34 1.04599e-33
3.942207e-34 -1.2205084e-33
-0.14058167 -2.641615e-34
-0.07198931 6.133725e-34
-0.38025984 3.8102495e-34
0.5981627 -9.052317e-34
4.3956684e-34 -1.1754962e-33
3.1032594e-34 8.280429e-34
3.4351758e-34 7.856483e-34
5.5414507e-34 -2.1041588e-34
-1.248324e-34 0.0044932007
8.8546844e-35 -0.3508491
6.8084945e-34 -0.4295554
-1.1866068e-34 -0.13176644
-3.865728e-34 9.088804e-06
1.8786859e-34 -0.35067832
3.3450276e-34 0.37535986
-2.8077459e-34 0.28786227
0.0013890187 0.44722718
0.026067872 0.24968775
0.0082543865 0.31687224
-0.02225164 9.918349e-34
2.0089658e-34 -1.3927404e-33
-6.1273506e-34 -1.2877562e-33
-6.228039e-34 1.0205193e-33
-5.0242814e-34 9.401986e-34
-4.3343494e-34 -5.9421037e-34
3.0939117e-34 -1.1976041e-33
1.2827092e-34 -1.4003625e-33
-4.305108e-34 -2.3580773e-36
7.481718e-34
4.8942575e-34
4.6177516e-35
-6.6717886e-34
3.223957e-34
-1.584663e-34
6.743674e-34
1.6929226e-34
-1.6124294e-34
-4.8999394e-34
3.5384667e-34
4.6176213e-35
-4.3959643e-36
4.8607646e-34
-2.2389736e-07
-1.0547912e-34
4.7272058e-35
2.1540245e-09
1.0148082e-33
-1.2641985e-34
-4.718617e-34
-2.9784954e-34
-9.195764e-34
-5.4015044e-35
-9.436068e-34
2.340125e-08
-6.886075e-34
6.8557177e-34
-2.3418155e-11
-8.925727e-34
-2.6056772e-34
-2.770205e-35
-1.3465729e-33
-2.8787352e-35
2.5913718e-34
-2.7904087e-34
-4.580196e-34
4.9749566e-34
7.079356e-34
1.5309345e-34
5.076401e-34
-7.8047275e-35
5.7707056e-34
1.0374484e-33
-7.2734595e-34
-2.4512414e-34
0.5898928
-0.13292696
0.13457516
-0.3083663
-4.5226676e-05
-0.016318614
-0.056287136
-0.0416729
-0.13633117
-0.034681365
-0.058179155
-0.053308636
-0.15685758
-0.057880845
-0.049490057
-4.48231e-06
0.54238904
-0.12667982
-0.11757153
-0.2049767
-0.12322974
0.46258917
0.3563643
-0.0011422047
0.012159694
0.10425257
7.641402e-06
-0.0068169823
-0.061314583
-0.20332839
-0.19299586
0.43478948
-0.006821075
5.7795678e-34
-9.393816e-35
9.3423295e-34
-4.974839e-34
-1.2766868e-33
6.1611773e-34
-1.0581506e-34
-8.838601e-34
-1.4182854e-33
-7.169634e-34
6.2219504e-34
-0.05864723
0.012660546
0.47422087
-0.12896037
8.181692e-05
0.15611899
-0.043533176
0.39083794
-0.4173265
-0.02371774
-0.0947099
7.7225295e-35
-1.7053759e-23
-5.490969e-23
-2.3247693e-23
-1.0633658e-22
9.971754e-23
4.4417918e-24
5.392504e-23
2.8454636e-23
8.56064e-23
9.8926345e-23