Commit 01b357d4ed86c08082bf9c56330cd25bd3cec10b
1 parent
98293f20
添加获取显存占用的代码
Showing
2 changed files
with
117 additions
and
6 deletions
src/demo/main.cpp
... | ... | @@ -2,12 +2,49 @@ |
2 | 2 | #include <vector> |
3 | 3 | #include <string> |
4 | 4 | #include <iostream> |
5 | +#include <dirent.h> | |
6 | +#include<fstream> | |
7 | + | |
5 | 8 | #include "../utils/logger.hpp" |
9 | +#include "../utils/DeviceUtil.hpp" | |
6 | 10 | |
7 | 11 | using namespace std; |
8 | 12 | |
9 | 13 | void show_result(std::vector<AnalysisResult> r, vector<string> vec_path); |
10 | 14 | |
15 | + | |
16 | +void GetFileNames(string path,vector<string>& filenames) | |
17 | +{ | |
18 | + DIR *pDir; | |
19 | + struct dirent* ptr; | |
20 | + if(!(pDir = opendir(path.c_str()))){ | |
21 | + cout<<"Folder doesn't Exist!"<<endl; | |
22 | + return; | |
23 | + } | |
24 | + while((ptr = readdir(pDir))!=0) { | |
25 | + if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0){ | |
26 | + filenames.push_back(path + "/" + ptr->d_name); | |
27 | + } | |
28 | + } | |
29 | + closedir(pDir); | |
30 | +} | |
31 | + | |
32 | +vector<string> GetFilesFromFile(string file_path){ | |
33 | + | |
34 | + vector<string> vec_files; | |
35 | + | |
36 | + fstream infile(file_path); | |
37 | + | |
38 | + string text; | |
39 | + while (getline(infile, text)){ | |
40 | + // text.erase(text.size() - 1, 1); | |
41 | + vec_files.push_back(text); | |
42 | + } | |
43 | + infile.close(); | |
44 | + | |
45 | + return vec_files; | |
46 | +} | |
47 | + | |
11 | 48 | int main() { |
12 | 49 | |
13 | 50 | void *vaHandle = NULL; |
... | ... | @@ -32,14 +69,43 @@ int main() { |
32 | 69 | // vec_path.push_back(path); |
33 | 70 | // } |
34 | 71 | |
72 | + | |
73 | + | |
35 | 74 | vector<string> vec_path; |
75 | + GetFileNames("/home/share/data/villiage_test/test", vec_path); | |
76 | + | |
77 | + vec_path = GetFilesFromFile("./files1.log"); | |
78 | + | |
79 | + // { | |
80 | + // string path = "./img/test_road2.jpg"; | |
81 | + // vec_path.push_back(path); | |
82 | + // } | |
83 | + | |
84 | + int last_recoder = 0; | |
85 | + int index = 0; | |
86 | + | |
87 | + while (true) | |
36 | 88 | { |
37 | - string path = "./img/test_motor4.jpg"; | |
38 | - vec_path.push_back(path); | |
89 | + for (size_t i = 0; i < vec_path.size(); i++) | |
90 | + { | |
91 | + vector<string> vec_file_name; | |
92 | + vec_file_name.push_back(vec_path[i]); | |
93 | + vec_file_name.push_back(vec_path[i]); | |
94 | + | |
95 | + std::vector<AnalysisResult> result = village_pic_analysis_file(vaHandle, vec_file_name); | |
96 | + show_result(result, vec_path); | |
97 | + | |
98 | + int cur_recoder = GetDeviceMem(0); | |
99 | + if (cur_recoder > last_recoder) | |
100 | + { | |
101 | + LOG_INFO("memesize cur: {} last:{} file:{}", cur_recoder, last_recoder, vec_path[i]); | |
102 | + } | |
103 | + last_recoder = cur_recoder; | |
104 | + } | |
105 | + LOG_INFO("第{}次完成:{}", index, vec_path.size()); | |
106 | + index++; | |
39 | 107 | } |
40 | 108 | |
41 | - std::vector<AnalysisResult> result = village_pic_analysis_file(vaHandle, vec_path); | |
42 | - show_result(result, vec_path); | |
43 | 109 | |
44 | 110 | village_pic_release(&vaHandle); |
45 | 111 | |
... | ... | @@ -62,6 +128,8 @@ void show_result(std::vector<AnalysisResult> result, vector<string> vec_path){ |
62 | 128 | |
63 | 129 | for (size_t i = 0; i < result.size(); i++) |
64 | 130 | { |
131 | + LOG_INFO("-------------------------------------------第{}张图---------------------------------------------", i); | |
132 | + | |
65 | 133 | std::vector<VehicleInfo> info = result[i].info; |
66 | 134 | for (size_t j = 0; j < info.size(); j++) |
67 | 135 | { |
... | ... | @@ -91,7 +159,7 @@ void show_result(std::vector<AnalysisResult> result, vector<string> vec_path){ |
91 | 159 | } |
92 | 160 | |
93 | 161 | |
94 | - LOG_INFO("-------------------------------------------{}---------------------------------------------", j); | |
162 | + LOG_INFO("----------------{}---------------", j); | |
95 | 163 | LOG_INFO("位置特征"); |
96 | 164 | 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_); |
97 | 165 | LOG_INFO(" 拍摄方向:{}", shot_type[info[j].type]); |
... | ... | @@ -150,13 +218,18 @@ void show_result(std::vector<AnalysisResult> result, vector<string> vec_path){ |
150 | 218 | LineInfo one_line = vec_line[i]; |
151 | 219 | LOG_INFO(" 标线类型:{}", line_cls[one_line.line_type]); |
152 | 220 | string str_line = ""; |
153 | - for (size_t j = 0; j < one_line.vec_pt.size(); j++) | |
221 | + const cv::Scalar color(seg_colors[i][0], seg_colors[i][1], seg_colors[i][2]); | |
222 | + size_t j = 0; | |
223 | + for (; j < one_line.vec_pt.size() - 1; j++) | |
154 | 224 | { |
225 | + cv::line(image, one_line.vec_pt[j], one_line.vec_pt[j+1], color, 2, 8); | |
155 | 226 | str_line += to_string(one_line.vec_pt[j].x)+","+to_string(one_line.vec_pt[j].y) + "_"; |
156 | 227 | } |
228 | + str_line += to_string(one_line.vec_pt[j].x)+","+to_string(one_line.vec_pt[j].y) + "_"; | |
157 | 229 | LOG_INFO(" 标线点集:{}", str_line); |
158 | 230 | } |
159 | 231 | |
232 | + std::vector<std::vector<cv::Point> > polys; | |
160 | 233 | std::vector<SegInfo> vec_road = result[i].vec_road; |
161 | 234 | for (size_t i = 0; i < vec_road.size(); i++) |
162 | 235 | { |
... | ... | @@ -167,8 +240,19 @@ void show_result(std::vector<AnalysisResult> result, vector<string> vec_path){ |
167 | 240 | { |
168 | 241 | str_line += to_string(one_seg.vec_pt[j].x)+","+to_string(one_seg.vec_pt[j].y) + "_"; |
169 | 242 | } |
243 | + | |
244 | + // polys.push_back(one_seg.vec_pt); | |
245 | + | |
246 | + const cv::Scalar color(seg_colors[i][0], seg_colors[i][1], seg_colors[i][2]); | |
247 | + cv::polylines(image, one_seg.vec_pt, true, color, 3); | |
248 | + | |
249 | + // cv::fillPoly(image, one_seg.vec_pt, color); | |
250 | + | |
170 | 251 | LOG_INFO(" 车道点集:{}", str_line); |
171 | 252 | } |
253 | + | |
254 | + // const cv::Scalar color(0, 0, 255); | |
255 | + // cv::fillPoly(image, polys, color); | |
172 | 256 | } |
173 | 257 | |
174 | 258 | cv::imwrite("./show_result.jpg", image); | ... | ... |
src/utils/DeviceUtil.hpp
0 → 100644
1 | + | |
2 | +#ifndef __DEVICE_UTIL__ | |
3 | +#define __DEVICE_UTIL__ | |
4 | + | |
5 | +#include "acl/acl.h" | |
6 | +#include "acl/ops/acl_dvpp.h" | |
7 | + | |
8 | +#include "logger.hpp" | |
9 | + | |
10 | + | |
11 | +int GetDeviceMem(int dev_id) { | |
12 | + aclrtSetDevice(dev_id); | |
13 | + size_t free = 0; | |
14 | + size_t total = 0; | |
15 | + aclError err = aclrtGetMemInfo(ACL_DDR_MEM, &free, &total); | |
16 | + aclrtResetDevice(dev_id); | |
17 | + if (err != 0){ | |
18 | + LOG_ERROR("aclrtGetMemInfo error!"); | |
19 | + return -1; | |
20 | + } | |
21 | + LOG_INFO("device {} memory usage/total:{}/{}", dev_id, total - free, total); | |
22 | + | |
23 | + return total - free; | |
24 | +} | |
25 | + | |
26 | + | |
27 | +#endif // __DEVICE_UTIL__ | |
0 | 28 | \ No newline at end of file | ... | ... |