diff --git a/src/ai_platform/FeatureAnalysis.cpp b/src/ai_platform/FeatureAnalysis.cpp index 4e46efc..8437a42 100644 --- a/src/ai_platform/FeatureAnalysis.cpp +++ b/src/ai_platform/FeatureAnalysis.cpp @@ -123,12 +123,26 @@ void FeatureAnalysis::update_car_info(ObjectInfo& res_obj, vpc_img_info& img_inf if (vec_vpd_res.size() > 0) { VPDResult res = vec_vpd_res[0]; + for (size_t i = 0; i < res.vec_vpd_res.size(); i++) + { + auto& info = res.vec_vpd_res[i]; + info.left_ = res_obj.left + info.left_; + info.top_ = res_obj.top + info.top_; + } + res_obj.vec_vpd_cls = res.vec_vpd_res; } vector vec_plate_res = m_vehicle_plate.process(vec_Mem); if (vec_plate_res.size() > 0) { + for (size_t i = 0; i < vec_plate_res.size(); i++) + { + auto& info = vec_plate_res[i]; + info.left_ = res_obj.left + info.left_; + info.top_ = res_obj.top + info.top_; + } + res_obj.vehicle_plate = vec_plate_res[0]; } } diff --git a/src/ai_platform/task_manager.h b/src/ai_platform/task_manager.h index 08f2734..a9bc60c 100644 --- a/src/ai_platform/task_manager.h +++ b/src/ai_platform/task_manager.h @@ -10,8 +10,6 @@ #include "../decoder/dvpp/DvppDecoder.h" #include "../decoder/interface/utiltools.hpp" -#include "opencv2/highgui/highgui.hpp" - using namespace std; typedef struct TaskInfo diff --git a/src/demo/demo.cpp b/src/demo/demo.cpp index 51691c8..320bb1e 100755 --- a/src/demo/demo.cpp +++ b/src/demo/demo.cpp @@ -7,7 +7,14 @@ #include #include +#include "opencv2/opencv.hpp" +#include "opencv2/imgcodecs/legacy/constants_c.h" +#include "opencv2/imgproc/types_c.h" + +#include "demo_util.hpp" + using namespace std; +using namespace cv; static long long get_cur_time(){ @@ -157,20 +164,61 @@ string createTask(void *handle, int gi, bool bFlag = true){ void show_result(ObjectData obj) { - cout << obj.task_id << endl; - cout << obj.task_frame_count << endl; + printf("%s %d \n", obj.task_id.c_str(), obj.task_frame_count); printf("%d %d (%d,%d,%d,%d) %lf \n", obj.index, obj.object_id, obj.left, obj.top, obj.right, obj.bottom, obj.confidence); + cv::Mat image = cv::imread(obj.ori_pic_path); + + cv::Rect rc(obj.left, obj.top,obj.right - obj.left, obj.bottom - obj.top); + const cv::Scalar color(0, 0, 255); + cv::rectangle(image, rc, color); + if (obj.index == 0) {// person - /* code */ + for (size_t i = 0; i < HP_ATTRI_SIZE; i++) + { + auto hp_cls = obj.hp_cls[i]; + printf("(%d, %f) ", hp_cls.res_index, hp_cls.res_prob); + } + printf("\n"); + for (size_t i = 0; i < HUMANREID_FEATURE_SIZE; i++) + { + auto hp_cls = obj.hp_feature[i]; + printf("%f ", obj.hp_feature[i]); + } + printf("\n"); } else if (obj.index >= 4 && obj.index <= 8) {// vehicle - /* code */ + printf("vehicle color:%d prob:%f \n", obj.vehicle_color_index, obj.vehicle_color_prob); + for (size_t i = 0; i < obj.vec_vpd_cls.size(); i++) + { + auto info = obj.vec_vpd_cls[i]; + printf("%d %f (%d, %d, %d, %d) \n", info.index, info.confidence, info.left_, info.top_, info.width_, info.height_); + + cv::Rect rc(info.left_, info.top_, info.width_, info.height_); + const cv::Scalar color(0, 255, 255); + cv::rectangle(image, rc, color); + } + + auto& plate_info = obj.vehicle_plate; + printf("plate : (%d, %d, %d, %d) %f \n", plate_info.left_, plate_info.top_, plate_info.width_, plate_info.height_, plate_info.detect_score ); + cv::Rect rc(plate_info.left_, plate_info.top_, plate_info.width_, plate_info.height_); + const cv::Scalar color(0, 255, 0); + cv::rectangle(image, rc, color); + for (size_t i = 0; i < 8; i++) + { + printf("%s:%f ", plate_info.recg[i].character, plate_info.recg[i].maxprob); + } + printf("\n"); + printf("num_score: %f \n", plate_info.num_score); + printf("type: %d \n", plate_info.type); + printf("state:%d %f\n", plate_info.state, plate_info.state_score); } - + string result_path = "./res/result/" + obj.task_id + "_" + to_string(obj.object_id) + ".jpg"; + cv::imwrite(result_path, image); + image.release(); } void test_gpu(int gpuID){ @@ -195,6 +243,8 @@ void test_gpu(int gpuID){ printf("Init Success\n"); } + CreateResultFolder("./res/result", ""); + // createTask(handle, algor_vec2, 19, false); // createTask(handle, algor_vec2, 20, false); // createTask(handle, algor_vec2, 21, false); diff --git a/src/demo/demo_util.hpp b/src/demo/demo_util.hpp new file mode 100644 index 0000000..7c76ee2 --- /dev/null +++ b/src/demo/demo_util.hpp @@ -0,0 +1,110 @@ +#ifndef __DEMO_UTIL__ +#define __DEMO_UTIL__ + +#include +#include +#include +#include +#include + +#define ACCESS access +#define MKDIR(a) mkdir((a),0755) + + +int CreateDir(char *pszDir); +void CreateResultFolder(const char* resultFolder, const char* jointFolder); + + +int CreateDir(char *pszDir) +{ + int i = 0; + int iRet; + int iLen = strlen(pszDir); + if (pszDir[iLen - 1] != '\\' && pszDir[iLen - 1] != '/') + { + pszDir[iLen] = '/'; + pszDir[iLen + 1] = '\0'; + } + iLen = strlen(pszDir); + + if (iLen > 2 && ((pszDir[i] == '\\' && pszDir[i + 1] == '\\') || (pszDir[i] == '/' && pszDir[i + 1] == '/'))) + { + i = 2; + for (; i <= iLen; i++) + if (pszDir[i] == '\\' || pszDir[i] == '/') + break; + + i++; + + for (; i <= iLen; i++) + { + if (pszDir[i] == '\\' || pszDir[i] == '/') + { + pszDir[i] = '\0'; + //printf("file access %s\n", pszDir); + iRet = ACCESS(pszDir, 0); + //printf("file access %d\n", iRet); + if (iRet != 0) + { + //printf("file mkdir %s\n", pszDir); + iRet = MKDIR(pszDir); + //printf("file mkdir %d\n", iRet); + if (iRet != 0) + { + return -1; + } + } + pszDir[i] = '/'; + + } + } + return 0; + } + + if (pszDir[i] != '\\' && pszDir[i] != '/') + i = 0; + else + i = 1; + for (; i <= iLen; i++) + { + if (pszDir[i] == '\\' || pszDir[i] == '/') + { + pszDir[i] = '\0'; + iRet = ACCESS(pszDir, 0); + if (iRet != 0) + { + iRet = MKDIR(pszDir); + if (iRet != 0) + { + return -1; + } + } + pszDir[i] = '/'; + + } + } + return 0; +} + + +void CreateResultFolder(const char* resultFolder, const char* jointFolder) +{ + if (strlen(resultFolder) > 240) //?too long + { + return; + } + else if (strlen(resultFolder) < 1) //?too short + { + return; + } + + char dir[260]; + + sprintf(dir, "%s%s/", resultFolder, jointFolder); + if (CreateDir(dir) != 0) + { + return; + } +} + +#endif // __DEMO_UTIL__ \ No newline at end of file diff --git a/src/reprocessing_module/snapshot_reprocessing.cpp b/src/reprocessing_module/snapshot_reprocessing.cpp index 6e3b030..0d2cafd 100755 --- a/src/reprocessing_module/snapshot_reprocessing.cpp +++ b/src/reprocessing_module/snapshot_reprocessing.cpp @@ -121,15 +121,6 @@ void snapshot_reprocessing::update_bestsnapshot(vector vec_devMem total_snapshot_info[new_obj].flags[2] = obj_info.right > frame_width - minDistance[2] - SCALE_OUT ? 0 : 1; //right total_snapshot_info[new_obj].flags[3] = obj_info.bottom > frame_height - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom - int cur_left = max(obj_info.left - 10, 0); - int cur_top = max(obj_info.top - 10, 0); - int cur_right = min(obj_info.right + 10, frame_width - 1); - int cur_bottom = min(obj_info.bottom + 10, frame_height - 1); - total_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素 - total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top); - - total_snapshot_info[new_obj].frameCount = memPtr->getFrameNb(); - video_object_info info; info.left = max(obj_info.left - expansion_width, 0); info.top = max(obj_info.top - expansion_height, 0); @@ -141,6 +132,12 @@ void snapshot_reprocessing::update_bestsnapshot(vector vec_devMem info.index = index; vec_obj_info.push_back(info); + + total_snapshot_info[new_obj].obj_pos = { info.left, info.top, info.right - info.left, info.bottom - info.top }; //debug by zsh 推出的坐标外扩10像素 + total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = (info.right - info.left) * (info.bottom - info.top); + + total_snapshot_info[new_obj].frameCount = memPtr->getFrameNb(); + } else { total_snapshot_info[new_obj].last_area = (obj_info.right - obj_info.left) * (obj_info.bottom - obj_info.top); @@ -164,15 +161,6 @@ void snapshot_reprocessing::update_bestsnapshot(vector vec_devMem total_snapshot_info[new_obj].index.count--; } - int cur_left = max(obj_info.left - 10, 0); - int cur_top = max(obj_info.top - 10, 0); - int cur_right = min(obj_info.right + 10, frame_width - 1); - int cur_bottom = min(obj_info.bottom + 10, frame_height - 1); - total_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素 - total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top); - - total_snapshot_info[new_obj].frameCount = memPtr->getFrameNb(); - video_object_info info; info.left = max(obj_info.left - expansion_width, 0); info.top = max(obj_info.top - expansion_height, 0); @@ -184,6 +172,11 @@ void snapshot_reprocessing::update_bestsnapshot(vector vec_devMem info.index = index; vec_obj_info.push_back(info); + + total_snapshot_info[new_obj].obj_pos = { info.left, info.top, info.right - info.left, info.bottom - info.top }; //debug by zsh 推出的坐标外扩10像素 + total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = (info.right - info.left) * (info.bottom - info.top); + + total_snapshot_info[new_obj].frameCount = memPtr->getFrameNb(); } }