Commit b30126723b42e89ccf665ba193a6f3d74622f134

Authored by Hu Chunming
1 parent ceb693e9

天啊及hp,road_seg子sdk;完成子SDK的串联

build/src/Makefile
... ... @@ -70,6 +70,7 @@ SRCS := $(wildcard $(CUR_PROJ_PATH)/*.cpp) \
70 70 $(wildcard $(CUR_PROJ_PATH)/common/cnn/*.cpp) \
71 71 $(wildcard $(CUR_PROJ_PATH)/common/dvppx/*.cpp) \
72 72 $(wildcard $(CUR_PROJ_PATH)/common/model_process/*.cpp) \
  73 + $(wildcard $(CUR_PROJ_PATH)/utils/*.cpp) \
73 74  
74 75 DIRS := $(notdir $(SRCS))
75 76 OBJS := $(patsubst %cpp, %o, $(DIRS))
... ... @@ -106,6 +107,9 @@ $(TARGET):$(OBJS)
106 107 %.o:$(CUR_PROJ_PATH)/common/model_process/%.cpp
107 108 $(XX) $(CXXFLAGS) -c $<
108 109  
  110 +%.o:$(CUR_PROJ_PATH)/utils/%.cpp
  111 + $(XX) $(CXXFLAGS) -c $<
  112 +
109 113 clean:
110 114 @rm -f $(TARGET)
111 115 @rm -f $(OBJS)
... ...
src/PicAnalysis.cpp
... ... @@ -60,6 +60,11 @@ int PicAnalysis::init(int dev_id) {
60 60 return -1;
61 61 }
62 62  
  63 + ret = m_crop_util.init(dev_id);
  64 + if(0 != ret){
  65 + return -1;
  66 + }
  67 +
63 68 ACL_CALL(aclrtCreateContext(&m_ctx, 0), ACL_SUCCESS, SY_FAILED);
64 69 ACL_CALL(aclrtSetCurrentContext(m_ctx), ACL_SUCCESS, SY_FAILED);
65 70 ACL_CALL(aclrtCreateStream(&stream), ACL_SUCCESS, SY_FAILED);
... ... @@ -105,7 +110,98 @@ int PicAnalysis::analysis_sync(vector&lt;string&gt; vec_file_path){
105 110 vec_img.push_back(img);
106 111 }
107 112  
108   - m_vehicle_analysis.detect(vec_img);
  113 + va_result* result = m_vehicle_analysis.detect(vec_img);
  114 +
  115 + m_road_seg_algorithm.detect(vec_img);
  116 +
  117 + for (int b = 0; b < batch_size; b++)
  118 + {
  119 + ImageData src = dvpp_data[b];
  120 + for(int c=0;c<result[b].count;c++)
  121 + {
  122 + vehicle_info result_info = result[b].info[c];
  123 + int shot_type=result[b].info[c].type;
  124 +
  125 + // 行人
  126 + if (6 == shot_type)
  127 + {
  128 + sy_rect human_rect = result_info.vehicle_body_detect_res.rect;
  129 + ImageData* human_data = m_crop_util.crop(src, human_rect.left_, human_rect.top_, human_rect.left_ + human_rect.width_, human_rect.top_ + human_rect.height_);
  130 +
  131 + sy_img img;
  132 + img.w_ = human_data->alignWidth;
  133 + img.h_ = human_data->alignHeight;
  134 + img.data_ = human_data->data_naked;
  135 +
  136 + vector<sy_img> vec_human_img;
  137 + vec_human_img.push_back(img);
  138 +
  139 + human_analysis(vec_human_img);
  140 +
  141 + delete human_data;
  142 + human_data = nullptr;
  143 + }
  144 +
  145 + // 司乘
  146 + int vpd_num = result_info.vehicle_pendant_det_res.count;
  147 + vector<sy_img> vec_human_img;
  148 + for(int p=0; p<vpd_num; p++)
  149 + {
  150 + int index = result_info.vehicle_pendant_det_res.vpd_res[p].index;
  151 + if(index == 0){
  152 + sy_rect human_rect = result_info.vehicle_pendant_det_res.vpd_res[p].rect;
  153 + ImageData* human_data = m_crop_util.crop(src, human_rect.left_, human_rect.top_, human_rect.left_ + human_rect.width_, human_rect.top_ + human_rect.height_);
  154 +
  155 + sy_img img;
  156 + img.w_ = human_data->alignWidth;
  157 + img.h_ = human_data->alignHeight;
  158 + img.data_ = human_data->data_naked;
  159 +
  160 + vec_human_img.push_back(img);
  161 + }
  162 + }
  163 +
  164 + m_clothes_algorithm.detect(vec_human_img);
  165 +
  166 + for(int p=0; p<vpd_num; p++)
  167 + {
  168 + int index = result_info.vehicle_pendant_det_res.vpd_res[p].index;
  169 + if(index == 0){
  170 + sy_rect human_rect = result_info.vehicle_pendant_det_res.vpd_res[p].rect;
  171 + }
  172 + }
  173 +
  174 + // 摩托车
  175 + if(shot_type==2)//摩托车
  176 + {
  177 + //摩托车驾驶人是否戴安全帽
  178 + // analysis_result.motor_helmeted = result_info.mta_res.motor_driver_helmeted.status;
  179 + // float score=result_info.mta_res.motor_driver_helmeted.confidence;
  180 +
  181 + sy_rect motor_rect = result_info.vehicle_body_detect_res.rect;
  182 + ImageData* motor_data = m_crop_util.crop(src, motor_rect.left_, motor_rect.top_, motor_rect.left_ + motor_rect.width_, motor_rect.top_ + motor_rect.height_);
  183 +
  184 + sy_img img;
  185 + img.w_ = motor_data->alignWidth;
  186 + img.h_ = motor_data->alignHeight;
  187 + img.data_ = motor_data->data_naked;
  188 +
  189 + vector<sy_img> vec_motor_img;
  190 + vec_motor_img.push_back(img);
  191 +
  192 + m_motor_rainshed_algorithm.detect(vec_motor_img);
  193 +
  194 + m_motor_phone_algorithm.detect(vec_motor_img);
  195 +
  196 + //
  197 +
  198 +
  199 + delete motor_data;
  200 + motor_data = nullptr;
  201 + }
  202 +
  203 + }
  204 + }
109 205  
110 206 vector<HeadTailResult> head_tail_result;
111 207 ret = m_head_tail_algorithm.detect(vec_img, head_tail_result);
... ... @@ -114,17 +210,7 @@ int PicAnalysis::analysis_sync(vector&lt;string&gt; vec_file_path){
114 210 head_tail_result.clear();
115 211 }
116 212  
117   - m_clothes_algorithm.detect(vec_img);
118   -
119   - m_human_algorithm.detect(vec_img);
120   -
121   - m_human_car_algorithm.detect(vec_img);
122   -
123   - m_motor_rainshed_algorithm.detect(vec_img);
124   -
125   - m_motor_phone_algorithm.detect(vec_img);
126   -
127   - m_road_seg_algorithm.detect(vec_img);
  213 +
128 214  
129 215 LOG_INFO("analysis_sync finished!");
130 216  
... ... @@ -149,4 +235,12 @@ int PicAnalysis::release() {
149 235 aclrtDestroyContext(m_ctx);
150 236  
151 237 return 0;
  238 +}
  239 +
  240 +int PicAnalysis::human_analysis(vector<sy_img> vec_img) {
  241 + vector<BodyColorInfo> vec_body_color = m_human_algorithm.detect(vec_img);
  242 +}
  243 +
  244 +int PicAnalysis::check_motor_retrograde_motion(vector<sy_img> vec_motor_img) {
  245 + m_human_car_algorithm.detect(vec_motor_img);
152 246 }
153 247 \ No newline at end of file
... ...
src/PicAnalysis.h
... ... @@ -8,6 +8,8 @@
8 8 #include "./ai_engine_module/MotorPhoneAnalysis.h"
9 9 #include "./ai_engine_module/RoadSegAnalysis.h"
10 10  
  11 +#include "./utils/CropUtil.h"
  12 +
11 13 using namespace std;
12 14  
13 15  
... ... @@ -25,6 +27,11 @@ public:
25 27 int release();
26 28  
27 29 private:
  30 + int human_analysis(vector<sy_img> vec_img);
  31 +
  32 + int check_motor_retrograde_motion(vector<sy_img> vec_img);
  33 +
  34 +private:
28 35 aclrtContext m_ctx{nullptr};
29 36 aclrtStream stream{nullptr};
30 37 DvppProcess* m_dvpp{nullptr};
... ... @@ -37,6 +44,8 @@ private:
37 44 MotorRainshedAnalysis m_motor_rainshed_algorithm;
38 45 MotorPhoneAnalysis m_motor_phone_algorithm;
39 46 RoadSegAnalysis m_road_seg_algorithm;
  47 +
  48 + CropUtil m_crop_util;
40 49 };
41 50  
42 51  
... ...
src/ai_engine_module/HumanAnalysis.cpp
1 1 #include "HumanAnalysis.h"
2 2  
  3 +static std::string body_colors[] = { "黑", "白", "灰", "红", "蓝", "黄", "绿", "多色", "其他" };
  4 +
3 5 HumanAnalysis::HumanAnalysis(/* args */)
4 6 {
5 7 }
... ... @@ -28,27 +30,35 @@ int HumanAnalysis::init(int devId){
28 30 return SY_SUCCESS;
29 31 }
30 32  
31   -int HumanAnalysis::detect(vector<sy_img> vec_img){
32   -
33   - ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);
  33 +vector<BodyColorInfo> HumanAnalysis::detect(vector<sy_img> vec_img){
34 34  
35 35 const int batchsize = vec_img.size();
36 36 hp_analysis_res * results = new hp_analysis_res[batchsize];
37 37  
38 38 int ret = SY_FAILED;
  39 + vector<BodyColorInfo> vec_body_color;
39 40  
40 41 do
41 42 {
  43 + ret = aclrtSetCurrentContext(ctx);
  44 + if (SY_SUCCESS != ret) {
  45 + printf("aclrtSetCurrentContext failed!");
  46 + break;
  47 + }
  48 +
42 49 ret = hp_batch(m_handle, vec_img.data(), batchsize, results);
43 50 if (SY_SUCCESS != ret) {
44 51 printf("hp_batch failed!");
45 52 break;
46 53 }
47 54  
48   - for(int batchIdx = 0;batchIdx<batchsize;batchIdx++) {
49   - for (int i = 0; i < HP_ATTRI_INDEX_SIZE; i++) {
50   - printf("hp index:%d,confidence:%f\n",results[batchIdx].res_objs[i].res_index,results[batchIdx].res_objs[i].res_prob);
51   - }
  55 + for(int batchIdx = 0;batchIdx<batchsize;batchIdx++) {
  56 + BodyColorInfo info;
  57 + info.upper_body_color = results[batchIdx].res_objs[5].res_index;
  58 + info.lower_body_color = results[batchIdx].res_objs[8].res_index;
  59 + printf("upper color:%s, lower color:%s\n",body_colors[info.upper_body_color], body_colors[info.lower_body_color]);
  60 +
  61 + vec_body_color.push_back(info);
52 62 }
53 63 } while (0);
54 64  
... ... @@ -56,7 +66,7 @@ int HumanAnalysis::detect(vector&lt;sy_img&gt; vec_img){
56 66 delete [] results;
57 67 }
58 68  
59   - return ret;
  69 + return vec_body_color;
60 70 }
61 71  
62 72 int HumanAnalysis::release() {
... ...
src/ai_engine_module/HumanAnalysis.h
1 1 #include "include.h"
2 2 #include "human_parsing.h"
3 3  
  4 +struct BodyColorInfo{
  5 + int upper_body_color;
  6 + int lower_body_color;
  7 +};
  8 +
4 9 class HumanAnalysis
5 10 {
6 11 public:
... ... @@ -9,7 +14,7 @@ public:
9 14  
10 15 int init(int devId);
11 16  
12   - int detect(vector<sy_img> vec_img);
  17 + vector<BodyColorInfo> detect(vector<sy_img> vec_img);
13 18  
14 19 private:
15 20 int release();
... ...
src/ai_engine_module/RoadSegAnalysis.cpp
... ... @@ -55,8 +55,10 @@ int RoadSegAnalysis::detect(vector&lt;sy_img&gt; vec_img){
55 55 } while (0);
56 56  
57 57 for (int b = 0; b < batchsize; b++) {
58   - delete[] results[b].seg_array; results[b].seg_array = NULL;
59   - delete[] results[b].direct_seg; results[b].direct_seg = NULL;
  58 + delete[] results[b].seg_array;
  59 + results[b].seg_array = NULL;
  60 + delete[] results[b].direct_seg;
  61 + results[b].direct_seg = NULL;
60 62 }
61 63  
62 64 return ret;
... ...
src/ai_engine_module/VehicleAnalysis.cpp
... ... @@ -67,7 +67,7 @@ int VehicleAnalysis::init(int devId, int max_batch_size) {
67 67 return 0;
68 68 }
69 69  
70   -int VehicleAnalysis::detect(vector<sy_img> vec_img) {
  70 +va_result * VehicleAnalysis::detect(vector<sy_img> vec_img) {
71 71  
72 72 int batch_size = vec_img.size();
73 73  
... ... @@ -83,514 +83,207 @@ int VehicleAnalysis::detect(vector&lt;sy_img&gt; vec_img) {
83 83 }
84 84  
85 85 int ret = va_batch(m_handle, vec_img.data(), batch_size, result);
  86 +
  87 + vector<VehicleAnalysisResult> vec_result;
86 88  
87 89 for (int b = 0; b < batch_size; b++)
88   - {
89   - if(param.vehicle_detect_config==SY_CONFIG_CLOSE)//不做车头检测时,应设result[b].count=1,即输入是车头图像,只含1辆车。
90   - result[b].count=1;
91   -
92   - //oFile << file << ","<< result[b].count<< "," <<endl;;
93   - std::cout <<"car_count:" <<result[b].count<< std::endl;
  90 + {
94 91 for(int c=0;c<result[b].count;c++)
95   - {
  92 + {
  93 + vehicle_info result_info = result[b].info[c];
  94 +
  95 + VehicleAnalysisResult analysis_result;
  96 +
96 97 std::string str_vehicle_type;
97   - int vehicle_type=result[b].info[c].type;
98   - //std::cout << "vehicle_type="<<vehicle_type<< std::endl;
99   - if (vehicle_type==0)str_vehicle_type = "head";
100   - else if (vehicle_type==1)str_vehicle_type = "rear";
101   - else if (vehicle_type==2)str_vehicle_type = "motor";
102   - else if (vehicle_type==3)str_vehicle_type = "tricycle";
103   - else if (vehicle_type==4)str_vehicle_type = "body";
104   - else if (vehicle_type==5)str_vehicle_type = "body_nova";
105   - std::cout << " vehicle_type:"<<str_vehicle_type<< std::endl;
106   -
107   - //1.车头结果:蓝框//2.车窗结果:绿框
  98 + int shot_type=result_info.type;
  99 + if (shot_type==0)str_vehicle_type = "head";
  100 + else if (shot_type==1)str_vehicle_type = "rear";
  101 + else if (shot_type==2)str_vehicle_type = "motor";
  102 + else if (shot_type==3)str_vehicle_type = "tricycle";
  103 + else if (shot_type==4)str_vehicle_type = "body";
  104 + else if (shot_type==5)str_vehicle_type = "body_nova";
  105 +
  106 + analysis_result.shot_type = shot_type;
  107 +
  108 + //1.车头结果:蓝框//2.车窗结果:绿框
108 109 if(param.vehicle_detect_config==SY_CONFIG_OPEN)
109   - {
  110 + {
110 111 //车身
111 112 //std::cout << "vehicle_body_detect_res info:"<< std::endl;
112   - if(result[b].info[c].vehicle_body_detect_res.rect.width_>0)
  113 + if(result_info.vehicle_body_detect_res.rect.width_>0)
113 114 {
114   - float vehicle_body_detect_res_score = result[b].info[c].vehicle_body_detect_res.score;
115   - int x1=result[b].info[c].vehicle_body_detect_res.rect.left_;
116   - int y1=result[b].info[c].vehicle_body_detect_res.rect.top_;
117   - int x2=result[b].info[c].vehicle_body_detect_res.rect.left_+result[b].info[c].vehicle_body_detect_res.rect.width_;
118   - int y2=result[b].info[c].vehicle_body_detect_res.rect.top_+result[b].info[c].vehicle_body_detect_res.rect.height_;
  115 + float vehicle_body_detect_res_score = result_info.vehicle_body_detect_res.score;
  116 + int x1=result_info.vehicle_body_detect_res.rect.left_;
  117 + int y1=result_info.vehicle_body_detect_res.rect.top_;
  118 + int x2=result_info.vehicle_body_detect_res.rect.left_+result_info.vehicle_body_detect_res.rect.width_;
  119 + int y2=result_info.vehicle_body_detect_res.rect.top_+result_info.vehicle_body_detect_res.rect.height_;
119 120 std::cout << " vehicle_body_detect_res_score:" <<vehicle_body_detect_res_score<<",car_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl;
120 121  
121   - // Point lt(x1, y1);
122   - // Point rb(x2, y2);
123   - // rectangle(cvImg, lt, rb, cv::Scalar(0, 255,255), 4);
  122 + analysis_result.vehicle_rect = result_info.vehicle_body_detect_res.rect;
124 123 }
125 124  
126   - //车头
127   - //std::cout << "vehicle_detect_res info:"<< std::endl;
128   - if(result[b].info[c].vehicle_detect_res.rect.width_>0)
129   - {
130   - float vehicle_detect_res_score = result[b].info[c].vehicle_detect_res.score;
131   - int x1=result[b].info[c].vehicle_detect_res.rect.left_;
132   - int y1=result[b].info[c].vehicle_detect_res.rect.top_;
133   - int x2=result[b].info[c].vehicle_detect_res.rect.left_+result[b].info[c].vehicle_detect_res.rect.width_;
134   - int y2=result[b].info[c].vehicle_detect_res.rect.top_+result[b].info[c].vehicle_detect_res.rect.height_;
135   - std::cout << " vehicle_detect_res_score:" <<vehicle_detect_res_score<<",car_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl;
136   -
137   - // Point lt(x1, y1);
138   - // Point rb(x2, y2);
139   - // rectangle(cvImg, lt, rb, cv::Scalar(255, 0, 0), 4);
140   - }
141   -
142   - //车窗
143   - //std::cout << "vwd output----"<< std::endl;
144   - if(result[b].info[c].vehicle_win_detect_res.rect.width_>0)
145   - {
146   - float vehicle_win_detect_res_score = result[b].info[c].vehicle_win_detect_res.score;
147   - int x1=result[b].info[c].vehicle_win_detect_res.rect.left_;
148   - int y1=result[b].info[c].vehicle_win_detect_res.rect.top_;
149   - int x2=result[b].info[c].vehicle_win_detect_res.rect.left_+result[b].info[c].vehicle_win_detect_res.rect.width_;
150   - int y2=result[b].info[c].vehicle_win_detect_res.rect.top_+result[b].info[c].vehicle_win_detect_res.rect.height_;
151   - std::cout << " vehicle_win_detect_res_score:" <<vehicle_win_detect_res_score<<",win_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl;
152   -
153   - // Point lt(x1, y1);
154   - // Point rb(x2, y2);
155   - // rectangle(cvImg, lt, rb, cv::Scalar(0, 255, 0), 4);
156   - }
157   - }
158   -
159   -
160   - //3.车颜色
161   - if(param.vehicle_color_config==SY_CONFIG_OPEN&& (vehicle_type==0 || vehicle_type==1 || vehicle_type==4))
162   - {
163   - //std::cout << "vc output----"<< std::endl;
164   - int index=result[b].info[c].vehicle_color_res.index;
165   - float score=result[b].info[c].vehicle_color_res.score;
  125 + // //车头
  126 + // if(result_info.vehicle_detect_res.rect.width_>0)
  127 + // {
  128 + // float vehicle_detect_res_score = result_info.vehicle_detect_res.score;
  129 + // int x1=result_info.vehicle_detect_res.rect.left_;
  130 + // int y1=result_info.vehicle_detect_res.rect.top_;
  131 + // int x2=result_info.vehicle_detect_res.rect.left_+result_info.vehicle_detect_res.rect.width_;
  132 + // int y2=result_info.vehicle_detect_res.rect.top_+result_info.vehicle_detect_res.rect.height_;
  133 + // std::cout << " vehicle_detect_res_score:" <<vehicle_detect_res_score<<",car_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl;
  134 +
  135 + // }
166 136  
167   - if(score>0.5)
168   - {
169   - std::cout << " car color info:"<< endl;
170   - std::cout << " index:"<< index<<" score:"<< score<< std::endl;
171   -
172   - // std::string str_i = CARCOLOR1[index];
173   - // cv::putText(cvImg, str_i,
174   - // cv::Point(result[b].info[c].vehicle_body_detect_res.rect.left_+5, result[b].info[c].vehicle_body_detect_res.rect.top_+50),
175   - // cv::FONT_HERSHEY_COMPLEX_SMALL,
176   - // 1.3,
177   - // cv::Scalar(0, 0, 255),
178   - // 2);
179   - }
  137 + // //车窗
  138 + // if(result_info.vehicle_win_detect_res.rect.width_>0)
  139 + // {
  140 + // float vehicle_win_detect_res_score = result_info.vehicle_win_detect_res.score;
  141 + // int x1=result_info.vehicle_win_detect_res.rect.left_;
  142 + // int y1=result_info.vehicle_win_detect_res.rect.top_;
  143 + // int x2=result_info.vehicle_win_detect_res.rect.left_+result_info.vehicle_win_detect_res.rect.width_;
  144 + // int y2=result_info.vehicle_win_detect_res.rect.top_+result_info.vehicle_win_detect_res.rect.height_;
  145 + // std::cout << " vehicle_win_detect_res_score:" <<vehicle_win_detect_res_score<<",win_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl;
  146 +
  147 + // }
180 148 }
181   -
182   -
  149 +
183 150 //4.VR车型识别
184   - if(param.vehicle_recg_config==SY_CONFIG_OPEN && (vehicle_type==0 || vehicle_type==1 || vehicle_type==4 ))
  151 + if(param.vehicle_recg_config==SY_CONFIG_OPEN && (shot_type==0 || shot_type==1 || shot_type==4 ))
185 152 {
186   - //std::cout << "vr output----"<< std::endl;
187   -
188   - char *vehicle_brand=result[b].info[c].vehicle_recg_res.vehicle_brand;//车辆品牌
189   - char* vehicle_subbrand=result[b].info[c].vehicle_recg_res.vehicle_subbrand; //车辆子品牌
190   - char* vehicle_issue_year=result[b].info[c].vehicle_recg_res.vehicle_issue_year; //车辆年款
191   - char* vehicle_type_=result[b].info[c].vehicle_recg_res.vehicle_type; //车辆类型
192   - char* freight_ton=result[b].info[c].vehicle_recg_res.freight_ton; //货车吨级
193   - float name_score=result[b].info[c].vehicle_recg_res.name_score; //识别置信度
  153 + char *vehicle_brand=result_info.vehicle_recg_res.vehicle_brand;//车辆品牌
  154 + char* vehicle_subbrand=result_info.vehicle_recg_res.vehicle_subbrand; //车辆子品牌
  155 + char* vehicle_issue_year=result_info.vehicle_recg_res.vehicle_issue_year; //车辆年款
  156 + char* vehicle_type_=result_info.vehicle_recg_res.vehicle_type; //车辆类型
  157 + char* freight_ton=result_info.vehicle_recg_res.freight_ton; //货车吨级
  158 + float name_score=result_info.vehicle_recg_res.name_score; //识别置信度
194 159  
195 160 float name_score_thre = 0;
196   - //if(vehicle_type==0)name_score_thre=0.7;//车头车型识别建议阈值0.7
197   - //if(vehicle_type==1)name_score_thre=0.8;//车尾车型识别建议阈值0.8
  161 + //if(shot_type==0)name_score_thre=0.7;//车头车型识别建议阈值0.7
  162 + //if(shot_type==1)name_score_thre=0.8;//车尾车型识别建议阈值0.8
198 163 if(name_score > name_score_thre)
199 164 {
200   - cout << " vehicle_recg info: " << endl;
201   - std::cout << " name_score: " << name_score << std::endl;
202   - std::cout << " vehicle_brand: " << vehicle_brand << std::endl;
203   - std::cout << " vehicle_subbrand: " << vehicle_subbrand << std::endl;
204   - std::cout << " vehicle_issue_year: " << vehicle_issue_year << std::endl;
205   - std::cout << " vehicle_type_: " << vehicle_type_ << std::endl;
206   - std::cout << " freight_ton: " << freight_ton << std::endl;
207   -
208   - //printf("name_score:%f\n", name_score);
209   - //printf("vehicle_brand:%s\n", vehicle_brand);
210   - //printf("vehicle_subbrand:%s\n", vehicle_subbrand);
211   - //printf("vehicle_issue_year:%s\n", vehicle_issue_year);
212   - //printf("vehicle_type_:%s\n", vehicle_type_);
213   - //printf("freight_ton:%s\n", freight_ton);
  165 + analysis_result.vehicle_type = vehicle_type_;
214 166 }
215   -
  167 + } else {
  168 + analysis_result.vehicle_type = str_vehicle_type;
216 169 }
217   -
218   -
  170 + std::cout << "vehicle_type_: " << analysis_result.vehicle_type << std::endl;
  171 +
219 172 //5.VP车牌检测识别
220   - if(param.vehicle_plate_det_recg_config==SY_CONFIG_OPEN && (vehicle_type==0 || vehicle_type==1))
  173 + if(param.vehicle_plate_det_recg_config==SY_CONFIG_OPEN && (shot_type==0 || shot_type==1))
221 174 {
  175 + vplate_results plate_result = result_info.vehicle_plate_det_recg_res;
222 176 std::cout << " car plate info:"<< endl;
223   - int special_type=result[b].info[c].vehicle_plate_det_recg_res.special_type;//常规车牌、临时车牌、低速车牌。0-common,1-temporary_license_plate,2-low_speed_license_plate.
  177 + int special_type=plate_result.special_type;//常规车牌、临时车牌、低速车牌。0-common,1-temporary_license_plate,2-low_speed_license_plate.
224 178 std::cout << " special_type:" << special_type<< std::endl;
225 179  
226   - float detect_score=result[b].info[c].vehicle_plate_det_recg_res.detect_score;
227   - //std::cout << "detect_score:" << detect_score<< std::endl;
  180 + float detect_score=plate_result.detect_score;
228 181 if(detect_score>0.3)
229   - {
230   - int type=result[b].info[c].vehicle_plate_det_recg_res.type;
231   - sy_rect rect=result[b].info[c].vehicle_plate_det_recg_res.rect;
232   -
233   - int x1=rect.left_;
234   - int y1=rect.top_;
235   - int x2=rect.left_+rect.width_;
236   - int y2=rect.top_+rect.height_;
237   - std::cout << " vp_type:"<<type<<",vp_det_score:" <<detect_score <<",vp_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl;
238   -
239   - // Point lt(x1, y1);
240   - // Point rb(x2, y2);
241   - // rectangle(cvImg, lt, rb, cv::Scalar(0, 0, 255), 4);
242   -
243   -
244   -
  182 + {
245 183 //车牌识别结果
246   - float num_score=result[b].info[c].vehicle_plate_det_recg_res.num_score;
247 184 std::string plate_recg="";
  185 + std::string character_prob;
248 186 //if(num_score>0.99)//车牌识别建议置信度阈值0.99
249 187 {
250 188  
251   - //printf("plate: ");
252 189 for (int m = 0; m < PLATENUM; m++)
253 190 {
254   - //printf("%s", result[b].info[c].vehicle_plate_det_recg_res.recg[m].character);
255   - plate_recg=plate_recg + result[b].info[c].vehicle_plate_det_recg_res.recg[m].character;
  191 + plate_recg=plate_recg + plate_result.recg[m].character;
  192 + character_prob += std::string(plate_result.recg[m].character) + "-" + std::to_string(plate_result.recg[m].maxprob) + ",";
256 193 }
257   - //printf("\n");
258   -
259   - //printf("maxprob: ");
260   - //for (int m = 0; m < PLATENUM; m++)
261   - //{
262   - // printf("%f ", result[b].info[c].vehicle_plate_det_recg_res.vehicle_plate_infos[0].recg[m].maxprob);
263   - //}
264   - //printf("\n");
265   -
266   -
267   - //std::cout << "type:" << type<<" num_score:" <<num_score<<" " << std::endl;
268   - std::cout <<" "<<plate_recg<< ",vp_num_score:" << num_score<< std::endl;
269   -
270 194 }
271   -
272   -
273   - char str_cc[100];
274   - memset(str_cc, 0, sizeof(str_cc));
275   - cv::Point2f p1;
276   - p1.x = x1;
277   - p1.y = y1-60;
278   - //sprintf(str_cc, "det_%.2f_recg_%.2f_%s",detectScore,numScore,plate_recg.c_str());
279   - sprintf(str_cc, "det_%.2f",detect_score);
280   - // cv::putText(cvImg, str_cc,
281   - // p1,
282   - // cv::FONT_HERSHEY_COMPLEX_SMALL,
283   - // 1.3,
284   - // cv::Scalar(0, 0, 255),
285   - // 2);
286   -
287   - memset(str_cc, 0, sizeof(str_cc));
288   - p1.x = x1;
289   - p1.y = y1-30;
290   - sprintf(str_cc, "recg_%.2f",num_score);
291   - // cv::putText(cvImg, str_cc,
292   - // p1,
293   - // cv::FONT_HERSHEY_COMPLEX_SMALL,
294   - // 1.3,
295   - // cv::Scalar(0, 0, 255),
296   - // 2);
297   -
298   - memset(str_cc, 0, sizeof(str_cc));
299   - p1.x = x1;
300   - p1.y = y1;
301   - sprintf(str_cc, "%s",plate_recg.c_str());
302   - // cv::putText(cvImg, str_cc,
303   - // p1,
304   - // cv::FONT_HERSHEY_COMPLEX_SMALL,
305   - // 1.3,
306   - // cv::Scalar(0, 0, 255),
307   - // 2);
308 195  
  196 + analysis_result.plate_det_score = plate_result.detect_score;
  197 + analysis_result.plate_rect = plate_result.rect;//车牌检测坐标
  198 + analysis_result.plate_type = plate_result.type; //车牌类型:0-单排蓝色 1-单排黄色 2-单排白色 3-单排黑色 4-双排黄色 5-双排白色 6-新能源黄绿色 7-新能源白绿色
  199 + analysis_result.plate_num = plate_recg;
  200 + analysis_result.character_prob = character_prob;
  201 + analysis_result.plate_num_score = plate_result.num_score;//识别置信度
  202 + // analysis_result.special_type; //常规车牌、临时车牌、低速车牌。0-common,1-temporary_license_plate,2-low_speed_license_plate.
309 203 }
310 204  
311 205 }
312   -
  206 +
313 207 //6.车属性结果:
314   - if(param.vehicle_pendant_det_config==SY_CONFIG_OPEN && (vehicle_type==0|| vehicle_type==4))
  208 + if(param.vehicle_pendant_det_config==SY_CONFIG_OPEN && (shot_type==0|| shot_type==4))
315 209 {
316 210 std::cout << " vehicle_pendant_det_res info:"<< endl;
317   - int vpd_num = result[b].info[c].vehicle_pendant_det_res.count;
  211 + int vpd_num = result_info.vehicle_pendant_det_res.count;
318 212 //std::cout << vpd_num<< std::endl;
319 213 std::cout << " vpd_num:"<<vpd_num<< endl;
320 214 for(int p=0; p<vpd_num; p++)
321 215 {
322   - int index = result[b].info[c].vehicle_pendant_det_res.vpd_res[p].index;
323   - float detect_score = result[b].info[c].vehicle_pendant_det_res.vpd_res[p].confidence;
324   - int driver_copilot_info = result[b].info[c].vehicle_pendant_det_res.vpd_res[p].driver_copilot_info;
325   - int x1=result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.left_;
326   - int y1=result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.top_;
327   - int x2=result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.left_+result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.width_;
328   - int y2=result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.top_+result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.height_;
329   -
330   - //std::cout <<p<<" ["<<x1<<" "<<y1<<" "<<x2-x1<<" "<<y2-y1<<"] "<<detectScore<<" "<<index<<" "<<driver_copilot_info<< std::endl;
331   - std::cout << " vpd id:"<<p<<" index:"<<index<<",vpd_det_score:" <<detect_score <<",vpd_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<<" driver_copilot_info:"<<driver_copilot_info<< std::endl;
332   -
333   -
334   - // Point lt(x1, y1);
335   - // Point rb(x2, y2);
336   - // rectangle(cvImg, lt, rb, cv::Scalar(255, 255, 0), 4);
337   -
338   - //车属性人脸特征
339   - //f(index ==1)//人脸
340   - //{
341   - // std::cout << " vpd face feature:[";
342   - // /*for(int f=0;f<VPD_FACE_FEATURESIZE;f++)
343   - // {
344   - // float fea = result[b].info[c].vehicle_pendant_det_res.vpd_res[p].feature[f];
345   - // //std::cout << "feature "<<f<<":"<<fea<<std::endl;
346   - // std::cout <<fea<< " ";
347   - // }*/
348   - // std::cout << "]"<< std::endl;
349   - // //std::cout << "face feature:"<<result[b].info[c].vehicle_pendant_det_res.vpd_res[p].feature[0]<<" "<<result[b].info[c].vehicle_pendant_det_res.vpd_res[p].feature[1]<<" "<<result[b].info[c].vehicle_pendant_det_res.vpd_res[p].feature[2]<<std::endl;
350   - //}
351   - }
352   - }
353   -
354   - //7.VID车违规结果-----------
355   - if(param.vehicle_illegal_config==SY_CONFIG_OPEN && vehicle_type==0)
356   - {
357   - std::cout << " vehicle_illegal_det_res info:"<< endl;
358   - vid_result cur_result = result[b].info[c].vehicle_illegal_det_res;
359   - //副驾驶copilot
360   - {
361   - //有人没人判断,阈值0.6
362   - std::string str_person="UNCERTAINTY";
363   - if(cur_result.copilot.person.status==SOMEBODY)
364   - str_person ="PERSON";
365   - else if(cur_result.copilot.person.status==NOBODY)
366   - str_person ="NOPERSON";
367   - //cv::putText(batch_mat[b], str_person,
368   - // cv::Point(5, 25),
369   - // cv::FONT_HERSHEY_COMPLEX_SMALL,
370   - // 1.3,
371   - // cv::Scalar(255, 0, 0),
372   - // 2);
373   -
374   - //打电话,阈值0.9
375   - std::string str_call="UNCERTAINTY";
376   - if(cur_result.copilot.call.status==lEGAL)
377   - str_call ="lEGAL";//str_call ="NOCALL";
378   - else if(cur_result.copilot.call.status==ILLEGAL)
379   - str_call ="ILLEGAL";//str_call ="CALL";
380   - //cv::putText(batch_mat[b], str_call,
381   - // cv::Point(5, 50),
382   - // cv::FONT_HERSHEY_COMPLEX_SMALL,
383   - // 1.3,
384   - // cv::Scalar(255, 0, 0),
385   - // 2);
386   -
387   - //使用电话、阈值0.89
388   - std::string str_phone="UNCERTAINTY";
389   - if(cur_result.copilot.phone.status==lEGAL)
390   - str_phone ="lEGAL";//str_phone ="NOPHONE";
391   - else if(cur_result.copilot.phone.status==ILLEGAL)
392   - str_phone ="ILLEGAL";//str_phone ="USEPHONE";
393   - //cv::putText(batch_mat[b], str_phone,
394   - // cv::Point(5, 75),
395   - // cv::FONT_HERSHEY_COMPLEX_SMALL,
396   - // 1.3,
397   - // cv::Scalar(255, 0, 0),
398   - // 2);
399   -
400   - //系安全带,阈值0.5
401   - std::string str_belt="UNCERTAINTY";
402   - if(cur_result.copilot.belt.status==lEGAL)
403   - str_belt ="lEGAL";//str_belt ="SAFETYBELT";
404   - else if(cur_result.copilot.belt.status==ILLEGAL)
405   - str_belt ="ILLEGAL";
406   -
407   - //cv::putText(batch_mat[b], str_belt,
408   - // cv::Point(5, 75),
409   - // cv::FONT_HERSHEY_COMPLEX_SMALL,
410   - // 1.3,
411   - // cv::Scalar(255, 0, 0),
412   - // 2);
413   -
414   - //抽烟,阈值0.9
415   - std::string str_smoke="UNCERTAINTY";
416   - if(cur_result.copilot.smoke.status==ILLEGAL)
417   - str_smoke ="ILLEGAL";//str_smoke ="SMOKE";
418   - else if(cur_result.copilot.smoke.status==lEGAL)
419   - str_smoke ="lEGAL";//str_smoke ="NOSMOKE";
420   - //cv::putText(batch_mat[b], str_smoke,
421   - // cv::Point(5, 100),
422   - // cv::FONT_HERSHEY_COMPLEX_SMALL,
423   - // 1.3,
424   - // cv::Scalar(255, 0, 0),
425   - // 2);
426   -
427   - //std::cout << "copilot: "<<str_person<< " "<<str_call<< " "<<str_phone<< " "<<str_belt<< " "<<str_smoke<< std::endl;
428   - //std::cout << "copilot confidence: "<<cur_result.copilot.person.confidence<< " "<<cur_result.copilot.call.confidence<< " "<<cur_result.copilot.phone.confidence<< " "<<cur_result.copilot.belt.confidence<< " "<<cur_result.copilot.smoke.confidence<< std::endl;
429   - std::cout << " copilot: "<<"person:"<<str_person<< " call:"<<str_call<< " phone:"<<str_phone<< " belt:"<<str_belt<< " smoke:"<<str_smoke<< std::endl;
430   - std::cout << " copilot confidence: "<<"person:"<<cur_result.copilot.person.confidence<< " call:"<<cur_result.copilot.call.confidence<< " phone:"<<cur_result.copilot.phone.confidence<< " belt:"<<cur_result.copilot.belt.confidence<< " smoke:"<<cur_result.copilot.smoke.confidence<< std::endl;
431   -
432   - }
433   -
434   - //驾驶driver
435   - {
436   - //有人没人判断,阈值0.6
437   - std::string str_person="UNCERTAINTY";
438   - if(cur_result.driver.person.status==SOMEBODY)
439   - str_person ="PERSON";
440   - else if(cur_result.driver.person.status==NOBODY)
441   - str_person ="NOPERSON";
442   - //cv::putText(batch_mat[b], str_person,
443   - // cv::Point(5, 150),
444   - // cv::FONT_HERSHEY_COMPLEX_SMALL,
445   - // 1.3,
446   - // cv::Scalar(255, 0, 0),
447   - // 2);
448   -
449   - //打电话,阈值0.9
450   - std::string str_call="UNCERTAINTY";
451   - if(cur_result.driver.call.status==lEGAL)
452   - str_call ="lEGAL";//str_call ="NOCALL";
453   - else if(cur_result.driver.call.status==ILLEGAL)
454   - str_call ="ILLEGAL";//str_call ="CALL";
455   - //cv::putText(batch_mat[b], str_call,
456   - // cv::Point(5, 175),
457   - // cv::FONT_HERSHEY_COMPLEX_SMALL,
458   - // 1.3,
459   - // cv::Scalar(255, 0, 0),
460   - // 2);
461   -
462   - //使用电话,阈值0.89
463   - std::string str_phone="UNCERTAINTY";
464   - if(cur_result.driver.phone.status==lEGAL)
465   - str_phone ="lEGAL";//str_phone ="NOPHONE";
466   - else if(cur_result.driver.phone.status==ILLEGAL)
467   - str_phone ="ILLEGAL";//str_phone ="USEPHONE";
468   - //cv::putText(batch_mat[b], str_phone,
469   - // cv::Point(5, 200),
470   - // cv::FONT_HERSHEY_COMPLEX_SMALL,
471   - // 1.3,
472   - // cv::Scalar(255, 0, 0),
473   - // 2);
474   -
475   - //系安全带,阈值0.5
476   - std::string str_belt="UNCERTAINTY";
477   - if(cur_result.driver.belt.status==lEGAL)
478   - str_belt ="lEGAL";//str_belt ="SAFETYBELT";
479   - else if(cur_result.driver.belt.status==ILLEGAL)
480   - str_belt ="ILLEGAL";//str_belt ="NOSAFETYBELT";
481   -
482   - //cv::putText(batch_mat[b], str_belt,
483   - // cv::Point(5, 200),
484   - // cv::FONT_HERSHEY_COMPLEX_SMALL,
485   - // 1.3,
486   - // cv::Scalar(255, 0, 0),
487   - // 2);
488   -
489   - //抽烟,阈值0.9
490   - std::string str_smoke="UNCERTAINTY";
491   - if(cur_result.driver.smoke.status==ILLEGAL)
492   - str_smoke ="ILLEGAL";//str_smoke ="SMOKE";
493   - else if(cur_result.driver.smoke.status==lEGAL)
494   - str_smoke ="lEGAL";//str_smoke ="NOSMOKE";
495   - //cv::putText(batch_mat[b], str_smoke,
496   - // cv::Point(5, 225),
497   - // cv::FONT_HERSHEY_COMPLEX_SMALL,
498   - // 1.3,
499   - // cv::Scalar(255, 0, 0),
500   - // 2);
501   -
502   - //std::cout << "driver: "<<str_person<< " "<<str_call<< " "<<str_phone<< " "<<str_belt<< " "<<str_smoke<< std::endl;
503   - //std::cout << "driver confidence: "<<cur_result.driver.person.confidence<< " "<<cur_result.driver.call.confidence<< " "<<cur_result.driver.phone.confidence<< " "<<cur_result.driver.belt.confidence<< " "<<cur_result.driver.smoke.confidence<< std::endl;
504   - std::cout << " driver: person:"<<str_person<< " call:"<<str_call<< " phone:"<<str_phone<< " belt:"<<str_belt<< " smoke:"<<str_smoke<< std::endl;
505   - std::cout << " driver confidence: person:"<<cur_result.driver.person.confidence<< " call:"<<cur_result.driver.call.confidence<< " phone:"<<cur_result.driver.phone.confidence<< " belt:"<<cur_result.driver.belt.confidence<< " smoke:"<<cur_result.driver.smoke.confidence<< std::endl;
506   -
507   - }
508   - }
509   -
510   - //8.车特征
511   - if(param.vehicle_feature_config==SY_CONFIG_OPEN && (vehicle_type==0 || vehicle_type==1))
512   - {
513   - std::cout << " vehicle_fea_res info: "<<std::endl;
514   - std::cout << " [";
515   - for(int f=0;f<VA_FEATURESIZE;f++)
516   - {
517   - float fea=result[b].info[c].vehicle_fea_res.feature[f];
518   - //std::cout << "feature "<<f<<":"<<fea<<std::endl;
519   - std::cout <<fea<<" ";
  216 + int index = result_info.vehicle_pendant_det_res.vpd_res[p].index;
  217 + if(index == 0){
  218 + DriverInfo info;
  219 + info.driver_rect = result_info.vehicle_pendant_det_res.vpd_res[p].rect;
  220 + info.driver_prob = result_info.vehicle_pendant_det_res.vpd_res[p].confidence;
  221 + analysis_result.vec_drivers.push_back(info);
  222 + }
520 223 }
521   - std::cout <<"]"<<std::endl;
522   - //std::cout << "feature 0 :"<<result[b].info[c].vehicle_fea_res.feature[0]<<std::endl;
523   - //std::cout << "feature 1 :"<<result[b].info[c].vehicle_fea_res.feature[1]<<std::endl;
524   - //std::cout << "feature 2 :"<<result[b].info[c].vehicle_fea_res.feature[2]<<std::endl;
525   - //std::cout << "feature 3 :"<<result[b].info[c].vehicle_fea_res.feature[3]<<std::endl;
526   - //std::cout << "feature 4 :"<<result[b].info[c].vehicle_fea_res.feature[4]<<std::endl;
527   - //std::cout << "feature 5 :"<<result[b].info[c].vehicle_fea_res.feature[5]<<std::endl;
528   -
529   - //test
530   - //for(int f=0;f<10;f++)
531   - //{
532   - // float fea=result[b].info[c].vehicle_fea_res.feature[f];
533   - // std::cout << "feature "<<f<<":"<<fea<<std::endl;
534   - //}
535 224 }
536 225  
537 226 //11.摩托车三轮车分析
538   - if(param.vehicle_motor_tricycle_analysis_config==SY_CONFIG_OPEN && (vehicle_type==2 || vehicle_type==3))
  227 + if(param.vehicle_motor_tricycle_analysis_config==SY_CONFIG_OPEN && (shot_type==2 || shot_type==3))
539 228 {
540 229 //std::cout << "mta output----"<< std::endl;
541 230  
542   - if(vehicle_type==2)//摩托车
  231 + if(shot_type==2)//摩托车
543 232 {
544   - //摩托车载人
545   - //int status=result[b].info[c].mta_res.motor_manned.status;
546   - //float score=result[b].info[c].mta_res.motor_manned.confidence;
547   - //if(status == MOTOR_MANNED)
548   - // std::cout << "motor info: MOTOR_MANNED, prob: " << score << std::endl;
549   - //else if(status == MOTOR_NOT_MANNED)
550   - // std::cout << "motor info: MOTOR_NOT_MANNED, prob: " << score << std::endl;
551   -
552   - //摩托车驾驶人是否戴安全帽
553   - int status=result[b].info[c].mta_res.motor_driver_helmeted.status;
554   - float score=result[b].info[c].mta_res.motor_driver_helmeted.confidence;
555   - if(status == MOTOR_DRIVER_HELMETED)
556   - std::cout << " motor info: MOTOR_DRIVER_HELMETED, prob: " << score << std::endl;
557   - else if(status == MOTOR_DRIVER_NOT_HELMETED)
558   - std::cout << " motor info: MOTOR_DRIVER_NOT_HELMETED, prob: " << score << std::endl;
  233 + //摩托车载人
  234 + //int status=result_info.mta_res.motor_manned.status;
  235 + //float score=result_info.mta_res.motor_manned.confidence;
  236 + //if(status == MOTOR_MANNED)
  237 + // std::cout << "motor info: MOTOR_MANNED, prob: " << score << std::endl;
  238 + //else if(status == MOTOR_NOT_MANNED)
  239 + // std::cout << "motor info: MOTOR_NOT_MANNED, prob: " << score << std::endl;
  240 +
  241 + //摩托车驾驶人是否戴安全帽
  242 + analysis_result.motor_helmeted = result_info.mta_res.motor_driver_helmeted.status;
  243 + float score=result_info.mta_res.motor_driver_helmeted.confidence;
559 244  
560 245 }
561 246 }
562   - //载人输出
563   - //if(param.vehicle_manned_config==SY_CONFIG_OPEN && (vehicle_type==0 || vehicle_type==1 || vehicle_type==3))
564   - if(param.vehicle_manned_config==SY_CONFIG_OPEN && vehicle_type!=5)
565   - {
566   - std::cout << "----------------------manned output----"<< std::endl;
567   - int hs_count = result[b].info[c].manned_res.hs_count;
568   - std::cout <<"manned_hs_count:"<< hs_count << std::endl;
569   - for(int lo=0;lo<hs_count;lo++)
570   - {
571   - int x1=result[b].info[c].manned_res.hs_rect[lo].rect.left_;
572   - int y1=result[b].info[c].manned_res.hs_rect[lo].rect.top_;
573   - int x2=result[b].info[c].manned_res.hs_rect[lo].rect.left_+result[b].info[c].manned_res.hs_rect[lo].rect.width_;
574   - int y2=result[b].info[c].manned_res.hs_rect[lo].rect.top_+result[b].info[c].manned_res.hs_rect[lo].rect.height_;
575 247  
576   - std::cout <<"manned_hs_rect:"<< x1 <<" "<< y1<<" " <<x2<<" " << y2<< std::endl;
577   -
578   - // Point lt(x1, y1);
579   - // Point rb(x2, y2);
580   - // rectangle(cvImg, lt, rb, cv::Scalar(0, 255, 255), 4);
581   - }
  248 + //载人输出
  249 + if(param.vehicle_manned_config==SY_CONFIG_OPEN && shot_type!=5)
  250 + {
  251 + if(result_info.manned_res.hs_count >= 3){
  252 + analysis_result.motor_manned = 1;
  253 + }
582 254 }
583   - }
584   -
585   - //测试相似度比对函数,batch_size设为2
586   - //double similarity=va_compute_similarity(result[0].info[0].vehicle_fea_res.feature, result[1].info[0].vehicle_fea_res.feature, FEATURESIZE);
587   - //std::cout << "similarity: "<<similarity<<std::endl;
588   -
589   - // cv::imwrite((saveimagepath+file).c_str(),cvImg);
590   -
  255 + }
591 256 }
592 257  
593 258 //delete result
  259 + // for(int b=0;b<batch_size;b++)
  260 + // {
  261 + // for(int c=0; c<100; c++)
  262 + // {
  263 + // if(result[b].info[c].vehicle_pendant_det_res.vpd_res!=NULL)
  264 + // delete[] result[b].info[c].vehicle_pendant_det_res.vpd_res;
  265 +
  266 + // }
  267 + // if(result[b].info!=NULL){
  268 + // delete[] result[b].info;
  269 + // }
  270 +
  271 + // }
  272 +
  273 + // if(result!=NULL){
  274 + // delete[] result;
  275 + // }
  276 +
  277 + return result;
  278 +}
  279 +
  280 +void VehicleAnalysis::release(){
  281 + if (m_handle) {
  282 + va_release(&m_handle);
  283 + }
  284 +}
  285 +
  286 +void VehicleAnalysis::release_result(va_result* result, int batch_size){
594 287 for(int b=0;b<batch_size;b++)
595 288 {
596 289 for(int c=0; c<100; c++)
... ... @@ -608,12 +301,4 @@ int VehicleAnalysis::detect(vector&lt;sy_img&gt; vec_img) {
608 301 if(result!=NULL){
609 302 delete[] result;
610 303 }
611   -
612   - return 0;
613   -}
614   -
615   -void VehicleAnalysis::release(){
616   - if (m_handle) {
617   - va_release(&m_handle);
618   - }
619 304 }
... ...
src/ai_engine_module/VehicleAnalysis.h
... ... @@ -6,6 +6,31 @@
6 6 #include "vehicle_analysis.h"
7 7 #include "vehicle_result.h"
8 8  
  9 +struct DriverInfo {
  10 + sy_rect driver_rect;
  11 + float driver_prob;
  12 + int driver_color;
  13 +};
  14 +
  15 +struct VehicleAnalysisResult{
  16 + int shot_type;
  17 + sy_rect vehicle_rect;
  18 + string vehicle_type;
  19 +
  20 + sy_rect plate_rect;//车牌检测坐标
  21 + float plate_det_score;//车牌检测置信度
  22 + string plate_num;
  23 + string character_prob;
  24 + float plate_num_score;//识别置信度
  25 + int plate_type; //车牌类型:0-单排蓝色 1-单排黄色 2-单排白色 3-单排黑色 4-双排黄色 5-双排白色 6-新能源黄绿色 7-新能源白绿色
  26 + int special_type; //常规车牌、临时车牌、低速车牌。0-common,1-temporary_license_plate,2-low_speed_license_plate.
  27 +
  28 + vector<DriverInfo> vec_drivers; // 副驾也被认为是司机
  29 +
  30 + int motor_helmeted;
  31 + int motor_manned{0};
  32 +};
  33 +
9 34 class VehicleAnalysis
10 35 {
11 36 private:
... ... @@ -16,7 +41,9 @@ public:
16 41  
17 42 int init(int devId, int max_batch_size);
18 43  
19   - int detect(vector<sy_img> vec_img);
  44 + va_result* detect(vector<sy_img> vec_img);
  45 +
  46 + void release_result(va_result*, int);
20 47  
21 48 private:
22 49 void release();
... ...
src/ai_engine_module/include.h
... ... @@ -25,4 +25,5 @@ using namespace std;
25 25 using namespace cv;
26 26  
27 27  
  28 +
28 29 #endif
29 30 \ No newline at end of file
... ...
src/common/dvppx/dvpp_cropandpastex.cpp
... ... @@ -57,7 +57,12 @@ int DvppCropAndPastex::InitCropAndPasteInputDesc(ImageData&amp; inputImage)
57 57 return SY_FAILED;
58 58 }
59 59  
60   - acldvppSetPicDescData(vpcInputDesc_, inputImage.data.get()); // JpegD . vpcResize
  60 + if (inputImage.data_naked == nullptr) {
  61 + acldvppSetPicDescData(vpcInputDesc_, inputImage.data.get()); // JpegD . vpcResize
  62 + } else {
  63 + acldvppSetPicDescData(vpcInputDesc_, inputImage.data_naked); // JpegD . vpcResize
  64 + }
  65 +
61 66 acldvppSetPicDescFormat(vpcInputDesc_, format_);
62 67 acldvppSetPicDescWidth(vpcInputDesc_, inputImage.width);
63 68 acldvppSetPicDescHeight(vpcInputDesc_, inputImage.height);
... ... @@ -266,8 +271,6 @@ int DvppCropAndPastex::ResizeWithPadding(ImageData&amp; resizedImage, ImageData&amp; src
266 271 return SY_SUCCESS;
267 272 }
268 273  
269   -
270   -
271 274 int DvppCropAndPastex::PatchProcess(ImageData& resizedImage, ImageData& srcImage, uint32_t xmin, uint32_t ymin,
272 275 uint32_t xmax, uint32_t ymax)
273 276 {
... ... @@ -329,6 +332,73 @@ int DvppCropAndPastex::PatchProcess(ImageData&amp; resizedImage, ImageData&amp; srcImage
329 332 return SY_SUCCESS;
330 333 }
331 334  
  335 +ImageData* DvppCropAndPastex::Crop_naked(ImageData& srcImage, uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax)
  336 +{
  337 + ImageData* resizedImage = nullptr;
  338 +
  339 + do
  340 + {
  341 + if (SY_SUCCESS != InitCropAndPasteResource(srcImage)) {
  342 + ERROR_LOG("Dvpp cropandpaste failed for init error");
  343 + break;
  344 + }
  345 +
  346 + uint32_t cropLeftOffset = ((xmin >> 1) << 1); // must even
  347 + uint32_t cropTopOffset = ((ymin >> 1) << 1); // must even
  348 + uint32_t cropRightOffset = ((xmax >> 1) << 1) -1; // must odd
  349 + uint32_t cropBottomOffset = ((ymax >> 1) << 1) -1; // must odd
  350 +
  351 + cropArea_ = acldvppCreateRoiConfig(cropLeftOffset, cropRightOffset,
  352 + cropTopOffset, cropBottomOffset);
  353 + if (cropArea_ == nullptr) {
  354 + ERROR_LOG("acldvppCreateRoiConfig cropArea_ failed");
  355 + break;
  356 + }
  357 + //printf("debug crop area: %d %d %d %d\n", cropLeftOffset, cropTopOffset, cropRightOffset, cropBottomOffset);
  358 +
  359 + uint32_t pasteLeftOffset = 0; // must even
  360 + uint32_t pasteTopOffset = 0; // must even
  361 + uint32_t pasteRightOffset = (((pasteLeftOffset + size_.width) >> 1) << 1) -1; // must odd
  362 + uint32_t pasteBottomOffset = (((pasteTopOffset + size_.height) >> 1) << 1) -1; // must odd
  363 +
  364 + pasteArea_ = acldvppCreateRoiConfig(pasteLeftOffset, pasteRightOffset,
  365 + pasteTopOffset, pasteBottomOffset);
  366 + if (pasteArea_ == nullptr) {
  367 + ERROR_LOG("acldvppCreateRoiConfig pasteArea_ failed");
  368 + break;
  369 + }
  370 + //printf("debug paste area: %d %d %d %d\n", pasteLeftOffset, pasteTopOffset, pasteRightOffset, pasteBottomOffset);
  371 +
  372 + // crop and patse pic
  373 + aclError aclRet = acldvppVpcCropAndPasteAsync(dvppChannelDesc_, vpcInputDesc_,
  374 + vpcOutputDesc_, cropArea_, pasteArea_, stream_);
  375 + //printf("debug crop line:%d\n",__LINE__);
  376 + if (aclRet != ACL_SUCCESS) {
  377 + ERROR_LOG("acldvppVpcCropAndPasteAsync failed, aclRet = %d", aclRet);
  378 + break;
  379 + }
  380 +
  381 + aclRet = aclrtSynchronizeStream(stream_);
  382 + if (aclRet != ACL_SUCCESS) {
  383 + ERROR_LOG("crop and paste aclrtSynchronizeStream failed, aclRet = %d", aclRet);
  384 + break;
  385 + }
  386 +
  387 + resizedImage = new ImageData();
  388 + resizedImage->width = size_.width;
  389 + resizedImage->height = size_.height;
  390 + resizedImage->alignWidth = ALIGN_UP16(size_.width);
  391 + resizedImage->alignHeight = ALIGN_UP2(size_.height);
  392 + resizedImage->size = vpcOutBufferSize_;
  393 + resizedImage->data_naked = (uint8_t*)vpcOutBufferDev_;
  394 +
  395 + } while (0);
  396 +
  397 + DestroyCropAndPasteResource();
  398 +
  399 + return resizedImage;
  400 +}
  401 +
332 402 int DvppCropAndPastex::Crop2Process(ImageData& resizedImage, ImageData& leftImage, ImageData& rightImage, ImageData& srcImage)
333 403 {
334 404 //left
... ... @@ -500,7 +570,6 @@ int DvppCropAndPastex::Process(ImageData&amp; resizedImage, ImageData&amp; srcImage)
500 570 return SY_SUCCESS;
501 571 }
502 572  
503   -
504 573 void DvppCropAndPastex::DestroyCropAndPasteResource()
505 574 {
506 575 if (cropArea_ != nullptr) {
... ...
src/common/dvppx/dvpp_cropandpastex.h
... ... @@ -56,12 +56,15 @@ public:
56 56 * @return result
57 57 */
58 58 int Process(ImageData& resizedImage, ImageData& srcImage);
  59 +
59 60 int Crop2Process(ImageData& resizedImage, ImageData& leftImage, ImageData& rightImage, ImageData& srcImage);
60 61 int PatchProcess(ImageData& resizedImage, ImageData& srcImage, uint32_t xmin, uint32_t ymin,
61 62 uint32_t xmax, uint32_t ymax);
62 63  
63 64 int ResizeWithPadding(ImageData& resizedImage, ImageData& srcImage);
64 65  
  66 + ImageData* Crop_naked(ImageData& srcImage, uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax);
  67 +
65 68 private:
66 69 int InitCropAndPasteResource(ImageData& inputImage);
67 70 int InitCropAndPasteInputDesc(ImageData& inputImage);
... ...
src/common/dvppx/dvpp_processx.cpp
... ... @@ -93,13 +93,18 @@ int DvppProcessx::CropAndPadding(ImageData&amp; dest, ImageData&amp; src,
93 93 return cropandpaddingOp.ResizeWithPadding(dest, src);
94 94 }
95 95  
96   -
97 96 int DvppProcessx::PatchCropAndPaste(ImageData& dest, ImageData& src, uint32_t xmin, uint32_t ymin,
98 97 uint32_t xmax, uint32_t ymax, uint32_t width, uint32_t height) {
99 98 DvppCropAndPastex patchcropandpasteOp(stream_, dvppChannelDesc_, width, height);
100 99 return patchcropandpasteOp.PatchProcess(dest, src, xmin, ymin, xmax, ymax);
101 100 }
102 101  
  102 +ImageData* DvppProcessx::Crop_naked(ImageData& src, uint32_t xmin, uint32_t ymin,
  103 + uint32_t xmax, uint32_t ymax, uint32_t width, uint32_t height) {
  104 + DvppCropAndPastex cropandpasteOp(stream_, dvppChannelDesc_, width, height);
  105 + return cropandpasteOp.Crop_naked(src, xmin, ymin, xmax, ymax);
  106 +}
  107 +
103 108 int DvppProcessx::CvtJpegToYuv420sp(ImageData& dest, ImageData& src) {
104 109 DvppJpegDx jpegD(stream_, dvppChannelDesc_);
105 110 return jpegD.Process(dest, src);
... ...
src/common/dvppx/dvpp_processx.h
... ... @@ -62,6 +62,7 @@ public:
62 62 uint32_t width, uint32_t height);
63 63 int CropAndPaste(ImageData& src, ImageData& dest,
64 64 uint32_t width, uint32_t height);
  65 + ImageData* Crop_naked(ImageData& src, uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax, uint32_t width, uint32_t height);
65 66 int PatchCropAndPaste(ImageData& dest, ImageData& src, uint32_t xmin, uint32_t ymin,
66 67 uint32_t xmax, uint32_t ymax, uint32_t width, uint32_t height);
67 68 int Crop2Paste(ImageData& dest, ImageData& leftImage, ImageData& rightImage,
... ...
src/common/stream_data.h
... ... @@ -2,6 +2,8 @@
2 2 #define _STREAM_DATA_H_
3 3  
4 4 #include <memory>
  5 +#include "acl/acl.h"
  6 +#include "acl/ops/acl_dvpp.h"
5 7  
6 8 struct ImageData {
7 9 uint32_t width = 0;
... ... @@ -10,6 +12,17 @@ struct ImageData {
10 12 uint32_t alignHeight = 0;
11 13 uint32_t size = 0;
12 14 std::shared_ptr<uint8_t> data;
  15 + uint8_t* data_naked;
  16 +
  17 + ImageData(){
  18 + data_naked = nullptr;
  19 + }
  20 +
  21 + ~ImageData(){
  22 + if (data_naked) {
  23 + acldvppFree(data_naked);
  24 + }
  25 + }
13 26 };
14 27  
15 28 #endif
16 29 \ No newline at end of file
... ...
src/main.cpp
... ... @@ -7,9 +7,9 @@ int main() {
7 7 pic_analysis.init(0);
8 8  
9 9 vector<string> vec_path;
10   - for (size_t i = 0; i < 10; i++)
  10 + for (size_t i = 0; i < 1; i++)
11 11 {
12   - vec_path.push_back("./test_hv.jpg");
  12 + vec_path.push_back("./test_all.jpg");
13 13 }
14 14  
15 15 pic_analysis.analysis_sync(vec_path);
... ...
src/utils/CropUtil.cpp 0 → 100644
  1 +#include "CropUtil.h"
  2 +#include "logger.hpp"
  3 +#include "sy_errorinfo.h"
  4 +
  5 +CropUtil::CropUtil(/* args */)
  6 +{
  7 +}
  8 +
  9 +CropUtil::~CropUtil()
  10 +{
  11 + release();
  12 +}
  13 +
  14 +int CropUtil::init(int devId){
  15 + ACL_CALL(aclrtCreateContext(&m_ctx, devId), ACL_SUCCESS, SY_FAILED);
  16 +
  17 + ACL_CALL(aclrtCreateStream(&stream), ACL_SUCCESS, SY_FAILED);
  18 + m_dvpp = new DvppProcessx();
  19 + int ret = m_dvpp->InitResource(stream);
  20 + if (ret != SY_SUCCESS) {
  21 + delete m_dvpp;
  22 + m_dvpp = nullptr;
  23 + LOG_ERROR("dvpp init failed!");
  24 + return SY_FAILED;
  25 + }
  26 +
  27 + return SY_SUCCESS;
  28 +}
  29 +
  30 +int CropUtil::release(){
  31 + ACL_CALL(aclrtSetCurrentContext(m_ctx), ACL_SUCCESS, SY_FAILED);
  32 +
  33 + if (m_dvpp) {
  34 + delete m_dvpp;
  35 + m_dvpp = nullptr;
  36 + }
  37 +
  38 + if (stream != nullptr) {
  39 + int ret = aclrtDestroyStream(stream);
  40 + if (ret != ACL_SUCCESS) {
  41 + LOG_ERROR("destroy stream failed");
  42 + }
  43 + stream = nullptr;
  44 + }
  45 +
  46 + aclrtDestroyContext(m_ctx);
  47 +}
  48 +
  49 +ImageData* CropUtil::crop(ImageData& src, uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax) {
  50 + int ret = aclrtSetCurrentContext(m_ctx);
  51 + if (ACL_SUCCESS != ret)
  52 + {
  53 + return nullptr;
  54 + }
  55 +
  56 + int width = xmax - xmin;
  57 + int height = ymax - ymin;
  58 + uint32_t alignWidth = (width + 127) / 128 * 128;
  59 + uint32_t alignHeight = (height + 15) / 16 * 16;
  60 + return m_dvpp->Crop_naked(src, xmin, ymin, xmax, ymax, alignWidth, alignHeight);
  61 +}
0 62 \ No newline at end of file
... ...
src/utils/CropUtil.h 0 → 100644
  1 +#include "../dvppx/dvpp_processx.h"
  2 +
  3 +class CropUtil
  4 +{
  5 +public:
  6 + CropUtil(/* args */);
  7 + ~CropUtil();
  8 +
  9 + int init(int devId);
  10 +
  11 + ImageData* crop(ImageData& src, uint32_t xmin, uint32_t ymin, uint32_t xmax, uint32_t ymax);
  12 +
  13 +private:
  14 + int release();
  15 +
  16 +private:
  17 + aclrtContext m_ctx;
  18 + aclrtStream stream;
  19 + DvppProcessx* m_dvpp;
  20 +};
... ...