Commit 1de9018272cbe6444d7cb489550e1ed5f55d261e

Authored by Hu Chunming
1 parent ee1b6080

修复特征坐标跟原图坐标不相符的问题

src/ai_platform/FeatureAnalysis.cpp
... ... @@ -123,12 +123,26 @@ void FeatureAnalysis::update_car_info(ObjectInfo& res_obj, vpc_img_info& img_inf
123 123 if (vec_vpd_res.size() > 0)
124 124 {
125 125 VPDResult res = vec_vpd_res[0];
  126 + for (size_t i = 0; i < res.vec_vpd_res.size(); i++)
  127 + {
  128 + auto& info = res.vec_vpd_res[i];
  129 + info.left_ = res_obj.left + info.left_;
  130 + info.top_ = res_obj.top + info.top_;
  131 + }
  132 +
126 133 res_obj.vec_vpd_cls = res.vec_vpd_res;
127 134 }
128 135  
129 136 vector<VehiclePlateResult> vec_plate_res = m_vehicle_plate.process(vec_Mem);
130 137 if (vec_plate_res.size() > 0)
131 138 {
  139 + for (size_t i = 0; i < vec_plate_res.size(); i++)
  140 + {
  141 + auto& info = vec_plate_res[i];
  142 + info.left_ = res_obj.left + info.left_;
  143 + info.top_ = res_obj.top + info.top_;
  144 + }
  145 +
132 146 res_obj.vehicle_plate = vec_plate_res[0];
133 147 }
134 148 }
... ...
src/ai_platform/task_manager.h
... ... @@ -10,8 +10,6 @@
10 10 #include "../decoder/dvpp/DvppDecoder.h"
11 11 #include "../decoder/interface/utiltools.hpp"
12 12  
13   -#include "opencv2/highgui/highgui.hpp"
14   -
15 13 using namespace std;
16 14  
17 15 typedef struct TaskInfo
... ...
src/demo/demo.cpp
... ... @@ -7,7 +7,14 @@
7 7 #include <unistd.h>
8 8 #include <iostream>
9 9  
  10 +#include "opencv2/opencv.hpp"
  11 +#include "opencv2/imgcodecs/legacy/constants_c.h"
  12 +#include "opencv2/imgproc/types_c.h"
  13 +
  14 +#include "demo_util.hpp"
  15 +
10 16 using namespace std;
  17 +using namespace cv;
11 18  
12 19  
13 20 static long long get_cur_time(){
... ... @@ -157,20 +164,61 @@ string createTask(void *handle, int gi, bool bFlag = true){
157 164  
158 165 void show_result(ObjectData obj)
159 166 {
160   - cout << obj.task_id << endl;
161   - cout << obj.task_frame_count << endl;
  167 + printf("%s %d \n", obj.task_id.c_str(), obj.task_frame_count);
162 168 printf("%d %d (%d,%d,%d,%d) %lf \n", obj.index, obj.object_id, obj.left, obj.top, obj.right, obj.bottom, obj.confidence);
163 169  
  170 + cv::Mat image = cv::imread(obj.ori_pic_path);
  171 +
  172 + cv::Rect rc(obj.left, obj.top,obj.right - obj.left, obj.bottom - obj.top);
  173 + const cv::Scalar color(0, 0, 255);
  174 + cv::rectangle(image, rc, color);
  175 +
164 176 if (obj.index == 0)
165 177 {// person
166   - /* code */
  178 + for (size_t i = 0; i < HP_ATTRI_SIZE; i++)
  179 + {
  180 + auto hp_cls = obj.hp_cls[i];
  181 + printf("(%d, %f) ", hp_cls.res_index, hp_cls.res_prob);
  182 + }
  183 + printf("\n");
  184 + for (size_t i = 0; i < HUMANREID_FEATURE_SIZE; i++)
  185 + {
  186 + auto hp_cls = obj.hp_feature[i];
  187 + printf("%f ", obj.hp_feature[i]);
  188 + }
  189 + printf("\n");
167 190 }
168 191 else if (obj.index >= 4 && obj.index <= 8)
169 192 {// vehicle
170   - /* code */
  193 + printf("vehicle color:%d prob:%f \n", obj.vehicle_color_index, obj.vehicle_color_prob);
  194 + for (size_t i = 0; i < obj.vec_vpd_cls.size(); i++)
  195 + {
  196 + auto info = obj.vec_vpd_cls[i];
  197 + printf("%d %f (%d, %d, %d, %d) \n", info.index, info.confidence, info.left_, info.top_, info.width_, info.height_);
  198 +
  199 + cv::Rect rc(info.left_, info.top_, info.width_, info.height_);
  200 + const cv::Scalar color(0, 255, 255);
  201 + cv::rectangle(image, rc, color);
  202 + }
  203 +
  204 + auto& plate_info = obj.vehicle_plate;
  205 + printf("plate : (%d, %d, %d, %d) %f \n", plate_info.left_, plate_info.top_, plate_info.width_, plate_info.height_, plate_info.detect_score );
  206 + cv::Rect rc(plate_info.left_, plate_info.top_, plate_info.width_, plate_info.height_);
  207 + const cv::Scalar color(0, 255, 0);
  208 + cv::rectangle(image, rc, color);
  209 + for (size_t i = 0; i < 8; i++)
  210 + {
  211 + printf("%s:%f ", plate_info.recg[i].character, plate_info.recg[i].maxprob);
  212 + }
  213 + printf("\n");
  214 + printf("num_score: %f \n", plate_info.num_score);
  215 + printf("type: %d \n", plate_info.type);
  216 + printf("state:%d %f\n", plate_info.state, plate_info.state_score);
171 217 }
172 218  
173   -
  219 + string result_path = "./res/result/" + obj.task_id + "_" + to_string(obj.object_id) + ".jpg";
  220 + cv::imwrite(result_path, image);
  221 + image.release();
174 222 }
175 223  
176 224 void test_gpu(int gpuID){
... ... @@ -195,6 +243,8 @@ void test_gpu(int gpuID){
195 243 printf("Init Success\n");
196 244 }
197 245  
  246 + CreateResultFolder("./res/result", "");
  247 +
198 248 // createTask(handle, algor_vec2, 19, false);
199 249 // createTask(handle, algor_vec2, 20, false);
200 250 // createTask(handle, algor_vec2, 21, false);
... ...
src/demo/demo_util.hpp 0 → 100644
  1 +#ifndef __DEMO_UTIL__
  2 +#define __DEMO_UTIL__
  3 +
  4 +#include <unistd.h>
  5 +#include <stdarg.h>
  6 +#include <sys/stat.h>
  7 +#include <stdio.h>
  8 +#include <string.h>
  9 +
  10 +#define ACCESS access
  11 +#define MKDIR(a) mkdir((a),0755)
  12 +
  13 +
  14 +int CreateDir(char *pszDir);
  15 +void CreateResultFolder(const char* resultFolder, const char* jointFolder);
  16 +
  17 +
  18 +int CreateDir(char *pszDir)
  19 +{
  20 + int i = 0;
  21 + int iRet;
  22 + int iLen = strlen(pszDir);
  23 + if (pszDir[iLen - 1] != '\\' && pszDir[iLen - 1] != '/')
  24 + {
  25 + pszDir[iLen] = '/';
  26 + pszDir[iLen + 1] = '\0';
  27 + }
  28 + iLen = strlen(pszDir);
  29 +
  30 + if (iLen > 2 && ((pszDir[i] == '\\' && pszDir[i + 1] == '\\') || (pszDir[i] == '/' && pszDir[i + 1] == '/')))
  31 + {
  32 + i = 2;
  33 + for (; i <= iLen; i++)
  34 + if (pszDir[i] == '\\' || pszDir[i] == '/')
  35 + break;
  36 +
  37 + i++;
  38 +
  39 + for (; i <= iLen; i++)
  40 + {
  41 + if (pszDir[i] == '\\' || pszDir[i] == '/')
  42 + {
  43 + pszDir[i] = '\0';
  44 + //printf("file access %s\n", pszDir);
  45 + iRet = ACCESS(pszDir, 0);
  46 + //printf("file access %d\n", iRet);
  47 + if (iRet != 0)
  48 + {
  49 + //printf("file mkdir %s\n", pszDir);
  50 + iRet = MKDIR(pszDir);
  51 + //printf("file mkdir %d\n", iRet);
  52 + if (iRet != 0)
  53 + {
  54 + return -1;
  55 + }
  56 + }
  57 + pszDir[i] = '/';
  58 +
  59 + }
  60 + }
  61 + return 0;
  62 + }
  63 +
  64 + if (pszDir[i] != '\\' && pszDir[i] != '/')
  65 + i = 0;
  66 + else
  67 + i = 1;
  68 + for (; i <= iLen; i++)
  69 + {
  70 + if (pszDir[i] == '\\' || pszDir[i] == '/')
  71 + {
  72 + pszDir[i] = '\0';
  73 + iRet = ACCESS(pszDir, 0);
  74 + if (iRet != 0)
  75 + {
  76 + iRet = MKDIR(pszDir);
  77 + if (iRet != 0)
  78 + {
  79 + return -1;
  80 + }
  81 + }
  82 + pszDir[i] = '/';
  83 +
  84 + }
  85 + }
  86 + return 0;
  87 +}
  88 +
  89 +
  90 +void CreateResultFolder(const char* resultFolder, const char* jointFolder)
  91 +{
  92 + if (strlen(resultFolder) > 240) //?too long
  93 + {
  94 + return;
  95 + }
  96 + else if (strlen(resultFolder) < 1) //?too short
  97 + {
  98 + return;
  99 + }
  100 +
  101 + char dir[260];
  102 +
  103 + sprintf(dir, "%s%s/", resultFolder, jointFolder);
  104 + if (CreateDir(dir) != 0)
  105 + {
  106 + return;
  107 + }
  108 +}
  109 +
  110 +#endif // __DEMO_UTIL__
0 111 \ No newline at end of file
... ...
src/reprocessing_module/snapshot_reprocessing.cpp
... ... @@ -121,15 +121,6 @@ void snapshot_reprocessing::update_bestsnapshot(vector&lt;DeviceMemory*&gt; vec_devMem
121 121 total_snapshot_info[new_obj].flags[2] = obj_info.right > frame_width - minDistance[2] - SCALE_OUT ? 0 : 1; //right
122 122 total_snapshot_info[new_obj].flags[3] = obj_info.bottom > frame_height - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom
123 123  
124   - int cur_left = max(obj_info.left - 10, 0);
125   - int cur_top = max(obj_info.top - 10, 0);
126   - int cur_right = min(obj_info.right + 10, frame_width - 1);
127   - int cur_bottom = min(obj_info.bottom + 10, frame_height - 1);
128   - total_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素
129   - total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top);
130   -
131   - total_snapshot_info[new_obj].frameCount = memPtr->getFrameNb();
132   -
133 124 video_object_info info;
134 125 info.left = max(obj_info.left - expansion_width, 0);
135 126 info.top = max(obj_info.top - expansion_height, 0);
... ... @@ -141,6 +132,12 @@ void snapshot_reprocessing::update_bestsnapshot(vector&lt;DeviceMemory*&gt; vec_devMem
141 132 info.index = index;
142 133  
143 134 vec_obj_info.push_back(info);
  135 +
  136 + total_snapshot_info[new_obj].obj_pos = { info.left, info.top, info.right - info.left, info.bottom - info.top }; //debug by zsh 推出的坐标外扩10像素
  137 + total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = (info.right - info.left) * (info.bottom - info.top);
  138 +
  139 + total_snapshot_info[new_obj].frameCount = memPtr->getFrameNb();
  140 +
144 141 } else {
145 142 total_snapshot_info[new_obj].last_area = (obj_info.right - obj_info.left) * (obj_info.bottom - obj_info.top);
146 143  
... ... @@ -164,15 +161,6 @@ void snapshot_reprocessing::update_bestsnapshot(vector&lt;DeviceMemory*&gt; vec_devMem
164 161 total_snapshot_info[new_obj].index.count--;
165 162 }
166 163  
167   - int cur_left = max(obj_info.left - 10, 0);
168   - int cur_top = max(obj_info.top - 10, 0);
169   - int cur_right = min(obj_info.right + 10, frame_width - 1);
170   - int cur_bottom = min(obj_info.bottom + 10, frame_height - 1);
171   - total_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素
172   - total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top);
173   -
174   - total_snapshot_info[new_obj].frameCount = memPtr->getFrameNb();
175   -
176 164 video_object_info info;
177 165 info.left = max(obj_info.left - expansion_width, 0);
178 166 info.top = max(obj_info.top - expansion_height, 0);
... ... @@ -184,6 +172,11 @@ void snapshot_reprocessing::update_bestsnapshot(vector&lt;DeviceMemory*&gt; vec_devMem
184 172 info.index = index;
185 173  
186 174 vec_obj_info.push_back(info);
  175 +
  176 + total_snapshot_info[new_obj].obj_pos = { info.left, info.top, info.right - info.left, info.bottom - info.top }; //debug by zsh 推出的坐标外扩10像素
  177 + total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = (info.right - info.left) * (info.bottom - info.top);
  178 +
  179 + total_snapshot_info[new_obj].frameCount = memPtr->getFrameNb();
187 180 }
188 181 }
189 182  
... ...