2019赛季RM中部分区赛,自瞄和能量机关,完整稳定版。
This commit is contained in:
@@ -25,6 +25,7 @@ struct mcu_data{
|
||||
extern mcu_data mcuData;
|
||||
|
||||
void uartReceive(Serial *pSerial);
|
||||
void initVideoWriter(cv::VideoWriter& video, const std::string &armor_filename_prefix);
|
||||
void initVideoWriter(cv::VideoWriter& video, const std::string &filename_prefix);
|
||||
void lastVideo(std::string &video_name, const std::string &filename_prefix);
|
||||
|
||||
#endif /* _ADDITIONS_H_ */
|
||||
|
||||
@@ -138,9 +138,9 @@
|
||||
#include <sys/time.h>
|
||||
#define CNT_TIME(tag, codes, ...) do{ \
|
||||
static timeval ts, te; \
|
||||
gettimeofday(&ts); \
|
||||
gettimeofday(&ts, NULL); \
|
||||
codes; \
|
||||
gettimeofday(&te); \
|
||||
gettimeofday(&te, NULL); \
|
||||
LOGM(tag": %.1lfms", (te.tv_sec-ts.tv_sec)*1000.0+(te.tv_usec-ts.tv_usec)/1000.0); \
|
||||
}while (0)
|
||||
#endif
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
//
|
||||
// Created by xinyang on 19-4-7.
|
||||
//
|
||||
|
||||
#ifndef _ADDITIONS_H_
|
||||
#define _ADDITIONS_H_
|
||||
|
||||
#include <serial/serial.h>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <thread>
|
||||
|
||||
void save_video_file(cv::Mat &src);
|
||||
void save_labelled_image(cv::Mat &src, cv::Rect2d box);
|
||||
|
||||
|
||||
#endif /* _ADDITIONS_H_ */
|
||||
@@ -7,24 +7,32 @@
|
||||
#include <additions/additions.h>
|
||||
#include <log.h>
|
||||
#include <opencv2/videoio/videoio_c.h>
|
||||
#include <iostream>
|
||||
|
||||
#define RECEIVE_LOG_LEVEL LOG_NOTHING
|
||||
#define RECEIVE_LOG_LEVEL LOG_MSG
|
||||
|
||||
using namespace std;
|
||||
|
||||
void uartReceive(Serial* pSerial) {
|
||||
char buffer[100];
|
||||
char buffer[20];
|
||||
int cnt = 0;
|
||||
LOGM("data receive start!");
|
||||
LOGM(STR_CTR(WORD_LIGHT_WHITE,"data receive start!"));
|
||||
while (true) {
|
||||
char byte;
|
||||
char byte = 0;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
while (pSerial->ReadData((uint8_t*)&byte, 1) && byte!='\n') {
|
||||
buffer[cnt++] = byte;
|
||||
if (cnt >= 100) {
|
||||
LOG(RECEIVE_LOG_LEVEL, "data receive over flow!");
|
||||
if (cnt >= sizeof(buffer)) {
|
||||
// LOGE("data receive over flow!");
|
||||
cnt = 0;
|
||||
}
|
||||
}
|
||||
if (cnt==0 && byte=='\n'){
|
||||
LOGM("%d", cnt);
|
||||
}
|
||||
if (cnt == sizeof(mcuData)) {
|
||||
memcpy(&mcuData, buffer, sizeof(mcuData));
|
||||
LOGM("Get, state:%c, mark:%d!", mcuData.state, (int)mcuData.mark);
|
||||
}
|
||||
cnt = 0;
|
||||
}
|
||||
@@ -38,13 +46,24 @@ void initVideoWriter(cv::VideoWriter& video, const std::string &filename_prefix)
|
||||
in >> cnt;
|
||||
in.close();
|
||||
}
|
||||
std::string armor_file_name = filename_prefix + std::to_string(cnt) + ".avi";
|
||||
std::string file_name = filename_prefix + std::to_string(cnt) + ".avi";
|
||||
cnt++;
|
||||
std::ofstream out(filename_prefix + "cnt.txt");
|
||||
if (out.is_open()) {
|
||||
out << cnt << std::endl;
|
||||
out.close();
|
||||
}
|
||||
video.open(armor_file_name, CV_FOURCC('P', 'I', 'M', '1'), 90, cv::Size(640, 480), true);
|
||||
video.open(file_name, CV_FOURCC('P', 'I', 'M', '1'), 90, cv::Size(640, 480), true);
|
||||
}
|
||||
|
||||
void lastVideo(std::string &video_name, const std::string &filename_prefix){
|
||||
std::ifstream in(filename_prefix + "cnt.txt");
|
||||
int cnt = 0;
|
||||
if (in.is_open())
|
||||
{
|
||||
in >> cnt;
|
||||
in.close();
|
||||
}
|
||||
if(cnt > 1) std::string video_name = filename_prefix + std::to_string(cnt) + ".avi";
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ bool CameraWrapper::init() {
|
||||
|
||||
rgb_buffer = (unsigned char *)malloc(tCapability.sResolutionRange.iHeightMax *
|
||||
tCapability.sResolutionRange.iWidthMax * 3);
|
||||
#ifdef Windows
|
||||
char filepath[200];
|
||||
sprintf(filepath, PROJECT_DIR"/others/%s.Config", name.data());
|
||||
if (CameraReadParameterFromFile(h_camera, filepath) != CAMERA_STATUS_SUCCESS) {
|
||||
@@ -72,6 +73,15 @@ bool CameraWrapper::init() {
|
||||
return false;
|
||||
}
|
||||
LOGM("successfully loaded %s!", filepath);
|
||||
#elif defined(Linux)
|
||||
CameraSetAeState(h_camera, false);
|
||||
CameraSetExposureTime(h_camera, 17*1000);
|
||||
CameraSetAnalogGain(h_camera, 60);
|
||||
if(mode == 0){
|
||||
CameraSetGain(h_camera, 140, 140, 140);
|
||||
CameraSetLutMode(h_camera, LUTMODE_PRESET);
|
||||
}
|
||||
#endif
|
||||
double t;
|
||||
CameraGetExposureTime(h_camera, &t);
|
||||
LOGM("Exposure time: %lfms", t / 1000.0);
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
//
|
||||
// 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/"
|
||||
|
||||
bool save_label_error_flag = false;
|
||||
|
||||
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){
|
||||
if(!save_label_error_flag) {
|
||||
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_label_error_flag = true;
|
||||
return;
|
||||
}
|
||||
fprintf(fp, "%lf %lf %lf %lf\n", box.x, box.y, box.width, box.height);
|
||||
fclose(fp);
|
||||
save_labelled_cnt(cnt);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <options/options.h>
|
||||
#include <iostream>
|
||||
|
||||
#define LOG_LEVEL LOG_NONE
|
||||
//#define LOG_LEVEL LOG_NONE
|
||||
#include <log.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
Reference in New Issue
Block a user