From ba6761f1fc1478f699b660bade0ff800c7007fb9 Mon Sep 17 00:00:00 2001 From: cmhu <2657262686@qq.com> Date: Thu, 16 Jan 2025 11:34:39 +0800 Subject: [PATCH] 补充日志 --- jni/VehicleNativeInterface.cpp | 76 +++++++++++++++++++++++++++++++++++++++++----------------------------------- src/PicAnalysis.cpp | 12 ++++++++++-- src/ai_engine_module/RoadSegAnalysis.cpp | 32 ++++++++++++++++++++++++-------- src/demo/main.cpp | 2 +- src/village_inc.h | 2 +- 5 files changed, 77 insertions(+), 47 deletions(-) diff --git a/jni/VehicleNativeInterface.cpp b/jni/VehicleNativeInterface.cpp index 0ab6b1a..b5b17a9 100644 --- a/jni/VehicleNativeInterface.cpp +++ b/jni/VehicleNativeInterface.cpp @@ -5,6 +5,7 @@ #include "map" #include #include +#include #include "../src/village_pic_interface.h" @@ -13,7 +14,7 @@ #include #include "base64.h" -#include "curl/curl.h" +// #include "curl/curl.h" //dvpp���� #include "dvpp_process.h" @@ -21,9 +22,9 @@ //#include "img_codec.h" double msecond() { - struct timeval tv; - gettimeofday(&tv, 0); - return (tv.tv_sec * 1000.0 + tv.tv_usec / 1000.0); + chrono::time_point tpMicro + = chrono::time_point_cast(chrono::system_clock::now()); + return tpMicro.time_since_epoch().count(); } @@ -89,9 +90,9 @@ using namespace std; * �������� * */ sy_format getImgByteType(int type); -size_t write_data(char *ptr, size_t size, size_t nmemb, void *userdata); -//function to retrieve the image as cv::Mat data type -cv::Mat curlImg(const char *img_url, int timeout); +// size_t write_data(char *ptr, size_t size, size_t nmemb, void *userdata); +// //function to retrieve the image as cv::Mat data type +// cv::Mat curlImg(const char *img_url, int timeout); /** * ȫ�ֱ��� @@ -154,7 +155,12 @@ JNIEXPORT jint JNICALL Java_com_objecteye_nativeinterface_vehicle_VehicleNativeI param.log_days = aiEngineParam_logDays; param.log_mem = aiEngineParam_logMem; - printf("jni dev_id:%d sdk_path:%s_log_level:%d\n", param.dev_id, param.sdk_path.c_str(), param.log_level); + printf("jni dev_id:%d \n", param.dev_id); + printf("jni sdk_path:%s_\n", param.sdk_path.c_str()); + printf("jni log_level:%d\n", param.log_level); + printf("jni log_path:%s\n", param.log_path.c_str()); + printf("jni log_days:%d\n", param.log_days); + printf("jni log_mem:%ld\n", param.log_mem); int ret = village_pic_init(&vaHandle, param); if (ret != SUCCESS) { @@ -310,7 +316,7 @@ JNIEXPORT jint JNICALL Java_com_objecteye_nativeinterface_vehicle_VehicleNativeI printf("jni info:village_pic_analysis failed."); return -1; } - //cout << "VAJNI_TEST va_1batch -> end ...." << endl; + cout << "result size:" << vec_result.size() << endl; t3 = msecond(); //printf("va jni info:process time: %.2f\n", (t3 - t2)); @@ -678,29 +684,29 @@ sy_format getImgByteType(int type) return syFormat; } -//curl writefunction to be passed as a parameter -// we can't ever expect to get the whole image in one piece, -// every router / hub is entitled to fragment it into parts -// (like 1-8k at a time), -// so insert the part at the end of our stream. -size_t write_data(char *ptr, size_t size, size_t nmemb, void *userdata) -{ - vector *stream = (vector*)userdata; - size_t count = size * nmemb; - stream->insert(stream->end(), ptr, ptr + count); - return count; -} - -//function to retrieve the image as cv::Mat data type -cv::Mat curlImg(const char *img_url, int timeout = 10) -{ - vector stream; - CURL *curl = curl_easy_init(); - curl_easy_setopt(curl, CURLOPT_URL, img_url); //the img url - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); // pass the writefunction - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream); // pass the stream ptr to the writefunction - curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout); // timeout if curl_easy hangs, - CURLcode res = curl_easy_perform(curl); // start curl - curl_easy_cleanup(curl); // cleanup - return cv::imdecode(stream, -1); // 'keep-as-is' -} +// //curl writefunction to be passed as a parameter +// // we can't ever expect to get the whole image in one piece, +// // every router / hub is entitled to fragment it into parts +// // (like 1-8k at a time), +// // so insert the part at the end of our stream. +// size_t write_data(char *ptr, size_t size, size_t nmemb, void *userdata) +// { +// vector *stream = (vector*)userdata; +// size_t count = size * nmemb; +// stream->insert(stream->end(), ptr, ptr + count); +// return count; +// } + +// //function to retrieve the image as cv::Mat data type +// cv::Mat curlImg(const char *img_url, int timeout = 10) +// { +// vector stream; +// CURL *curl = curl_easy_init(); +// curl_easy_setopt(curl, CURLOPT_URL, img_url); //the img url +// curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); // pass the writefunction +// curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream); // pass the stream ptr to the writefunction +// curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout); // timeout if curl_easy hangs, +// CURLcode res = curl_easy_perform(curl); // start curl +// curl_easy_cleanup(curl); // cleanup +// return cv::imdecode(stream, -1); // 'keep-as-is' +// } diff --git a/src/PicAnalysis.cpp b/src/PicAnalysis.cpp index 39fb5d5..fac6a9a 100644 --- a/src/PicAnalysis.cpp +++ b/src/PicAnalysis.cpp @@ -9,19 +9,23 @@ PicAnalysis::PicAnalysis(/* args */) PicAnalysis::~PicAnalysis() { + LOG_INFO("~PicAnalysis()"); release(); aclFinalize(); } int PicAnalysis::init(VillageParam param) { - set_default_logger(LogLevel(param.log_level), "PicAnalysis", param.log_path.c_str(), param.log_mem, param.log_days); + 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); // 输入参数 LOG_INFO("dev_id: {}", param.dev_id); LOG_INFO("sdk_path: {}", param.sdk_path); LOG_INFO("log_level: {}", param.log_level); LOG_INFO("log_days: {}", param.log_days); + LOG_INFO("log_path: {}", log_path); int dev_id = param.dev_id; @@ -180,13 +184,15 @@ vector PicAnalysis::va_result2AnalysisResult(va_result* result, vector PicAnalysis::analysis_img(vector vec_img){ + LOG_INFO("vec_img size:{}", vec_img.size()); + vector vec_result; const int batch_size = vec_img.size(); int ret = aclrtSetCurrentContext(m_ctx); if (SY_SUCCESS != ret) { - printf("aclrtSetCurrentContext failed!"); + LOG_INFO("aclrtSetCurrentContext failed!"); return vec_result; } @@ -196,6 +202,8 @@ vector PicAnalysis::analysis_img(vector vec_img){ m_vehicle_analysis.release_result(result, vec_img.size()); } + LOG_INFO("vec_result size:{}", vec_result.size()); + bool bConsistent = false; std::vector vec_road = m_road_seg_algorithm.detect(vec_img); if (vec_road.size() == batch_size && vec_result.size() == batch_size) { diff --git a/src/ai_engine_module/RoadSegAnalysis.cpp b/src/ai_engine_module/RoadSegAnalysis.cpp index 981a66b..91f1ca4 100644 --- a/src/ai_engine_module/RoadSegAnalysis.cpp +++ b/src/ai_engine_module/RoadSegAnalysis.cpp @@ -80,6 +80,23 @@ std::vector RoadSegAnalysis::detect(vector vec_img){ return vec_road; } +// void test(){ +// cv::Mat image(cv::Size(640, 360), CV_8UC3, cv::Scalar(0, 0, 0)); + +// for (int i = 0; i < poly_masks.size(); ++i) { +// SegInfo seg_info; +// seg_info.seg_type = region_classes[i]; +// seg_info.vec_pt = poly_masks[i]; + +// int k = seg_info.seg_type; +// const cv::Scalar color(seg_colors[k][0], seg_colors[k][1], seg_colors[k][2]); +// polylines(image, seg_info.vec_pt, true, color, 3, cv::LINE_AA); +// } + +// cv::imwrite("./road.jpg", image); +// image.release(); +// } + RoadInfo RoadSegAnalysis::parse_road(rs_result one_result, sy_img src) { RoadInfo one_road; @@ -123,7 +140,7 @@ std::vector RoadSegAnalysis::parse_direct(rs_result one_result, sy_img cv::Mat seg_output = seg_post_process(large_resolution, one_result.direct_seg, combined, poly_masks, region_classes, lanes, cats, x_sort); //m_masks:mask前的结果 poly_masks后的结果 - cv::Mat image(cv::Size(640, 360), CV_8UC3, cv::Scalar(0, 0, 0)); + // cv::Mat image(cv::Size(640, 360), CV_8UC3, cv::Scalar(0, 0, 0)); std::vector vec_road; for (int i = 0; i < poly_masks.size(); ++i) { @@ -131,16 +148,15 @@ std::vector RoadSegAnalysis::parse_direct(rs_result one_result, sy_img seg_info.seg_type = region_classes[i]; seg_info.vec_pt = poly_masks[i]; - int k = seg_info.seg_type; - const cv::Scalar color(seg_colors[k][0], seg_colors[k][1], seg_colors[k][2]); - - polylines(image, seg_info.vec_pt, true, color, 3, cv::LINE_AA); - vec_road.push_back(seg_info); + + // int k = seg_info.seg_type; + // const cv::Scalar color(seg_colors[k][0], seg_colors[k][1], seg_colors[k][2]); + // polylines(image, seg_info.vec_pt, true, color, 3, cv::LINE_AA); } - cv::imwrite("./direct.jpg", image); - image.release(); + // cv::imwrite("./direct.jpg", image); + // image.release(); return vec_road; } diff --git a/src/demo/main.cpp b/src/demo/main.cpp index e9b048f..468749e 100644 --- a/src/demo/main.cpp +++ b/src/demo/main.cpp @@ -15,7 +15,7 @@ int main() { int ret = village_pic_init(&vaHandle, param); vector vec_path; - size_t i = 1; + size_t i = 3; // for (i = 1; i < 8; i++) { string path = "./img/test_phone"; diff --git a/src/village_inc.h b/src/village_inc.h index aafbbca..113c63e 100644 --- a/src/village_inc.h +++ b/src/village_inc.h @@ -21,7 +21,7 @@ struct VillageParam { // AI_LOG_LEVEL_ERROR = 4, // 重要日志,如结果和严重错误 int log_level{2}; int log_days{30}; //日志保存周期 - std::string log_path{"logs/main.log"}; //日志文件路径 + std::string log_path{"logs"}; //日志文件路径 unsigned long log_mem{64 * 1024 * 1024}; //每个日志最大大小 }; -- libgit2 0.21.4