-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
150 lines (127 loc) · 3.77 KB
/
Copy pathmain.cpp
File metadata and controls
150 lines (127 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "threadpool/ThreadPool.hpp"
#include "lockfree/LockFree.hpp"
#include "hikrobot/HikRobot.hpp"
#include "daheng_camera/daheng_camera.hpp"
#include "Detect.hpp"
#include "Track.hpp"
#include "Mouse.hpp"
#include "function/function.hpp"
#ifndef MCAP_IMPLEMENTATION
#define MCAP_IMPLEMENTATION
#endif
#include "Capture.hpp"
#define DUMP
#ifndef DUMP
#define CAPTURE
#else
#include "dump/dump.hpp"
#endif
#include <nlohmann/json.hpp>
#include <fstream>
int main() {
ThreadPool t_p;
LfStack<FromData> fd_msgs;
#ifndef DUMP
LfStack<ImageInfo> image_info_stack;
LfStack<ImageInfo> mouse_info_stack;
SerialPort sp;
#ifdef CAPTURE
LfStack<CaptureInfo> capture_stack;
#endif
auto receive = [&]() -> void {
//1、读取json文件
nlohmann::json config = nlohmann::json::parse(std::ifstream("../config/json/sensors.json"));
std::string type = config["camera"]["type"];
//2、动态创建相机
std::unique_ptr<sensors::BaseCamera> cmaera;
if (type == "daheng") {
cmaera = std::make_unique<DahengCamera>(sp);
}else if (type == "hikrobot"){
cmaera = std::make_unique<HikRobot>(sp);
}else{
std::cerr<<"unknown camera type"<<type<<std::endl;
exit(-1);
}
cmaera->cameraInit();
while (1) {
//std::cout<< "opening camera"<<std::endl;
cmaera->refreshImage(fd_msgs);
}
};
auto detect = [&]() -> void {
Detect detect("debug");
while (1) {
detect.detect(
fd_msgs,
image_info_stack,
mouse_info_stack);
}
};
auto track = [&]() -> void {
Track tracker(sp, "debug");
while (1) {
#ifdef CAPTURE
tracker.update(image_info_stack, capture_stack);
#else
tracker.update(image_info_stack);
#endif
}
};
auto mouse = [&]() -> void {
Mouse m;
while (1) {
m.mouseControl(mouse_info_stack);
}
};
#ifdef CAPTURE
auto capture_func = [&]() -> void {
std::cout << "capture thread start." << std::endl;
Capture cap("/Dart",
"Vision",
"foxglove.CaptureInformation",
"/home/ganjie/Vision_Code/config/flatbuffers/CaptureInformation.fbs",
"8UC3");
cap.setMacpPath(function::getBagPath());
cap.init();
int frame_count;
J_CAPTURE.config_["frame_cnt"] >> frame_count;
while(true) {
std::optional<CaptureInfo> opt_value = capture_stack.pop();
if (!opt_value.has_value() || opt_value.value().cd.dune == 1 || !opt_value.value().cd.mode) {
continue;
}
cap.update(opt_value.value());
if (!(--frame_count)) {
cap.finish();
cap.setMacpPath(function::getBagPath());
cap.init();
J_CAPTURE.config_["frame_cnt"] >> frame_count;
}
}
};
#endif
t_p.addTask(receive);
t_p.addTask(detect);
t_p.addTask(track);
t_p.addTask(mouse);
#ifdef CAPTURE
t_p.addTask(capture_func);
#endif
#else
auto dump = [&]() -> void {
std::string directory;
std::string name;
std::string type;
J_CAPTURE.config_["mcap"]["directory"] >> directory;
J_CAPTURE.config_["mcap"]["name"] >> name;
J_CAPTURE.config_["mcap"]["type"] >> type;
std::cout << directory + name + type << std::endl;
std::ifstream input(directory + name + type, std::ios::binary);
mcap::FileStreamReader dataSource{input};
DumpMessages(name, dataSource, fd_msgs);
};
t_p.addTask(dump);
#endif
t_p.run();
return 0;
}