diff --git a/src/demo/main.cpp b/src/demo/main.cpp index afb3399..674d0a0 100644 --- a/src/demo/main.cpp +++ b/src/demo/main.cpp @@ -2,12 +2,49 @@ #include #include #include +#include +#include + #include "../utils/logger.hpp" +#include "../utils/DeviceUtil.hpp" using namespace std; void show_result(std::vector r, vector vec_path); + +void GetFileNames(string path,vector& filenames) +{ + DIR *pDir; + struct dirent* ptr; + if(!(pDir = opendir(path.c_str()))){ + cout<<"Folder doesn't Exist!"<d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0){ + filenames.push_back(path + "/" + ptr->d_name); + } + } + closedir(pDir); +} + +vector GetFilesFromFile(string file_path){ + + vector 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; +} + int main() { void *vaHandle = NULL; @@ -32,14 +69,43 @@ int main() { // vec_path.push_back(path); // } + + vector vec_path; + GetFileNames("/home/share/data/villiage_test/test", vec_path); + + vec_path = GetFilesFromFile("./files1.log"); + + // { + // string path = "./img/test_road2.jpg"; + // vec_path.push_back(path); + // } + + int last_recoder = 0; + int index = 0; + + while (true) { - string path = "./img/test_motor4.jpg"; - vec_path.push_back(path); + for (size_t i = 0; i < vec_path.size(); i++) + { + vector vec_file_name; + vec_file_name.push_back(vec_path[i]); + vec_file_name.push_back(vec_path[i]); + + std::vector result = village_pic_analysis_file(vaHandle, vec_file_name); + show_result(result, vec_path); + + int cur_recoder = GetDeviceMem(0); + if (cur_recoder > last_recoder) + { + LOG_INFO("memesize cur: {} last:{} file:{}", cur_recoder, last_recoder, vec_path[i]); + } + last_recoder = cur_recoder; + } + LOG_INFO("第{}次完成:{}", index, vec_path.size()); + index++; } - std::vector result = village_pic_analysis_file(vaHandle, vec_path); - show_result(result, vec_path); village_pic_release(&vaHandle); @@ -62,6 +128,8 @@ void show_result(std::vector result, vector vec_path){ for (size_t i = 0; i < result.size(); i++) { + LOG_INFO("-------------------------------------------第{}张图---------------------------------------------", i); + std::vector info = result[i].info; for (size_t j = 0; j < info.size(); j++) { @@ -91,7 +159,7 @@ void show_result(std::vector result, vector vec_path){ } - LOG_INFO("-------------------------------------------{}---------------------------------------------", j); + LOG_INFO("----------------{}---------------", j); 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]); @@ -150,13 +218,18 @@ void show_result(std::vector result, vector vec_path){ LineInfo one_line = vec_line[i]; LOG_INFO(" 标线类型:{}", line_cls[one_line.line_type]); string str_line = ""; - for (size_t j = 0; j < one_line.vec_pt.size(); j++) + 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++) { + cv::line(image, one_line.vec_pt[j], one_line.vec_pt[j+1], color, 2, 8); str_line += to_string(one_line.vec_pt[j].x)+","+to_string(one_line.vec_pt[j].y) + "_"; } + str_line += to_string(one_line.vec_pt[j].x)+","+to_string(one_line.vec_pt[j].y) + "_"; LOG_INFO(" 标线点集:{}", str_line); } + std::vector > polys; std::vector vec_road = result[i].vec_road; for (size_t i = 0; i < vec_road.size(); i++) { @@ -167,8 +240,19 @@ void show_result(std::vector result, vector vec_path){ { str_line += to_string(one_seg.vec_pt[j].x)+","+to_string(one_seg.vec_pt[j].y) + "_"; } + + // 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); + LOG_INFO(" 车道点集:{}", str_line); } + + // const cv::Scalar color(0, 0, 255); + // cv::fillPoly(image, polys, color); } cv::imwrite("./show_result.jpg", image); diff --git a/src/utils/DeviceUtil.hpp b/src/utils/DeviceUtil.hpp new file mode 100644 index 0000000..caa65bd --- /dev/null +++ b/src/utils/DeviceUtil.hpp @@ -0,0 +1,27 @@ + +#ifndef __DEVICE_UTIL__ +#define __DEVICE_UTIL__ + +#include "acl/acl.h" +#include "acl/ops/acl_dvpp.h" + +#include "logger.hpp" + + +int GetDeviceMem(int dev_id) { + aclrtSetDevice(dev_id); + size_t free = 0; + size_t total = 0; + aclError err = aclrtGetMemInfo(ACL_DDR_MEM, &free, &total); + aclrtResetDevice(dev_id); + if (err != 0){ + LOG_ERROR("aclrtGetMemInfo error!"); + return -1; + } + LOG_INFO("device {} memory usage/total:{}/{}", dev_id, total - free, total); + + return total - free; +} + + +#endif // __DEVICE_UTIL__ \ No newline at end of file