e6b08c4f
Hu Chunming
优化demo
|
1
2
3
|
#include "../village_pic_interface.h"
#include <vector>
#include <string>
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
4
|
#include <iostream>
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
5
6
7
|
#include <dirent.h>
#include<fstream>
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
8
|
#include "../utils/logger.hpp"
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
9
|
#include "../utils/DeviceUtil.hpp"
|
e6b08c4f
Hu Chunming
优化demo
|
10
11
|
using namespace std;
|
20396d5c
Hu Chunming
添加车头车尾算法
|
12
|
|
5fc0b809
Hu Chunming
完善demo
|
13
|
void show_result(std::vector<AnalysisResult> r, vector<string> vec_path);
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
14
|
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
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
|
void GetFileNames(string path,vector<string>& filenames)
{
DIR *pDir;
struct dirent* ptr;
if(!(pDir = opendir(path.c_str()))){
cout<<"Folder doesn't Exist!"<<endl;
return;
}
while((ptr = readdir(pDir))!=0) {
if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0){
filenames.push_back(path + "/" + ptr->d_name);
}
}
closedir(pDir);
}
vector<string> GetFilesFromFile(string file_path){
vector<string> vec_files;
fstream infile(file_path);
string text;
while (getline(infile, text)){
// text.erase(text.size() - 1, 1);
vec_files.push_back(text);
}
infile.close();
return vec_files;
}
|
20396d5c
Hu Chunming
添加车头车尾算法
|
48
49
|
int main() {
|
e6b08c4f
Hu Chunming
优化demo
|
50
|
void *vaHandle = NULL;
|
20396d5c
Hu Chunming
添加车头车尾算法
|
51
|
|
6ec23cbb
Hu Chunming
更新demo
|
52
53
|
VillageParam param;
param.dev_id = 0;
|
581a68a4
Hu Chunming
修正parse_road无返回值导...
|
54
|
param.sdk_path = ".";
|
e3062370
Hu Chunming
优化日志
|
55
|
param.log_level = 1;
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
56
57
58
59
|
string log_path = param.log_path + "/main.log";
set_default_logger(LogLevel(param.log_level), "PicAnalysis", log_path.c_str(), param.log_mem, param.log_days);
|
5fc0b809
Hu Chunming
完善demo
|
60
|
|
e6b08c4f
Hu Chunming
优化demo
|
61
|
int ret = village_pic_init(&vaHandle, param);
|
20396d5c
Hu Chunming
添加车头车尾算法
|
62
|
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
63
64
65
66
67
68
69
70
71
|
// vector<string> vec_path;
// size_t i = 0;
// // for (i = 1; i < 8; i++)
// {
// string path = "./img/test_road";
// path = path + to_string(i) + ".jpg";
// vec_path.push_back(path);
// }
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
72
73
|
|
20396d5c
Hu Chunming
添加车头车尾算法
|
74
|
vector<string> vec_path;
|
3f4b245b
Hu Chunming
更新demo
|
75
|
// GetFileNames("/home/share/data/villiage_test/test3", vec_path);
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
76
|
|
d708ccb3
Hu Chunming
增加日志
|
77
|
// vec_path = GetFilesFromFile("./files1.log");
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
78
|
|
3f4b245b
Hu Chunming
更新demo
|
79
80
81
82
|
{
string path = "/home/share/data/villiage_test/test3/192.168.10.67_01_20230601160330100_15.jpg";
vec_path.push_back(path);
}
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
83
|
|
d708ccb3
Hu Chunming
增加日志
|
84
|
size_t last_recoder = 0;
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
85
|
int index = 0;
|
d708ccb3
Hu Chunming
增加日志
|
86
|
int max_value = vec_path.size();
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
87
|
|
3f4b245b
Hu Chunming
更新demo
|
88
|
// while (true)
|
20396d5c
Hu Chunming
添加车头车尾算法
|
89
|
{
|
d708ccb3
Hu Chunming
增加日志
|
90
|
// for (size_t i = 0; i < vec_path.size(); i++)
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
91
|
{
|
d708ccb3
Hu Chunming
增加日志
|
92
93
94
|
int first_index = rand() % max_value;
int second_index = rand() % max_value;
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
95
|
vector<string> vec_file_name;
|
d708ccb3
Hu Chunming
增加日志
|
96
|
vec_file_name.push_back(vec_path[first_index]);
|
3f4b245b
Hu Chunming
更新demo
|
97
|
// vec_file_name.push_back(vec_path[second_index]);
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
98
99
|
std::vector<AnalysisResult> result = village_pic_analysis_file(vaHandle, vec_file_name);
|
3f4b245b
Hu Chunming
更新demo
|
100
|
show_result(result, vec_path);
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
101
|
|
d708ccb3
Hu Chunming
增加日志
|
102
|
size_t cur_recoder = GetDeviceMem(0);
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
103
104
|
if (cur_recoder > last_recoder)
{
|
d708ccb3
Hu Chunming
增加日志
|
105
106
|
// LOG_INFO("memesize cur: {} last:{} file:{} file:{}", cur_recoder, last_recoder, vec_path[first_index], vec_path[second_index]);
LOG_INFO("memesize cur: {} last:{} ", cur_recoder, last_recoder);
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
107
108
109
|
}
last_recoder = cur_recoder;
}
|
d708ccb3
Hu Chunming
增加日志
|
110
111
|
// LOG_INFO("第{}次完成:{}", index, vec_path.size());
LOG_INFO("第{}次完成", index);
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
112
|
index++;
|
20396d5c
Hu Chunming
添加车头车尾算法
|
113
114
|
}
|
20396d5c
Hu Chunming
添加车头车尾算法
|
115
|
|
e6b08c4f
Hu Chunming
优化demo
|
116
|
village_pic_release(&vaHandle);
|
20396d5c
Hu Chunming
添加车头车尾算法
|
117
118
|
return 0;
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
119
120
121
122
|
}
static string shot_type[] = {"head", "rear", "motor", "tricycle", "body", "body_nova", "6-行人"};
static string vehicle_type[] = {"person 人", " bike 自行车", "motor 摩托车", "tricycle 三轮车", "car 汽车", "bigbus 大巴", "lorry 货车", "tractor 拖拉机", "midibus 面包/中巴"};
|
5fc0b809
Hu Chunming
完善demo
|
123
|
static string plate_status[] = {"无车牌", " 正常车牌", " 遮挡车牌"};
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
124
125
126
127
128
|
static string plate_type[] = {"0-单排蓝色 ", "1-单排黄色 ", "2-单排白色 ", "3-单排黑色", " 4-双排黄色 ", "5-双排白色 ", "6-新能源黄绿色 ", "7-新能源白绿色"};
static string human_color[] = {"棕", "橙", "灰", "白", "粉", "紫", "红", "绿", "蓝", "银", "青", "黄", "黑","多色", "其他"};
static string line_cls[] = {"未知", "黄实线", " 白实线", "白虚线", "黄虚线", "车道中线"};
static string seg_cls[] = {"未知","行车道/机动车道", "非机动车道", "应急车道", "导流线", "人行横道", "禁停区域", "十字路口区域", "农村道路"};
|
5fc0b809
Hu Chunming
完善demo
|
129
130
131
132
133
|
uint8_t seg_colors[][3] = { {0, 0, 0}, {0, 255, 255}, {128, 255, 0}, {255, 128, 0}, {128, 0, 255}, {255, 0, 128}, {0, 128, 255}, {0, 255, 128}, {128, 255, 255}};
void show_result(std::vector<AnalysisResult> result, vector<string> vec_path){
cv::Mat image = cv::imread(vec_path[0]);
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
134
135
136
|
for (size_t i = 0; i < result.size(); i++)
{
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
137
138
|
LOG_INFO("-------------------------------------------第{}张图---------------------------------------------", i);
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
139
140
141
142
143
144
|
std::vector<VehicleInfo> info = result[i].info;
for (size_t j = 0; j < info.size(); j++)
{
auto plate_info = info[j].vehicle_plate_det_recg_res;
std::vector<pendant_info> pendant_res = info[j].vehicle_pendant_det_res;
|
5fc0b809
Hu Chunming
完善demo
|
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
cv::Rect rc;
rc.x = info[j].vehicle_body_detect_res.rect.left_;
rc.y = info[j].vehicle_body_detect_res.rect.top_;
rc.width = info[j].vehicle_body_detect_res.rect.width_;
rc.height = info[j].vehicle_body_detect_res.rect.height_;
const cv::Scalar color(seg_colors[j][0], seg_colors[j][1], seg_colors[j][2]);
cv::rectangle(image, rc, color);
auto taken_info = info[j].manned_res;
for (size_t k= 0; k < taken_info.hs_count; k++)
{
cv::Rect rc;
rc.x = taken_info.hs_rect[k].rect.left_;
rc.y = taken_info.hs_rect[k].rect.top_;
rc.width = taken_info.hs_rect[k].rect.width_;
rc.height = taken_info.hs_rect[k].rect.height_;
const cv::Scalar color(255, 255, 255);
cv::rectangle(image, rc, color);
}
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
168
|
LOG_INFO("----------------{}---------------", j);
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
169
170
171
172
|
LOG_INFO("位置特征");
LOG_INFO(" 车辆位置:{},{},{},{}", info[j].vehicle_body_detect_res.rect.left_ ,info[j].vehicle_body_detect_res.rect.top_, info[j].vehicle_body_detect_res.rect.width_, info[j].vehicle_body_detect_res.rect.height_);
LOG_INFO(" 拍摄方向:{}", shot_type[info[j].type]);
LOG_INFO("目标类型:{}", vehicle_type[info[j].vpt_type]);
|
5fc0b809
Hu Chunming
完善demo
|
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
if (info[j].vpt_type > 0)
{
LOG_INFO("车辆特征");
if (plate_info.stain_vp_result.type >= 0 && plate_info.stain_vp_result.type <= 2) {
LOG_INFO(" 号牌状态:{}", plate_status[plate_info.stain_vp_result.type]);
}else {
LOG_INFO(" 号牌状态:未知");
}
LOG_INFO(" 号牌位置:{},{},{},{}", plate_info.rect.left_, plate_info.rect.top_, plate_info.rect.width_, plate_info.rect.height_ );
if (plate_info.type >= 0) {
LOG_INFO(" 号牌种类:{} {}", plate_type[plate_info.type], plate_info.type);
} else {
LOG_INFO(" 号牌种类:未知", plate_type[plate_info.type], plate_info.type);
}
LOG_INFO(" 号牌号码:{}{}{}{}{}{}{}{}", plate_info.recg[0].character, plate_info.recg[1].character, plate_info.recg[2].character, plate_info.recg[3].character, plate_info.recg[4].character, plate_info.recg[5].character, plate_info.recg[6].character, plate_info.recg[7].character);
LOG_INFO(" 号牌可信度:{}", plate_info.detect_score);
|
3f4b245b
Hu Chunming
更新demo
|
190
|
LOG_INFO(" 每位号牌可信度: {}:{} {}:{} {}:{} {}:{} {}:{} {}:{} {}:{} {}:{}", plate_info.recg[0].character, plate_info.recg[0].maxprob, plate_info.recg[1].character, plate_info.recg[1].maxprob, plate_info.recg[2].character, plate_info.recg[2].maxprob, plate_info.recg[3].character, plate_info.recg[3].maxprob, plate_info.recg[4].character, plate_info.recg[4].maxprob, plate_info.recg[5].character, plate_info.recg[5].maxprob, plate_info.recg[6].character, plate_info.recg[6].maxprob, plate_info.recg[7].character, plate_info.recg[7].maxprob);
|
5fc0b809
Hu Chunming
完善demo
|
191
192
193
194
195
196
197
|
LOG_INFO(" 车辆类型分类:{}", vehicle_type[info[j].vpt_type]);
} else {
LOG_INFO("行人特征");
LOG_INFO(" 上衣颜色:{}", human_color[info[j].human_upper_color]);
LOG_INFO(" 下衣颜色:{}", human_color[info[j].human_lower_color]);
}
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
198
199
200
201
202
203
204
205
206
207
208
|
if (pendant_res.size() > 0)
{
LOG_INFO("驾乘人员特征");
for (size_t k = 0; k < pendant_res.size(); k++)
{
auto one_pendant = pendant_res[k];
LOG_INFO(" 位置信息:{},{},{},{}", one_pendant.rect.left_, one_pendant.rect.top_, one_pendant.rect.width_, one_pendant.rect.height_ );
LOG_INFO(" 可信度:{}", one_pendant.confidence);
LOG_INFO(" 衣着颜色:{}", human_color[one_pendant.iColor]);
}
}
|
5fc0b809
Hu Chunming
完善demo
|
209
|
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
210
|
LOG_INFO("违法行为特征");
|
5fc0b809
Hu Chunming
完善demo
|
211
|
LOG_INFO(" 不戴头盔:{} 置信度:{}", info[j].mta_res.motor_driver_helmeted.status, info[j].mta_res.motor_driver_helmeted.confidence);
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
LOG_INFO(" 违法载人:{}", info[j].motor_manned);
LOG_INFO(" 加装雨棚:{} {}", info[j].rainshed, info[j].rainshed_prob);
LOG_INFO(" 使用手机:{} {}", info[j].phoning, info[j].phoning_prob);
LOG_INFO(" 逆行:{}", info[j].reverse_driving);
LOG_INFO(" 货厢载人:{}", info[j].truck_manned);
LOG_INFO(" 违反禁止标线 压实线:{} 压导流线:{}", info[j].cross_line, info[j].cross_diversion_line);
}
LOG_INFO("标线信息");
std::vector<LineInfo> vec_line = result[i].vec_line;
for (size_t i = 0; i < vec_line.size(); i++)
{
LineInfo one_line = vec_line[i];
LOG_INFO(" 标线类型:{}", line_cls[one_line.line_type]);
string str_line = "";
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
227
228
229
|
const cv::Scalar color(seg_colors[i][0], seg_colors[i][1], seg_colors[i][2]);
size_t j = 0;
for (; j < one_line.vec_pt.size() - 1; j++)
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
230
|
{
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
231
|
cv::line(image, one_line.vec_pt[j], one_line.vec_pt[j+1], color, 2, 8);
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
232
233
|
str_line += to_string(one_line.vec_pt[j].x)+","+to_string(one_line.vec_pt[j].y) + "_";
}
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
234
|
str_line += to_string(one_line.vec_pt[j].x)+","+to_string(one_line.vec_pt[j].y) + "_";
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
235
236
237
|
LOG_INFO(" 标线点集:{}", str_line);
}
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
238
|
std::vector<std::vector<cv::Point> > polys;
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
239
240
241
242
243
244
245
246
247
248
|
std::vector<SegInfo> vec_road = result[i].vec_road;
for (size_t i = 0; i < vec_road.size(); i++)
{
SegInfo one_seg = vec_road[i];
LOG_INFO(" 车道类型:{}", seg_cls[one_seg.seg_type]);
string str_line = "";
for (size_t j = 0; j < one_seg.vec_pt.size(); j++)
{
str_line += to_string(one_seg.vec_pt[j].x)+","+to_string(one_seg.vec_pt[j].y) + "_";
}
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
249
250
251
252
253
254
255
256
|
// polys.push_back(one_seg.vec_pt);
const cv::Scalar color(seg_colors[i][0], seg_colors[i][1], seg_colors[i][2]);
cv::polylines(image, one_seg.vec_pt, true, color, 3);
// cv::fillPoly(image, one_seg.vec_pt, color);
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
257
258
|
LOG_INFO(" 车道点集:{}", str_line);
}
|
01b357d4
Hu Chunming
添加获取显存占用的代码
|
259
260
261
|
// const cv::Scalar color(0, 0, 255);
// cv::fillPoly(image, polys, color);
|
b1547dfc
Hu Chunming
设置初始值,避免异常值影响
|
262
|
}
|
5fc0b809
Hu Chunming
完善demo
|
263
264
265
|
cv::imwrite("./show_result.jpg", image);
image.release();
|
20396d5c
Hu Chunming
添加车头车尾算法
|
266
|
}
|