Commit 1fa395856fcabddf8f23f8ee90c9bcf2e55f74c3

Authored by Hu Chunming
1 parent 502f9d10

输出结果优化

src/ai_engine_module/VehiclePlate.cpp
... ... @@ -88,9 +88,29 @@ vector<VehiclePlateResult> VehiclePlate::process(vector<DeviceMemory*> vec_gpuMe
88 88 memcpy(res.recg, plate_info.recg, sizeof(PlateNum) * 8);
89 89 res.num_score = plate_info.num_score;
90 90 res.type = plate_info.type;
  91 +
91 92 res.state = plate_info.state;
92 93 res.state_score = plate_info.state_score;
93 94  
  95 + int space_char_num = 0;
  96 + for (size_t i = 0; i < 8; i++)
  97 + {
  98 + if (fabs(res.recg[i].maxprob) < 0.0001) {
  99 + space_char_num++ ;
  100 + }
  101 + }
  102 +
  103 + if (res.state == 0)
  104 + {
  105 + if (space_char_num == 0) {
  106 + res.state = 1;
  107 + res.state_score = res.detect_score;
  108 + } else if (space_char_num > 0 && space_char_num < PLATENUM) {
  109 + res.state = 2;
  110 + res.state_score = res.detect_score;
  111 + }
  112 + }
  113 +
94 114 vec_res.push_back(res);
95 115 }
96 116  
... ...
src/ai_platform/header.h
... ... @@ -46,6 +46,8 @@ typedef struct hp_cls_info //分类结果结构体
46 46 hp_cls_info() : res_index(0), res_prob(0) {};
47 47 } hp_cls_info;
48 48  
  49 +
  50 +static string vechicle_pendant[] = {"车头", "车尾", "车窗", "司机", "人脸", "安全带", "遮阳板", "年检标", "挂件", "纸巾盒", "转经筒", "打电话", "天窗", "行李架", "吸烟", "车前脸", "车后脸", "后视镜", "临时车牌", "车标", "三角标志", "三角危险", "长方形危险"};
49 51 typedef struct VPDInfo
50 52 {
51 53 int left_;
... ... @@ -64,6 +66,8 @@ struct PlateNum
64 66 int index;
65 67 };
66 68  
  69 +static string plate_type[] = {"单排蓝色 ", "单排黄色 ", "单排白色 ", "单排黑色", " 双排黄色 ", "双排白色 ", "新能源黄绿色 ", "新能源白绿色"};
  70 +static string plate_state[] = {"无车牌", " 正常车牌", " 遮挡车牌"};
67 71 struct VehiclePlateResult {
68 72 int left_;
69 73 int top_;
... ... @@ -79,6 +83,8 @@ struct VehiclePlateResult {
79 83 float state_score;//车牌状态置信度
80 84 };
81 85  
  86 +// 0-black 1-blue 2-brown 3-green 4-grey 5-orange 6-pink 7-purple 8-red 9-silver 10-white 11-yellow
  87 +static string vehicle_color[] = {"black", "blue", "brown", "green", "grey", "orange", "pink", "purple", "red", "silver", "white", "yellow"};
82 88 typedef struct ObjectData {
83 89 string task_id; //该物体属于的任务ID号
84 90 int task_frame_count; //该物体当前出现的帧号
... ...
src/demo/demo.cpp
... ... @@ -6,6 +6,8 @@
6 6 #include <stdlib.h>
7 7 #include <unistd.h>
8 8 #include <iostream>
  9 +#include <fstream>
  10 +#include <string>
9 11  
10 12 #include "opencv2/opencv.hpp"
11 13 #include "opencv2/imgcodecs/legacy/constants_c.h"
... ... @@ -164,8 +166,13 @@ string createTask(void *handle, int gi, bool bFlag = true){
164 166  
165 167 void show_result(ObjectData obj)
166 168 {
167   - printf("%s %d \n", obj.task_id.c_str(), obj.task_frame_count);
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);
  169 + string str_dir = "./res/result/";
  170 + string file_name = obj.task_id + "_" + to_string(obj.object_id) + "_" + obj.str_ts_ms;
  171 + string data_file_name = str_dir + file_name + ".txt";
  172 + std::ofstream res_file(data_file_name);
  173 +
  174 + res_file << obj.task_id << " " << obj.task_frame_count << endl;
  175 + res_file << obj.index << " " << obj.object_id << " " << obj.left << " " << obj.top << " " << obj.right << " " << obj.bottom << " " << obj.confidence << endl;
169 176  
170 177 cv::Mat image = cv::imread(obj.ori_pic_path);
171 178  
... ... @@ -175,26 +182,46 @@ void show_result(ObjectData obj)
175 182  
176 183 if (obj.index == 0)
177 184 {// person
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");
  185 + res_file << "person:" << endl;
  186 + res_file << "hair: " << hair[obj.hp_cls[0].res_index] << " " << obj.hp_cls[0].res_prob << endl;
  187 + res_file << "hair_color: " << hair_color[obj.hp_cls[1].res_index] << " " << obj.hp_cls[1].res_prob << endl;
  188 + res_file << "eye_glass: " << eye_glass[obj.hp_cls[2].res_index] << " " << obj.hp_cls[2].res_prob << endl;
  189 + res_file << "mask: " << mask[obj.hp_cls[3].res_index] << " " << obj.hp_cls[3].res_prob << endl;
  190 + res_file << "up cloth: " << up_cloth[obj.hp_cls[4].res_index] << " " << obj.hp_cls[4].res_prob << endl;
  191 + res_file << "up_cloth_color: " << up_cloth_color[obj.hp_cls[5].res_index] << " " << obj.hp_cls[5].res_prob << endl;
  192 + res_file << "clothing context: " << clothing_text[obj.hp_cls[6].res_index] << " " << obj.hp_cls[6].res_prob << endl;
  193 + res_file << "down cloth: " << down_cloth[obj.hp_cls[7].res_index] << " " << obj.hp_cls[7].res_prob << endl;
  194 + res_file << "down cloth color: " << down_cloth_color[obj.hp_cls[8].res_index] << " " << obj.hp_cls[8].res_prob << endl;
  195 + res_file << "bag: " << bag[obj.hp_cls[9].res_index] << " " << obj.hp_cls[9].res_prob << endl;
  196 + res_file << "sex: " << sex[obj.hp_cls[10].res_index] << " " << obj.hp_cls[10].res_prob << endl;
  197 + res_file << "age: " << age[obj.hp_cls[11].res_index] << " " << obj.hp_cls[11].res_prob << endl;
  198 + res_file << "viewpoint: " << viewpoint[obj.hp_cls[12].res_index] << " " << obj.hp_cls[12].res_prob << endl;
  199 + res_file << "umbrella: " << umbrella[obj.hp_cls[13].res_index] << " " << obj.hp_cls[13].res_prob << endl;
  200 + res_file << "hold_baby: " << hold_baby[obj.hp_cls[14].res_index] << " " << obj.hp_cls[14].res_prob << endl;
  201 + res_file << "person state: " << personstate[obj.hp_cls[15].res_index] << " " << obj.hp_cls[15].res_prob << endl;
  202 +
184 203 for (size_t i = 0; i < HUMANREID_FEATURE_SIZE; i++)
185 204 {
186 205 auto hp_cls = obj.hp_feature[i];
187   - printf("%f ", obj.hp_feature[i]);
  206 + res_file << obj.hp_feature[i] << " ";
188 207 }
189   - printf("\n");
  208 + res_file << endl;
190 209 }
191 210 else if (obj.index >= 4 && obj.index <= 8)
192 211 {// vehicle
193   - printf("vehicle color:%d prob:%f \n", obj.vehicle_color_index, obj.vehicle_color_prob);
  212 + res_file << "vehicle:" << endl;
  213 + if (obj.vehicle_color_index >= 0)
  214 + {
  215 + res_file << "color:" << vehicle_color[obj.vehicle_color_index] << " " << obj.vehicle_color_prob << endl;
  216 + }
  217 +
194 218 for (size_t i = 0; i < obj.vec_vpd_cls.size(); i++)
195 219 {
196 220 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_);
  221 + if (info.index >= 0)
  222 + {
  223 + res_file << vechicle_pendant[info.index] << " " << info.confidence << " " << info.left_ << " " << info.top_ << " " << info.width_ << " " << info.height_ << endl;
  224 + }
198 225  
199 226 cv::Rect rc(info.left_, info.top_, info.width_, info.height_);
200 227 const cv::Scalar color(0, 255, 255);
... ... @@ -202,22 +229,24 @@ void show_result(ObjectData obj)
202 229 }
203 230  
204 231 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 );
  232 + res_file << "plate:" << plate_info.left_ << " " << plate_info.top_ << " " << plate_info.width_ << " " << plate_info.height_ << " " << plate_info.detect_score << endl;
206 233 cv::Rect rc(plate_info.left_, plate_info.top_, plate_info.width_, plate_info.height_);
207 234 const cv::Scalar color(0, 255, 0);
208 235 cv::rectangle(image, rc, color);
  236 + res_file << "plate number:" ;
209 237 for (size_t i = 0; i < 8; i++)
210 238 {
211   - printf("%s:%f ", plate_info.recg[i].character, plate_info.recg[i].maxprob);
  239 + res_file << plate_info.recg[i].character << " " << plate_info.recg[i].maxprob << " ";
212 240 }
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);
  241 + res_file << endl;
  242 + res_file << "num_score:" << plate_info.num_score << endl;
  243 + res_file << "type:" << plate_type[plate_info.type] << endl;
  244 + res_file << "state:" << plate_state[plate_info.state] << " " << plate_info.state_score << endl;
217 245 }
218   - printf("\n");
  246 +
  247 + res_file.close();
219 248  
220   - string result_path = "./res/result/" + obj.task_id + "_" + to_string(obj.object_id) + "_" + obj.str_ts_ms + ".jpg";
  249 + string result_path = str_dir + file_name + ".jpg";
221 250 cv::imwrite(result_path, image);
222 251 image.release();
223 252 }
... ...