diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp index e233aa3..60371ba 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp @@ -167,7 +167,6 @@ int CMutliSourceVideoProcess::FinishProcessThread() ProcessThread.join(); //waiting thread finish VPT_Release(VPT_Handle); - m_face_det_module->face_det_module_release(); m_snaphot_helper.snapshot_helper_release(); @@ -262,14 +261,6 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN if (0 != ret) return ret; - m_face_det_module = nullptr; - if (vptParam.face_det_config == SY_CONFIG_OPEN) - { - m_face_det_module = new face_det_module(); - printf("begin init face det\n"); - m_face_det_module->face_det_module_init(vptParam.gpuid, vptParam.auth_license); - } - viewTaskID = -1; TaskinPlay = 0; TotalTask = 0; @@ -1014,46 +1005,47 @@ void CMutliSourceVideoProcess::algorthim_process() iter = TaskinPlayID.begin(); for (int i = 0; i < curPlayTaskCount; i++) { - tasks[*iter].taskFrameCount = tasks[*iter].task_algorithm_data.timestamp; + Task task = tasks[*iter]; + task.taskFrameCount = task.task_algorithm_data.timestamp; //若该路任务当前帧未检测到目标,返回ID为-1的目标表明未检测到目标 if (VPTResult[i].objCount == 0) { - callTaskObjInfoCallbackFunc(0, nullptr, tasks[*iter].taskFrameCount, *iter); + callTaskObjInfoCallbackFunc(0, nullptr, task.taskFrameCount, *iter); } //实时查看模块,若存在实时查看,把当前视频画面cp回内存 bool view = false; - int frameHeight = tasks[*iter].task_algorithm_data.height; - int frameWidth = tasks[*iter].task_algorithm_data.width; + int frameHeight = task.task_algorithm_data.height; + int frameWidth = task.task_algorithm_data.width; if (*iter == viewTaskID) { - cudaMemcpy(tasks[*iter].frameImage.data, tasks[*iter].task_algorithm_data.frame, 3 * tasks[*iter].task_algorithm_data.width * tasks[*iter].task_algorithm_data.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); + cudaMemcpy(task.frameImage.data, task.task_algorithm_data.frame, 3 * task.task_algorithm_data.width * task.task_algorithm_data.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); view = true; } //跟踪帧也需要返回跟踪的结果 - if (tasks[*iter].taskLastFrameCount > 0) + if (task.taskLastFrameCount > 0) { vector OneUnUsedResult = unUsedResult[i]; if (OneUnUsedResult.size() == 0) { - callTaskObjInfoCallbackFunc(0, nullptr, tasks[*iter].taskLastFrameCount + 1, *iter); + callTaskObjInfoCallbackFunc(0, nullptr, task.taskLastFrameCount + 1, *iter); } for (int k = 0; k < OneUnUsedResult.size(); ++k) { if (OneUnUsedResult[k].objCount == 0) { - callTaskObjInfoCallbackFunc(0, nullptr, tasks[*iter].taskLastFrameCount + k + 1, *iter); + callTaskObjInfoCallbackFunc(0, nullptr, task.taskLastFrameCount + k + 1, *iter); } else { //cout << "OneUnUsedResult.size = " << OneUnUsedResult.size() << " k=" << k << " OneUnUsedResult[k].objCount = " << OneUnUsedResult[k].objCount << endl; - callTaskObjInfoCallbackFunc(OneUnUsedResult[k].objCount, OneUnUsedResult[k].obj, tasks[*iter].taskLastFrameCount + k + 1, *iter); + callTaskObjInfoCallbackFunc(OneUnUsedResult[k].objCount, OneUnUsedResult[k].obj, task.taskLastFrameCount + k + 1, *iter); } } } - tasks[*iter].taskLastFrameCount = tasks[*iter].taskFrameCount; + task.taskLastFrameCount = task.taskFrameCount; unsigned char* snapshot_image_data[MAX_OBJ_COUNT]{};// = new unsigned char*[VPTResult[i].objCount]; int snapshot_left[MAX_OBJ_COUNT]{};// = new int[VPTResult[i].objCount]; @@ -1067,7 +1059,7 @@ void CMutliSourceVideoProcess::algorthim_process() vector human_idx; //用于记录快照数组中那些是人脸 vector human_obj_keys; - callTaskObjInfoCallbackFunc(VPTResult[i].objCount, VPTResult[i].obj, tasks[*iter].taskFrameCount, *iter); + callTaskObjInfoCallbackFunc(VPTResult[i].objCount, VPTResult[i].obj, task.taskFrameCount, *iter); for (int c = 0; c < VPTResult[i].objCount; c++) { OBJ_KEY newObj = { (*iter), VPTResult[i].obj[c].id }; @@ -1085,19 +1077,19 @@ void CMutliSourceVideoProcess::algorthim_process() int p1 = VPTResult[i].obj[c].left - 10 > 0 ? VPTResult[i].obj[c].left - 10 : 0; int p2 = VPTResult[i].obj[c].top - 15 > 0 ? VPTResult[i].obj[c].top - 15 : 0; - cv::rectangle(tasks[*iter].frameImage, Rect(VPTResult[i].obj[c].left, VPTResult[i].obj[c].top, + cv::rectangle(task.frameImage, Rect(VPTResult[i].obj[c].left, VPTResult[i].obj[c].top, VPTResult[i].obj[c].right - VPTResult[i].obj[c].left, VPTResult[i].obj[c].bottom - VPTResult[i].obj[c].top), Scalar(158, 52, 254), 3, 1, 0); #ifdef _MSC_VER string resss = "" + to_string(index) + " " + ObjTypes[index]; - putTextZH(tasks[*iter].frameImage, resss.c_str(), { p1, p2 }, Scalar(20, 255, 20), 14, "Arial"); + putTextZH(task.frameImage, resss.c_str(), { p1, p2 }, Scalar(20, 255, 20), 14, "Arial"); #else string resss = "" + to_string(VPTResult[i].obj[c].id) + " " + ObjTypesEnglish[VPTResult[i].obj[c].index]; - cv::putText(tasks[*iter].frameImage, resss.c_str(), cv::Point(p1, p2), cv::FONT_HERSHEY_COMPLEX, 2, Scalar(20, 255, 20), 2, 8, 0); + cv::putText(task.frameImage, resss.c_str(), cv::Point(p1, p2), cv::FONT_HERSHEY_COMPLEX, 2, Scalar(20, 255, 20), 2, 8, 0); #endif } - CropInfo crop_info = m_snaphot_helper.cacheSnapShotInfo(newObj, VPTResult[i].obj[c], tasks[*iter]); + CropInfo crop_info = m_snaphot_helper.cacheSnapShotInfo(newObj, VPTResult[i].obj[c], task); if(crop_info.bCrop){ snapshot_image_data[copy_obj_count] = crop_info.snapshot_image_data; snapshot_left[copy_obj_count] = crop_info.snapshot_left; @@ -1122,7 +1114,7 @@ void CMutliSourceVideoProcess::algorthim_process() { cudaSetDevice(mgpuid); cuCtxPushCurrent(context); - PartMemResizeBatch((unsigned char*)tasks[*iter].task_algorithm_data.frame, frameWidth, frameHeight, + PartMemResizeBatch((unsigned char*)task.task_algorithm_data.frame, frameWidth, frameHeight, snapshot_image_data, copy_obj_count, snapshot_left, snapshot_top, snapshot_right, snapshot_bottom, snapshot_dst_width, snapshot_dst_height, 0, 0, 0, 1, 1, 1); cuCtxPopCurrent(&context); @@ -1131,9 +1123,8 @@ void CMutliSourceVideoProcess::algorthim_process() { //需要做人脸检测 int human_count = human_idx.size(); - sy_img *human_img = new sy_img[human_count]; - - sy_point* ori_points = new sy_point[human_count]; + sy_img human_img[human_count]; + sy_point ori_points[human_count]; for (int idx = 0; idx < human_count; idx++) { int ii = human_idx[idx]; @@ -1142,167 +1133,16 @@ void CMutliSourceVideoProcess::algorthim_process() ori_points[idx].y_ = (snapshot_bottom[ii] - snapshot_top[ii]); } - fd_result *face_det_result = new fd_result[human_count]; - for (int fd_i = 0; fd_i < human_count; fd_i++) - { - face_det_result[fd_i].info = new fd_info[10]; //内存由外部申请 - } - - if (m_face_det_module->face_det_module_process(human_img, human_count, face_det_result, ori_points) == SUCCESS) - { - //printf("finish face_det_module_process: %d\n", human_count); - for (int idx = 0; idx < human_count; idx++) - { - OBJ_KEY cur_obj_key = human_obj_keys[idx]; - fd_result &cur_det_res = face_det_result[idx]; - int face_count = cur_det_res.count; - int face_idx = 0; - int ii = human_idx[idx]; - - if (face_count == 0) continue; - - if (face_count > 1) //检测到多余一个人脸 选最佳 - { - sy_point center_human = { human_img[idx].w_/2, human_img [idx].h_/2}; - float min_distance = INT_MAX; - - for (int c = 0; c < face_count; c++) - { - sy_point face_center = { cur_det_res.info[c].face_position.width_/2, cur_det_res.info[c].face_position.height_/2}; - float distance = fabs(center_human.x_ - face_center.x_) + fabs(center_human.y_ - face_center.y_); - - if (distance < min_distance) - { - min_distance = distance; - face_idx = c; - } - } - } - - fd_info& cur_det_info = cur_det_res.info[face_idx]; - if (m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame == nullptr) - { - sy_rect face_ori_rect = { (int)(snapshot_left[ii] + cur_det_info.face_position.left_ ), - (int)(snapshot_top[ii] + cur_det_info.face_position.top_), - (int)(cur_det_info.face_position.width_), (int)(cur_det_info.face_position.height_) }; - - int new_left = max(0, face_ori_rect.left_ - face_ori_rect.width_); - int new_top = max(0, face_ori_rect.top_ - face_ori_rect.height_); - int new_right = min((int)tasks[*iter].task_algorithm_data.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); - int new_bottom = min((int)tasks[*iter].task_algorithm_data.height - 1, (face_ori_rect.top_ + 2 * face_ori_rect.height_)); - int new_width = new_right - new_left; - int new_height = new_bottom - new_top; - - sy_rect face_expand_rect = { new_left, new_top, new_width, new_height }; - - int face_img_length = 3 * face_expand_rect.width_ * face_expand_rect.height_; - - cudaError_t cudaStatus = cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_img_length * sizeof(unsigned char)); - if (cudaStatus != cudaSuccess) { - fprintf(stderr, "here cudaMalloc frame[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); - break; - } - - m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.width = face_expand_rect.width_; - m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.height = face_expand_rect.height_; - memcpy((void*)&m_snaphot_helper.snapShotInfo[cur_obj_key].face_info, (void*)&cur_det_info, sizeof(fd_info)); - - //矫正坐标 从行人抠图检测结果 -> 人脸外扩抠图坐标 - fd_info& tmp_info = m_snaphot_helper.snapShotInfo[cur_obj_key].face_info; - - for (int p = 0; p < FACIALFEAPOINTSIZE; p++) - { - tmp_info.facial_fea_point[p].x_ = - tmp_info.facial_fea_point[p].x_ - tmp_info.face_position.left_ + (face_ori_rect.left_ - face_expand_rect.left_); - tmp_info.facial_fea_point[p].y_ = - tmp_info.facial_fea_point[p].y_ - tmp_info.face_position.top_ + (face_ori_rect.top_ - face_expand_rect.top_); - } - - m_snaphot_helper.snapShotInfo[cur_obj_key].face_info.face_position = - { (face_ori_rect.left_ - face_expand_rect.left_), (face_ori_rect.top_ - face_expand_rect.top_), face_ori_rect.width_, face_ori_rect.height_ }; - - - cudacommon::CropImgGpu((unsigned char*)tasks[*iter].task_algorithm_data.frame, tasks[*iter].task_algorithm_data.width, tasks[*iter].task_algorithm_data.height, - (unsigned char*)m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_expand_rect.left_, face_expand_rect.top_, face_expand_rect.width_, face_expand_rect.height_); - - //show_gpu_img_func(m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace); - } - else - { - sy_rect face_ori_rect = { (int)(snapshot_left[ii] + cur_det_info.face_position.left_), - (int)(snapshot_top[ii] + cur_det_info.face_position.top_), - (int)(cur_det_info.face_position.width_), (int)(cur_det_info.face_position.height_) }; - - //更新人脸快照条件:① 角度满足条件 ② 面积比之前人脸面积大 - if (validAngle(cur_det_res.info[face_idx].roll, cur_det_res.info[face_idx].yaw, cur_det_res.info[face_idx].pitch, 15.0, 20.0) - && betterArea(face_ori_rect, m_snaphot_helper.snapShotInfo[cur_obj_key].face_info.face_position)) - { - int new_left = max(0, face_ori_rect.left_ - face_ori_rect.width_); - int new_top = max(0, face_ori_rect.top_ - face_ori_rect.height_); - int new_right = min((int)tasks[*iter].task_algorithm_data.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); - int new_bottom = min((int)tasks[*iter].task_algorithm_data.height - 1, (face_ori_rect.top_ + 2 * face_ori_rect.height_)); - int new_width = new_right - new_left; - int new_height = new_bottom - new_top; - - sy_rect face_expand_rect = { new_left, new_top, new_width, new_height }; - - //更新快照 - int face_img_length = 3 * face_expand_rect.width_ * face_expand_rect.height_; - - cudaFree(m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame); - cudaError_t cudaStatus = cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_img_length * sizeof(unsigned char)); - if (cudaStatus != cudaSuccess) { - fprintf(stderr, "here cudaMalloc frame[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); - break; - } - - m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.width = face_expand_rect.width_; - m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.height = face_expand_rect.height_; - memcpy((void*)&m_snaphot_helper.snapShotInfo[cur_obj_key].face_info, (void*)&cur_det_info, sizeof(fd_info)); - - //矫正坐标 从行人抠图检测结果 -> 人脸外扩抠图坐标 - fd_info& tmp_info = m_snaphot_helper.snapShotInfo[cur_obj_key].face_info; - - for (int p = 0; p < FACIALFEAPOINTSIZE; p++) - { - tmp_info.facial_fea_point[p].x_ = - tmp_info.facial_fea_point[p].x_ - tmp_info.face_position.left_ + (face_ori_rect.left_ - face_expand_rect.left_); - tmp_info.facial_fea_point[p].y_ = - tmp_info.facial_fea_point[p].y_ - tmp_info.face_position.top_ + (face_ori_rect.top_ - face_expand_rect.top_); - } - - m_snaphot_helper.snapShotInfo[cur_obj_key].face_info.face_position = - {(face_ori_rect.left_ - face_expand_rect.left_), (face_ori_rect.top_ - face_expand_rect.top_), face_ori_rect.width_, face_ori_rect.height_}; - - cudacommon::CropImgGpu((unsigned char*)tasks[*iter].task_algorithm_data.frame, tasks[*iter].task_algorithm_data.width, tasks[*iter].task_algorithm_data.height, - (unsigned char*)m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_expand_rect.left_, face_expand_rect.top_, face_expand_rect.width_, face_expand_rect.height_); - - //show_gpu_image_withfdinfo_(m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace, cur_det_info); - - //show_gpu_image_withfdinfo_(m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace, m_snaphot_helper.snapShotInfo[cur_obj_key].face_info); - } - } - } - } - - if (face_det_result) - { - for (int fd_i = 0; fd_i < human_count; fd_i++) - delete[] face_det_result[fd_i].info; - delete face_det_result; - } - - if (human_img) delete[] human_img; - if (ori_points) delete[] ori_points; + m_snaphot_helper.cacheFaceSnapshotInfo(human_img, human_count, ori_points, human_idx, human_obj_keys, snapshot_left, snapshot_top, task); } } //实时查看 绘制目标轨迹 回调函数返回 if (view) { - DrawTracker(VPT_Handle, *iter, &tasks[*iter].frameImage); - if (tasks[*iter].taskRealTimeCallbackFunc != nullptr) - tasks[*iter].taskRealTimeCallbackFunc(tasks[*iter].frameImage.data, tasks[*iter].frameImage.rows, tasks[*iter].frameImage.cols); + DrawTracker(VPT_Handle, *iter, &task.frameImage); + if (task.taskRealTimeCallbackFunc != nullptr) + task.taskRealTimeCallbackFunc(task.frameImage.data, task.frameImage.rows, task.frameImage.cols); } // tasks[*iter].taskFrameCount += skip_frame_; iter++; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h index eb04107..97bb8d3 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h @@ -18,7 +18,6 @@ #include "mvpt_process_assist.h" #include "snapshot_helper.h" -#include "FaceDetModule.h" #include //#include "DxLogInterface.h" @@ -156,7 +155,6 @@ private: public: /*��������Ӧ����public�� �������̺߳����л��õ����µ����� ÿ����дһ��get����̫������*/ //fstream fout[THREAD_COUNT]; //���������� void * VPT_Handle; - face_det_module* m_face_det_module; int section_batch_size; int licence_status; int thrd_status; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp index c4374ee..818e08b 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp @@ -71,7 +71,7 @@ int HumanCarParsing::init(int gpuid, char* auth_license) return SUCCESS; } -int HumanCarParsing::process(sy_img * batch_img, int batch_size, hcp_analysis_result *&result) +int HumanCarParsing::process(sy_img * batch_img, int batch_size, hcp_analysis_result *result) { LOG_DEBUG("batch_size: {}", batch_size); hcp_batch(handle, batch_img, batch_size, result); diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.h index e65879b..db3104b 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.h @@ -12,7 +12,7 @@ public: ~HumanCarParsing(); int init(int gpuid, char* auth_license); - int process(sy_img * batch_img,int batchsize, hcp_analysis_result *&result); + int process(sy_img * batch_img,int batchsize, hcp_analysis_result *result); int release(); private: diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanFea.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanFea.cpp index 418892e..256e46f 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanFea.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanFea.cpp @@ -36,7 +36,7 @@ int HumanFea::init(int gpuid, char* auth_license) return SUCCESS; } -int HumanFea::process(sy_img * batch_img, int batch_size, human_fea_result*& result) +int HumanFea::process(sy_img * batch_img, int batch_size, human_fea_result* result) { for (int i = 0; i < batch_size; i++) { if (batch_img[i].data_ == NULL) { diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanFea.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanFea.h index 413c030..18408d1 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanFea.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanFea.h @@ -9,7 +9,7 @@ public: ~HumanFea(); int init(int gpuid, char* auth_license); - int process(sy_img * batch_img, int batch_size, human_fea_result*& result); + int process(sy_img * batch_img, int batch_size, human_fea_result* result); int release(); private: diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp index 40b59b5..4964222 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp @@ -140,6 +140,9 @@ void snapshot_helper::snapshot_helper_init(int gpuid, double gpu_total_memory, c m_vehicle_feature.init_vf(dbpath_utf8, gpuid, auth_license); } + if(face_detect_cf == SY_CONFIG_OPEN) { + m_face_det_module.face_det_module_init(gpuid, auth_license); + } OBJ_BATCH_COUNT = 20; if (gpu_total_memory < 9000) //8G显存,小内存方案 @@ -153,7 +156,6 @@ void snapshot_helper::snapshot_helper_init(int gpuid, double gpu_total_memory, c v_analysis = V_ANALYSIS_TYPE::VC_ANALYSIS; batch_hp = new sy_img[OBJ_BATCH_COUNT]{}; - batch_hcp = new sy_img[OBJ_BATCH_COUNT]{}; batch_vehicle = new sy_img[OBJ_BATCH_COUNT_VEHICLE]{}; batch_vehicle_vf = new sy_img[OBJ_BATCH_COUNT_VEHICLE]{}; @@ -178,17 +180,14 @@ void snapshot_helper::snapshot_helper_release() m_vehicle_feature.release_vpd(); m_vehicle_feature.release_vf(); m_human_fea.release(); + m_face_det_module.face_det_module_release(); if (batch_hp != NULL) { delete[] batch_hp; batch_hp = NULL; } - if (batch_hcp != NULL) - { - delete[] batch_hcp; - batch_hcp = NULL; - } + if (batch_vehicle != NULL) { delete[] batch_vehicle; @@ -585,21 +584,20 @@ void snapshot_helper::finish_task_ss_analysis(int task_id) //是 if (!hcp_keys.empty()) { + LOG_DEBUG("hcp_keys size: {}", hcp_keys.size()); + const int obj_batch_count = OBJ_BATCH_COUNT / OBJ_SCALE; const int hcp_batch_size = hcp_keys.size(); int hcp_batch_count = obj_batch_count; for (int i = 0; i <= (hcp_batch_size / obj_batch_count); ++i) { - hcp_analysis_result *result = nullptr; - human_fea_result * result_f = nullptr; if (i == (hcp_batch_size / obj_batch_count)) hcp_batch_count = hcp_batch_size % obj_batch_count; if (hcp_batch_count == 0) continue; - sy_img* finish_hcp_img = new sy_img[hcp_batch_count]{}; - + sy_img finish_hcp_img[hcp_batch_count]; for (int j = 0; j < hcp_batch_count; j++) { OBJ_KEY cur_obj_key = hcp_keys[j]; @@ -607,13 +605,13 @@ void snapshot_helper::finish_task_ss_analysis(int task_id) //是 finish_hcp_img[j].set_data(HCP_WIDTH, HCP_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); } + hcp_analysis_result result[hcp_batch_count]; if (hcp_analysis_cf == SY_CONFIG_OPEN) { - result = new hcp_analysis_result[hcp_batch_count]{}; m_human_car_parsing.process(finish_hcp_img, hcp_batch_count, result); } + human_fea_result result_f[hcp_batch_count]; if (hcf_recg_cf == SY_CONFIG_OPEN) { - result_f = new human_fea_result[hcp_batch_count]{}; m_human_fea.process(finish_hcp_img, hcp_batch_count, result_f); } int resIndex = 0; @@ -665,22 +663,6 @@ void snapshot_helper::finish_task_ss_analysis(int task_id) //是 } hcp_keys.erase(hcp_keys.begin(), hcp_keys.begin() + hcp_batch_count); - - if (result != nullptr) - { - delete[] result; - result = nullptr; - } - if (result_f != nullptr) - { - delete[] result_f; - result_f = nullptr; - } - if (finish_hcp_img != NULL) - { - delete[] finish_hcp_img; - finish_hcp_img = NULL; - } } } @@ -952,8 +934,8 @@ void snapshot_helper::hcp_analysis() human_fea_result * result_f = nullptr; int cur_batchsize = index == 0 ? per_batchsize : OBJ_BATCH_COUNT - per_batchsize; - for (int i = 0; i < cur_batchsize/*OBJ_BATCH_COUNT / OBJ_SCALE*/; i++) - //for (int i = 0; i < OBJ_BATCH_COUNT/ OBJ_SCALE; i++) + sy_img batch_hcp[cur_batchsize]; + for (int i = 0; i < cur_batchsize; i++) { OBJ_KEY cur_obj_key = count_bike.front(); count_bike.pop(); @@ -2132,6 +2114,7 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas { cur_width = HCP_WIDTH; cur_height = HCP_HEIGHT; + LOG_DEBUG("task_id:{} obj_id:{} index = 0、1", newObj.videoID, newObj.objID); } else if (8 == snapShotInfo[newObj].index.index || (snapShotInfo[newObj].index.index >= 4 && snapShotInfo[newObj].index.index <= 6)) { @@ -2319,4 +2302,150 @@ int snapshot_helper::getIndexByKey(OBJ_KEY newObj) { } return -1; +} + +void snapshot_helper::cacheFaceSnapshotInfo(sy_img *human_img, int human_count, sy_point* ori_points, vector human_idx, vector human_obj_keys, int snapshot_left[], int snapshot_top[], Task task) { + fd_result *face_det_result = new fd_result[human_count]; + for (int fd_i = 0; fd_i < human_count; fd_i++) + { + face_det_result[fd_i].info = new fd_info[10]; //内存由外部申请 + } + + int ret = m_face_det_module.face_det_module_process(human_img, human_count, face_det_result, ori_points); + if (SUCCESS == ret) + { + for (int idx = 0; idx < human_count; idx++) + { + OBJ_KEY cur_obj_key = human_obj_keys[idx]; + fd_result &cur_det_res = face_det_result[idx]; + int face_count = cur_det_res.count; + int face_idx = 0; + int ii = human_idx[idx]; + + if (face_count == 0) continue; + + if (face_count > 1) //检测到多余一个人脸 选最佳 + { + sy_point center_human = { human_img[idx].w_/2, human_img [idx].h_/2}; + float min_distance = INT_MAX; + + for (int c = 0; c < face_count; c++) + { + sy_point face_center = { cur_det_res.info[c].face_position.width_/2, cur_det_res.info[c].face_position.height_/2}; + float distance = fabs(center_human.x_ - face_center.x_) + fabs(center_human.y_ - face_center.y_); + + if (distance < min_distance) + { + min_distance = distance; + face_idx = c; + } + } + } + + fd_info& cur_det_info = cur_det_res.info[face_idx]; + if (snapShotInfo[cur_obj_key].snapShotFace.frame == nullptr) + { + sy_rect face_ori_rect = { (int)(snapshot_left[ii] + cur_det_info.face_position.left_ ), + (int)(snapshot_top[ii] + cur_det_info.face_position.top_), + (int)(cur_det_info.face_position.width_), (int)(cur_det_info.face_position.height_) }; + + int new_left = max(0, face_ori_rect.left_ - face_ori_rect.width_); + int new_top = max(0, face_ori_rect.top_ - face_ori_rect.height_); + int new_right = min((int)task.task_algorithm_data.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); + int new_bottom = min((int)task.task_algorithm_data.height - 1, (face_ori_rect.top_ + 2 * face_ori_rect.height_)); + int new_width = new_right - new_left; + int new_height = new_bottom - new_top; + + sy_rect face_expand_rect = { new_left, new_top, new_width, new_height }; + + int face_img_length = 3 * face_expand_rect.width_ * face_expand_rect.height_; + + cudaError_t cudaStatus = cudaMalloc((void**)&snapShotInfo[cur_obj_key].snapShotFace.frame, face_img_length * sizeof(unsigned char)); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "here cudaMalloc frame[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); + break; + } + + snapShotInfo[cur_obj_key].snapShotFace.width = face_expand_rect.width_; + snapShotInfo[cur_obj_key].snapShotFace.height = face_expand_rect.height_; + memcpy((void*)&snapShotInfo[cur_obj_key].face_info, (void*)&cur_det_info, sizeof(fd_info)); + + //矫正坐标 从行人抠图检测结果 -> 人脸外扩抠图坐标 + fd_info& tmp_info = snapShotInfo[cur_obj_key].face_info; + + for (int p = 0; p < FACIALFEAPOINTSIZE; p++) + { + tmp_info.facial_fea_point[p].x_ = + tmp_info.facial_fea_point[p].x_ - tmp_info.face_position.left_ + (face_ori_rect.left_ - face_expand_rect.left_); + tmp_info.facial_fea_point[p].y_ = + tmp_info.facial_fea_point[p].y_ - tmp_info.face_position.top_ + (face_ori_rect.top_ - face_expand_rect.top_); + } + + snapShotInfo[cur_obj_key].face_info.face_position = + { (face_ori_rect.left_ - face_expand_rect.left_), (face_ori_rect.top_ - face_expand_rect.top_), face_ori_rect.width_, face_ori_rect.height_ }; + + + cudacommon::CropImgGpu((unsigned char*)task.task_algorithm_data.frame, task.task_algorithm_data.width, task.task_algorithm_data.height, + (unsigned char*)snapShotInfo[cur_obj_key].snapShotFace.frame, face_expand_rect.left_, face_expand_rect.top_, face_expand_rect.width_, face_expand_rect.height_); + } + else + { + sy_rect face_ori_rect = { (int)(snapshot_left[ii] + cur_det_info.face_position.left_), + (int)(snapshot_top[ii] + cur_det_info.face_position.top_), + (int)(cur_det_info.face_position.width_), (int)(cur_det_info.face_position.height_) }; + + //更新人脸快照条件:① 角度满足条件 ② 面积比之前人脸面积大 + if (validAngle(cur_det_res.info[face_idx].roll, cur_det_res.info[face_idx].yaw, cur_det_res.info[face_idx].pitch, 15.0, 20.0) + && betterArea(face_ori_rect, snapShotInfo[cur_obj_key].face_info.face_position)) + { + int new_left = max(0, face_ori_rect.left_ - face_ori_rect.width_); + int new_top = max(0, face_ori_rect.top_ - face_ori_rect.height_); + int new_right = min((int)task.task_algorithm_data.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); + int new_bottom = min((int)task.task_algorithm_data.height - 1, (face_ori_rect.top_ + 2 * face_ori_rect.height_)); + int new_width = new_right - new_left; + int new_height = new_bottom - new_top; + + sy_rect face_expand_rect = { new_left, new_top, new_width, new_height }; + + //更新快照 + int face_img_length = 3 * face_expand_rect.width_ * face_expand_rect.height_; + + cudaFree(snapShotInfo[cur_obj_key].snapShotFace.frame); + cudaError_t cudaStatus = cudaMalloc((void**)&snapShotInfo[cur_obj_key].snapShotFace.frame, face_img_length * sizeof(unsigned char)); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "here cudaMalloc frame[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); + break; + } + + snapShotInfo[cur_obj_key].snapShotFace.width = face_expand_rect.width_; + snapShotInfo[cur_obj_key].snapShotFace.height = face_expand_rect.height_; + memcpy((void*)&snapShotInfo[cur_obj_key].face_info, (void*)&cur_det_info, sizeof(fd_info)); + + //矫正坐标 从行人抠图检测结果 -> 人脸外扩抠图坐标 + fd_info& tmp_info = snapShotInfo[cur_obj_key].face_info; + + for (int p = 0; p < FACIALFEAPOINTSIZE; p++) + { + tmp_info.facial_fea_point[p].x_ = + tmp_info.facial_fea_point[p].x_ - tmp_info.face_position.left_ + (face_ori_rect.left_ - face_expand_rect.left_); + tmp_info.facial_fea_point[p].y_ = + tmp_info.facial_fea_point[p].y_ - tmp_info.face_position.top_ + (face_ori_rect.top_ - face_expand_rect.top_); + } + + snapShotInfo[cur_obj_key].face_info.face_position = + {(face_ori_rect.left_ - face_expand_rect.left_), (face_ori_rect.top_ - face_expand_rect.top_), face_ori_rect.width_, face_ori_rect.height_}; + + cudacommon::CropImgGpu((unsigned char*)task.task_algorithm_data.frame, task.task_algorithm_data.width, task.task_algorithm_data.height, + (unsigned char*)snapShotInfo[cur_obj_key].snapShotFace.frame, face_expand_rect.left_, face_expand_rect.top_, face_expand_rect.width_, face_expand_rect.height_); + } + } + } + } + + if (face_det_result) + { + for (int fd_i = 0; fd_i < human_count; fd_i++) + delete[] face_det_result[fd_i].info; + delete face_det_result; + } } \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h index 7268573..ece4cde 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h @@ -18,6 +18,7 @@ #include "VehicleColor.h" #include "VehicleRearRecg.h" #include "VehicleRecognition.h" +#include "FaceDetModule.h" using namespace std; @@ -195,6 +196,8 @@ public: CropInfo cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Task task); + void cacheFaceSnapshotInfo(sy_img *human_img, int human_count, sy_point* ori_points, vector human_idx, vector human_obj_keys, int snapshot_left[], int snapshot_top[], Task task); + int getIndexByKey(OBJ_KEY newObj); private: @@ -216,6 +219,7 @@ private: VehiclePlate m_vehicle_plate; VehicleRearRecg m_vehicle_rear_recog; VehicleRecognition m_vehicle_recognition; + face_det_module m_face_det_module; queue count_person; queue count_bike; @@ -226,7 +230,6 @@ private: vector vehicle_result_v; sy_img * batch_hp = nullptr; - sy_img * batch_hcp = nullptr; sy_img * batch_vehicle = nullptr; sy_img * batch_vehicle_vf = nullptr;