重新整理文件夹结构,并添加CNN训练代码。
This commit is contained in:
67
others/src/options/additions.cpp
Normal file
67
others/src/options/additions.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// Created by xinyang on 19-4-7.
|
||||
//
|
||||
|
||||
#include <options/additions.h>
|
||||
#include <options/options.h>
|
||||
#include <stdio.h>
|
||||
#include <log.h>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define VIDEO_SAVE_DIR "/home/sjturm/Desktop/video/"
|
||||
|
||||
static cv::VideoWriter *create_video_writer(){
|
||||
FILE* info = fopen(VIDEO_SAVE_DIR"info.txt", "r");
|
||||
int cnt=0;
|
||||
fscanf(info, "%d", &cnt);
|
||||
fclose(info);
|
||||
info = fopen(VIDEO_SAVE_DIR"info.txt", "w");
|
||||
fprintf(info, "%d", ++cnt);
|
||||
|
||||
char name[100];
|
||||
sprintf(name, VIDEO_SAVE_DIR"%d.avi", cnt);
|
||||
return new cv::VideoWriter(name, cv::VideoWriter::fourcc('P','I','M','1'), 80, cv::Size(640,480),false);
|
||||
}
|
||||
|
||||
void save_video_file(cv::Mat &src){
|
||||
static cv::VideoWriter *video = create_video_writer();
|
||||
video->write(src);
|
||||
}
|
||||
|
||||
#define SAVE_DIR "/home/sjturm/Desktop/labelled/"
|
||||
|
||||
int get_labelled_cnt(){
|
||||
FILE *fp = fopen(SAVE_DIR"info.txt", "r");
|
||||
int cnt=0;
|
||||
fscanf(fp, "%d", &cnt);
|
||||
fclose(fp);
|
||||
return cnt+1;
|
||||
}
|
||||
|
||||
void save_labelled_cnt(int cnt){
|
||||
FILE *fp = fopen(SAVE_DIR"info.txt", "w");
|
||||
fprintf(fp, "%d", cnt);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void save_labelled_image(cv::Mat &src, cv::Rect2d box){
|
||||
static int cnt=get_labelled_cnt();
|
||||
char name[50];
|
||||
sprintf(name, SAVE_DIR"%d.jpg", cnt);
|
||||
cv::imwrite(name, src);
|
||||
sprintf(name, SAVE_DIR"%d.txt", cnt);
|
||||
FILE *fp = fopen(name, "w");
|
||||
if(fp == NULL){
|
||||
LOGW("Can't create file: %s!\nStop saving!", name);
|
||||
save_labelled = false;
|
||||
return;
|
||||
}
|
||||
fprintf(fp, "%lf %lf %lf %lf\n", box.x, box.y, box.width, box.height);
|
||||
fclose(fp);
|
||||
save_labelled_cnt(cnt);
|
||||
}
|
||||
68
others/src/options/options.cpp
Normal file
68
others/src/options/options.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// Created by xinyang on 19-3-27.
|
||||
//
|
||||
|
||||
#include <options/options.h>
|
||||
#include <log.h>
|
||||
#include <cstring>
|
||||
|
||||
bool show_armor_box = false;
|
||||
bool show_armor_boxes = false;
|
||||
bool show_light_blobs = false;
|
||||
bool show_origin = false;
|
||||
bool save_labelled = false;
|
||||
bool run_with_camera = false;
|
||||
bool save_video = false;
|
||||
bool collect_data = false;
|
||||
|
||||
void process_options(int argc, char *argv[]){
|
||||
if(argc >= 2){
|
||||
for(int i=1; i<argc; i++){
|
||||
if(strcmp(argv[i], "--help") == 0){
|
||||
LOGM("--show-armor-box: show the aim box.");
|
||||
LOGM("--show-armor-boxes: show the candidate aim boxes.");
|
||||
LOGM("--show-light-blobs: show the candidate light blobs.");
|
||||
LOGM("--show-origin: show the origin image.");
|
||||
LOGM("--save-label: save the image when box found.");
|
||||
LOGM("--run-with-camera: start the program with camera directly without asking.");
|
||||
LOGM("--save-video: save the video.");
|
||||
LOGM("--collect-data: collect data sent from mcu.");
|
||||
}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");
|
||||
}else if(strcmp(argv[i], "--save-labeled") == 0){
|
||||
save_labelled = true;
|
||||
LOGM("Enable save labeled");
|
||||
}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], "--collect-data") == 0){
|
||||
collect_data = true;
|
||||
LOGM("Enable data collection!");
|
||||
}else{
|
||||
LOGW("Unknown option: %s. Use --help to see options.", argv[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user