#include "opencv2/opencv.hpp" #include "opencv2/highgui/highgui.hpp" #include "snapshot_helper.h" #include #include #include "HumanParsing.h" #include "HumanCarParsing.h" #include "VehiclePlate.h" #include "VehicleRecognition.h" #include "VehicleColor.h" #include "non_vehicle_fea_trt.h" //#include "HumanFeatures.h" #include "vehicle_features.h" #include "VehicleRearRecg.h" #include "CropImg.h" using namespace std; string ObjTypes[9] = { "行人", "自行车", "摩托车", "三轮车", "小型车", "大车", "卡车", "拖拉机", "中巴" }; string ObjTypesEnglish[9] = { "person", "bike", "motor", "tricycle", "car", "bigbus", "lorry", "tractor", "midibus" }; DWORD SnapshotThreadProcess(LPVOID param); DWORD SnapshotImageWriteThreadProcess(LPVOID param); #ifdef _MSC_VER char* GbkToUtf8(const char *src_str) { int len = MultiByteToWideChar(CP_ACP, 0, src_str, -1, NULL, 0); wchar_t* wstr = new wchar_t[len + 1]; memset(wstr, 0, len + 1); MultiByteToWideChar(CP_ACP, 0, src_str, -1, wstr, len); len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL); char* str = new char[len + 1]; memset(str, 0, len + 1); WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL); //string strTemp = str; if (wstr) delete[] wstr; //if (str) delete[] str; return str; } #endif void snapshot_helper::snapshot_helper_init(int gpuid, double gpu_total_memory, char* dbpath, sy_command hp_analysis_config, \ sy_command hcp_analysis_config, sy_command vehicle_analysis_config, sy_command vehicle_recg_config, sy_command vehicle_plate_det_recg_config, sy_command hf_recg_config, sy_command hcf_recg_config, sy_command vcf_recg_config) { hp_analysis_cf = hp_analysis_config; hcp_analysis_cf = hcp_analysis_config; vehicle_analysis_cf = vehicle_analysis_config; hf_recg_cf = hf_recg_config; hcf_recg_cf = hcf_recg_config; vcf_recg_cf = vcf_recg_config; char* dbpath_utf8 = nullptr; #ifdef _MSC_VER dbpath_utf8 = GbkToUtf8(dbpath); #else dbpath_utf8 = dbpath; #endif if (hp_analysis_config == SY_CONFIG_OPEN || hf_recg_config == SY_CONFIG_OPEN) { HumanParsing_Init(hp_handle, gpuid); } if (hcp_analysis_config == SY_CONFIG_OPEN || hcf_recg_config == SY_CONFIG_OPEN) { HumanCarParsing_Init(hcp_handle, gpuid); } if (hf_recg_config == SY_CONFIG_OPEN || hcf_recg_config == SY_CONFIG_OPEN) { NonVehicleFea_Init(nvf_handle, gpuid); } if (vehicle_analysis_config == SY_CONFIG_OPEN) { VehicleColor_Init(vc_handle, gpuid); VehiclePlateDetectRecog_Init(vp_handle, gpuid); VehicleRecognition_Init(vr_handle, dbpath_utf8, gpuid); VehicleRearRecg_Init(vrr_handle, dbpath, gpuid); } if (vehicle_analysis_config == SY_CONFIG_OPEN || vcf_recg_config == SY_CONFIG_OPEN) { vhd_features_init(vhd_handle, dbpath_utf8, gpuid); } if (vcf_recg_config == SY_CONFIG_OPEN) { vf_features_init(vf_handle, dbpath_utf8, gpuid); } if (gpu_total_memory < 9000) //8G显存,小内存方案 { OBJ_BATCH_COUNT = 20; OBJ_BATCH_COUNT_VEHICLE = 20; } else { OBJ_BATCH_COUNT = 20; OBJ_BATCH_COUNT_VEHICLE = 10; } #ifdef _MSC_VER delete[] dbpath_utf8; #endif 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]{}; //count_vehivle_finishanalysis = 0; ProcessSnapshotThread = boost::thread(SnapshotThreadProcess, this); auto writeThread1 = std::thread(SnapshotImageWriteThreadProcess, this); writeThread1.detach(); auto writeThread2 = std::thread(SnapshotImageWriteThreadProcess, this); writeThread2.detach(); auto writeThread3 = std::thread(SnapshotImageWriteThreadProcess, this); writeThread3.detach(); auto writeThread4 = std::thread(SnapshotImageWriteThreadProcess, this); writeThread4.detach(); auto writeThread5 = std::thread(SnapshotImageWriteThreadProcess, this); writeThread5.detach(); auto writeThread6 = std::thread(SnapshotImageWriteThreadProcess, this); writeThread6.detach(); auto writeThread7 = std::thread(SnapshotImageWriteThreadProcess, this); writeThread7.detach(); auto writeThread8 = std::thread(SnapshotImageWriteThreadProcess, this); writeThread8.detach(); auto writeThread9 = std::thread(SnapshotImageWriteThreadProcess, this); writeThread9.detach(); auto writeThread10 = std::thread(SnapshotImageWriteThreadProcess, this); writeThread10.detach(); auto writeThread11 = std::thread(SnapshotImageWriteThreadProcess, this); writeThread11.detach(); auto writeThread12 = std::thread(SnapshotImageWriteThreadProcess, this); writeThread12.detach(); } void snapshot_helper::snapshot_helper_release() { HumanParsing_Release(hp_handle); HumanCarParsing_Release(hcp_handle); VehicleColor_Release(vc_handle); VehiclePlateDetectRecog_Release(vp_handle); VehicleRecognition_Release(vr_handle); VehicleRearRecg_Release(vrr_handle); vhd_feature_release(vhd_handle); vf_feature_release(vf_handle); NonVehicleFea_Release(nvf_handle); 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; batch_vehicle = NULL; } if (batch_vehicle_vf != NULL) { for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE; ++i) { if (batch_vehicle_vf[i].data_ != 0) { cudaFree(batch_vehicle_vf[i].data_); batch_vehicle_vf[i].data_ = NULL; } } delete[] batch_vehicle_vf; batch_vehicle_vf = NULL; } while (1) { { std::lock_guard lock(threadMutex); if (snapshotImageQueue.empty()) break; } } ProcessSnapshotThread.interrupt(); //interrupt thread ProcessSnapshotThread.join(); //waiting thread finish } void snapshot_helper::add_task_info(int new_task_id, TASK_INFO new_task_info) { m_task_info[new_task_id] = new_task_info; } void snapshot_helper::delete_task_info(int new_task_id, TASK_INFO new_task_info) { m_task_info[new_task_id].image_folder = NULL; m_task_info[new_task_id].snapshot_folder = NULL; m_task_info[new_task_id].obj_callback = NULL; } int snapshot_helper::save_snapshot(OBJ_KEY obj_key) { OBJ_VALUE & obj_value = snapShotInfo[obj_key]; //delete by mliu 20191118 /*if (finished_save_ss_info.find(obj_key) != finished_save_ss_info.end()) { return 0; }*/ if (m_task_info[obj_key.videoID].image_folder) //保存视频原图 { auto begintime = std::chrono::system_clock::now(); auto dx_frame = ImgSaveCache.get_frame(obj_key); int data_size = dx_frame->width * dx_frame->height * IMG_CHANNELS; unsigned char *snapshotDataHost = new unsigned char[data_size] {}; memcpy(snapshotDataHost, dx_frame->frame, data_size * sizeof(unsigned char)); char snapShotName[260]; sprintf(snapShotName, "%s/%d.jpg", m_task_info[obj_key.videoID].image_folder, obj_key.objID); save_snapshot(true, obj_key, snapShotName, "cpu", snapshotDataHost, dx_frame->width, dx_frame->height, obj_key.videoID, obj_key.objID, 1, obj_value.box.left, obj_value.box.top, obj_value.box.right, obj_value.box.bottom); ImgSaveCache.release(obj_key); ////CPU save video screenshot //int data_size = obj_value.snapShot.width * obj_value.snapShot.height * IMG_CHANNELS; //unsigned char *snapshotDataHost = new unsigned char[data_size] {}; //cudaMemcpy(snapshotDataHost, obj_value.snapShot.frame, data_size * sizeof(unsigned char), cudaMemcpyDeviceToHost); // //char snapShotName[260]; //sprintf(snapShotName, "%s/%d.jpg", m_task_info[obj_key.videoID].image_folder, obj_key.objID); //save_snapshot(true, obj_key, snapShotName, "cpu", snapshotDataHost, obj_value.snapShot.width, obj_value.snapShot.height, obj_key.videoID, obj_key.objID, 1, obj_value.box.left, obj_value.box.top, obj_value.box.right, obj_value.box.bottom); //if (obj_value.snapShot.frame) //{ // auto cudaStatus = cudaGetLastError(); // if (cudaStatus != cudaSuccess) { // fprintf(stderr, "save_snapshot :: cudaGetLastError failed: %s\n", cudaGetErrorString(cudaStatus)); // } // cudaError_t cudastate = cudaFree(obj_value.snapShot.frame); // if (cudastate != cudaSuccess) { // fprintf(stderr, "save_snapshot :: cudaFree failed: %s\n", cudaGetErrorString(cudastate)); // } // obj_value.snapShot.frame = NULL; //} //int data_size = obj_value.snapShot.width * obj_value.snapShot.height * IMG_CHANNELS; //float *snapshotDataHost = new float[data_size] {}; //cudaMemcpy(snapshotDataHost, obj_value.snapShot.frame, data_size * sizeof(float), cudaMemcpyDeviceToHost); //char snapShotName[260]; //sprintf(snapShotName, "%s/%d.jpg", m_task_info[obj_key.videoID].image_folder, obj_key.objID); //save_snapshot(true, obj_key, snapShotName, "cpu", snapshotDataHost, obj_value.snapShot.width, obj_value.snapShot.height, obj_key.videoID, obj_key.objID, 1, obj_value.box.left, obj_value.box.top, obj_value.box.right, obj_value.box.bottom); //if (obj_value.snapShot.frame) //{ // auto cudaStatus = cudaGetLastError(); // if (cudaStatus != cudaSuccess) { // fprintf(stderr, "save_snapshot :: cudaGetLastError failed: %s\n", cudaGetErrorString(cudaStatus)); // } // cudaError_t cudastate = cudaFree(obj_value.snapShot.frame); // if (cudastate != cudaSuccess) { // fprintf(stderr, "save_snapshot :: cudaFree failed: %s\n", cudaGetErrorString(cudastate)); // } // obj_value.snapShot.frame = NULL; // //add by mliu 20191118 // snapShotInfo[obj_key].snapShot.frame = NULL; //} } if (m_task_info[obj_key.videoID].snapshot_folder) { //CPU save obj snapshot unsigned char* tempSnapShotHost = new unsigned char[3 * obj_value.snapShotLittle.height * obj_value.snapShotLittle.width * sizeof(unsigned char)]{}; cudaMemcpy(tempSnapShotHost, obj_value.snapShotLittle.frame, 3 * obj_value.snapShotLittle.height * obj_value.snapShotLittle.width * sizeof(unsigned char), cudaMemcpyDeviceToHost); char snapShotName[260]; sprintf(snapShotName, "%s/%d.jpg", m_task_info[obj_key.videoID].snapshot_folder, obj_key.objID); save_snapshot(false, obj_key, snapShotName, "cpu", tempSnapShotHost, obj_value.snapShotLittle.width, obj_value.snapShotLittle.height, obj_key.videoID, obj_key.objID, 0, obj_value.box.left, obj_value.box.top, obj_value.box.right, obj_value.box.bottom); if (tempSnapShotHost) { delete[] tempSnapShotHost; tempSnapShotHost = NULL; } } return 0; } void snapshot_helper::save_without_analysis(OBJ_KEY obj_key) { auto iter = snapShotInfo.find(obj_key); if (iter == snapShotInfo.end()) cout << "cant find" << endl; else { save_snapshot(obj_key); snapshot_res_callback(obj_key); if (iter->second.snapShotLittle.frame) { cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; snapShotInfo[obj_key].snapShotLittle.frame = NULL; } snapShotInfo.erase(iter); } } void snapshot_helper::object_attri_analysis() //二次属性分析接口 { //count_person.size()的类型是size_t不为0,因为这个地方直接用三元运算符的话,会强制类型转换到size_t,没有办法和0比较 int analysis_person_size = count_person.size() - OBJ_BATCH_COUNT; analysis_person_size = max(0, analysis_person_size); int analysis_bike_size = count_bike.size() - OBJ_BATCH_COUNT; analysis_bike_size = max(0, analysis_bike_size); int analysis_vehicle_size = count_vehicle_v.size() - OBJ_BATCH_COUNT_VEHICLE; analysis_vehicle_size = max(0, analysis_vehicle_size); int tmp_size = max(analysis_person_size, max(analysis_bike_size, analysis_vehicle_size)); int analysis_type = -1; if (tmp_size == 0) return; else if (tmp_size == analysis_person_size) analysis_type = HP_ANALYSIS; else if (tmp_size == analysis_bike_size) analysis_type = HCP_ANALYSIS; else analysis_type = VC_ANALYSIS; switch (analysis_type) { case HP_ANALYSIS: //printf("============ begin hp_analysis. ana size: %d. \n", count_person.size()); hp_analysis(); break; case HCP_ANALYSIS: //printf("============ begin hcp_analysis. ana size: %d. \n", count_bike.size()); hcp_analysis(); break; case VC_ANALYSIS: if (v_analysis == V_ANALYSIS_TYPE::VC_ANALYSIS) { //printf("============ begin vehicle_color_analysis \n"); if (vehicle_color_analysis()) v_analysis = V_ANALYSIS_TYPE::VPDR_ANALYSIS; else v_analysis = V_ANALYSIS_TYPE::VC_ANALYSIS; } else if (v_analysis == V_ANALYSIS_TYPE::VPDR_ANALYSIS) { //printf("============ begin vehicle_plate_dr_analysis \n"); if (vehicle_plate_dr_analysis()) v_analysis = V_ANALYSIS_TYPE::VR_VF_ANALYSIS; else v_analysis = V_ANALYSIS_TYPE::VC_ANALYSIS; } else if (v_analysis == V_ANALYSIS_TYPE::VR_VF_ANALYSIS) { //printf("============ begin vehicle_recg_analysis \n"); vehicle_recg_analysis(); v_analysis = V_ANALYSIS_TYPE::VC_ANALYSIS; } //printf("============ begin vc_vr_analysis. ana size: %d. \n", count_vehicle_v.size()); //vf_feature(); break; default: break; } } void snapshot_helper::finish_task_ss_analysis(int task_id, sy_command hp_analysis_config, sy_command hcp_analysis_config, sy_command vehicle_analysis_config, sy_command hf_recg_config, sy_command hcf_recg_config, sy_command vcf_recg_config) //是否开启车辆特征识别); //某一路任务结束了,立马对该路任务进行二次属性分析 { vector hp_keys; vector hcp_keys; vector vehicle_keys; vector vehicle_else; //仅保存的 for (auto iter = snapShotInfo.begin(); iter != snapShotInfo.end(); iter++) { if (iter->first.videoID == task_id) { if (iter->second.index.index == 0 && (hp_analysis_config == SY_CONFIG_OPEN || hf_recg_config == SY_CONFIG_OPEN) && m_task_info[task_id].snapshot_folder != NULL && iter->second.snapShotLittle.frame != NULL && iter->second.snapShotLittle.height == HP_HEIGHT && iter->second.snapShotLittle.width == HP_WIDTH) hp_keys.push_back(iter->first); else if ((iter->second.index.index == 1 || iter->second.index.index == 2) && (hcp_analysis_config == SY_CONFIG_OPEN || hcf_recg_config == SY_CONFIG_OPEN) && m_task_info[task_id].snapshot_folder != NULL && iter->second.snapShotLittle.frame != NULL && iter->second.snapShotLittle.height == HCP_HEIGHT && iter->second.snapShotLittle.width == HCP_WIDTH) hcp_keys.push_back(iter->first); else if ((iter->second.index.index == 8 || (iter->second.index.index >= 4 && iter->second.index.index <= 6)) && (vehicle_analysis_config == SY_CONFIG_OPEN || vcf_recg_config == SY_CONFIG_OPEN) && m_task_info[task_id].snapshot_folder != NULL && iter->second.snapShotLittle.frame != NULL && iter->second.snapShotLittle.height == VEHICLE_HEIGHT && iter->second.snapShotLittle.width == VEHICLE_WIDTH) vehicle_keys.push_back(iter->first); else vehicle_else.push_back(iter->first); } } //printf("hp:%d, hcp:%d, vehicle:%d, else:%d total:%d\n", hp_keys.size(), hcp_keys.size(), vehicle_keys.size(), count_else, snapShotInfo.size()); //printf("count_person:%d, count_bike:%d, count_vehicle:%d\n", count_person.size(), count_bike.size(), count_vehicle_v.size()); if (!hp_keys.empty()) { const int obj_batch_count = OBJ_BATCH_COUNT / OBJ_SCALE; const int hp_batch_size = hp_keys.size(); int hp_batch_count = obj_batch_count; for (int i = 0; i <= (hp_batch_size / obj_batch_count); ++i) { hp_analysis_res *result = nullptr; human_fea_result *result_f = nullptr; if (i == (hp_batch_size / obj_batch_count)) hp_batch_count = hp_batch_size % obj_batch_count; if (hp_batch_count == 0) continue; sy_img* finish_hp_img = new sy_img[hp_batch_count]{}; for (int j = 0; j < hp_batch_count; j++) { OBJ_KEY cur_obj_key = hp_keys[j]; finish_hp_img[j].set_data(HP_WIDTH, HP_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); } if (hp_analysis_config == SY_CONFIG_OPEN) { result = new hp_analysis_res[hp_batch_count]{}; HumanParsing_Process(hp_handle, finish_hp_img, hp_batch_count, result); } if (hf_recg_config == SY_CONFIG_OPEN) { result_f = new human_fea_result[hp_batch_count]{}; NonVehicleFea_Process(nvf_handle, finish_hp_img, hp_batch_count, result_f); } int resIndex = 0; for (int k = 0; k < hp_batch_count; k++) { auto iter = snapShotInfo.find(hp_keys[k]); if (iter == snapShotInfo.end()) resIndex++; //cout << iter_key.videoID << " " << iter_key.objID << " cant find" << endl; else { hp_result curRes = {}; if (hp_analysis_config == SY_CONFIG_OPEN) memcpy(curRes.res_objs.res_objs, result[resIndex].res_objs, sizeof(classify_obj_res)* HP_FIR_INDEX_SIZE); if (hf_recg_config == SY_CONFIG_OPEN) memcpy(curRes.feature, result_f[resIndex].human_fea, sizeof(int8)* HF_FEA_SIZE); snapshot_res_callback(hp_keys[k], &curRes); resIndex++; int count_person_size = count_person.size(); for (int c = 0; c < count_person_size; c++) { OBJ_KEY iter = count_person.front(); count_person.pop(); if (iter.videoID == hp_keys[k].videoID && iter.objID == hp_keys[k].objID) continue; count_person.push(iter); } if (count_person.size() == count_person_size) //当前hp_keys[k] 不在count_person数组里 { save_snapshot(hp_keys[k]); } if (iter->second.snapShotLittle.frame) { cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } snapShotInfo.erase(iter); } } hp_keys.erase(hp_keys.begin(), hp_keys.begin() + hp_batch_count); if (result != nullptr) { delete[] result; result = nullptr; } if (result_f != nullptr) { delete[] result_f; result_f = nullptr; } if (finish_hp_img != NULL) { delete[] finish_hp_img; finish_hp_img = NULL; } } } if (!hcp_keys.empty()) { 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]{}; for (int j = 0; j < hcp_batch_count; j++) { OBJ_KEY cur_obj_key = hcp_keys[j]; // printf() finish_hcp_img[j].set_data(HCP_WIDTH, HCP_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); } if (hcp_analysis_config == SY_CONFIG_OPEN) { result = new hcp_analysis_result[hcp_batch_count]{}; HumanCarParsing_Process(hcp_handle, finish_hcp_img, hcp_batch_count, result); } if (hcf_recg_cf == SY_CONFIG_OPEN) { result_f = new human_fea_result[hcp_batch_count]{}; NonVehicleFea_Process(nvf_handle, finish_hcp_img, hcp_batch_count, result_f); } int resIndex = 0; for (int k = 0; k < hcp_batch_count; k++) { auto iter = snapShotInfo.find(hcp_keys[k]); if (iter == snapShotInfo.end()) resIndex++; else { hcp_result curRes = {}; if (hcp_analysis_config == SY_CONFIG_OPEN) memcpy(curRes.res_objs.res_objs, result[resIndex].res_objs, sizeof(classify_obj_res)* HCP_FIR_INDEX_SIZE); if (hcf_recg_config == SY_CONFIG_OPEN) memcpy(curRes.feature, result_f[resIndex].human_fea, sizeof(int8)* HCF_FEA_SIZE); snapshot_res_callback(hcp_keys[k], &curRes); resIndex++; int count_bike_size = count_bike.size(); for (int c = 0; c < count_bike_size; c++) { OBJ_KEY iter = count_bike.front(); count_bike.pop(); if (iter.videoID == hcp_keys[k].videoID && iter.objID == hcp_keys[k].objID) continue; count_bike.push(iter); } if (count_bike.size() == count_bike_size) //当前hp_keys[k] 不在count_person数组里 { save_snapshot(hcp_keys[k]); } if (iter->second.snapShotLittle.frame) { cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } snapShotInfo.erase(iter); } } 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; } } } if (!vehicle_keys.empty()) { const int obj_batch_count = OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE; const int vehicle_batch_size = vehicle_keys.size(); int vehicle_batch_count = obj_batch_count; for (int i = 0; i <= (vehicle_batch_size / obj_batch_count); ++i) { if (i == (vehicle_batch_size / obj_batch_count)) vehicle_batch_count = vehicle_batch_size % obj_batch_count; if (vehicle_batch_count == 0) continue; sy_img* finish_vehicle_img = new sy_img[vehicle_batch_count]{}; for (int j = 0; j < vehicle_batch_count; j++) { OBJ_KEY cur_obj_key = vehicle_keys[j]; finish_vehicle_img[j].set_data(VEHICLE_WIDTH, VEHICLE_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); } vc_result *vcresult = new vc_result[vehicle_batch_count]{}; vplate_result *vp_result = new vplate_result[vehicle_batch_count]{}; vr_result *vrresult = new vr_result[vehicle_batch_count]{}; if (vehicle_analysis_config == SY_CONFIG_OPEN) { VehicleColor_Process(vc_handle, finish_vehicle_img, vehicle_batch_count, vcresult); VehiclePlateDetectRecog_Process(vp_handle, finish_vehicle_img, vehicle_batch_count, vp_result); VehicleRecog_Process(finish_vehicle_img, vehicle_batch_count, vrresult, &vehicle_keys[0] + i*obj_batch_count); } int8 ** fea = nullptr; if (vcf_recg_config == SY_CONFIG_OPEN) { fea = new int8*[vehicle_batch_count] {}; for (int ii = 0; ii < vehicle_batch_count; ++ii) { fea[ii] = new int8[FEATURESIZE]{}; } vf_features_process(vf_handle, finish_vehicle_img, vehicle_batch_count, fea); } int resIndex = 0; int feaIndex = 0; for (int vc_idx = 0; vc_idx < vehicle_batch_count; vc_idx++) { auto iter = snapShotInfo.find(vehicle_keys[vc_idx]); if (iter == snapShotInfo.end()) resIndex++; //cout << iter_key.videoID << " " <::iterator iter = count_vehicle_v.begin(); iter != count_vehicle_v.end(); ) { if (iter->videoID == vehicle_keys[vc_idx].videoID && iter->objID == vehicle_keys[vc_idx].objID) iter = count_vehicle_v.erase(iter); else { ++iter; } } if (count_vehicle_v.size() == count_vehicle_size) //当前hp_keys[k] 不在count_person数组里 { save_snapshot(vehicle_keys[vc_idx]); } if (iter->second.snapShotLittle.frame) { cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } snapShotInfo.erase(iter);//modified by dyq } } vehicle_result_v.clear(); vector().swap(vehicle_result_v); if (fea != nullptr) { for (int ii = 0; ii < vehicle_batch_count; ++ii) { delete[] fea[ii]; } delete[] fea; fea = nullptr; } if (vcresult != NULL) { delete[] vcresult; vcresult = NULL; } if (vp_result != NULL) { delete[] vp_result; vp_result = NULL; } if (vrresult != NULL) { delete[] vrresult; vrresult = NULL; } if (finish_vehicle_img != NULL) { delete[] finish_vehicle_img; finish_vehicle_img = NULL; } vehicle_keys.erase(vehicle_keys.begin(), vehicle_keys.begin() + vehicle_batch_count); } v_analysis = V_ANALYSIS_TYPE::VC_ANALYSIS; } if (!vehicle_else.empty()) { const int else_size = vehicle_else.size(); for (int k = 0; k < else_size; k++) { auto iter = snapShotInfo.find(vehicle_else[k]); if (iter == snapShotInfo.end()) continue; else { save_without_analysis(iter->first); } } } } void snapshot_helper::hp_analysis() { if (count_person.size() >= OBJ_BATCH_COUNT) { #ifdef LOG_INFO std::cout << "------ begin HumanParsing_Process -----" << std::endl; #ifdef _MSC_VER LARGE_INTEGER nFreq, nBeginTime, nEndTime; LARGE_INTEGER nSaveBeginTime, nSaveEndTime; QueryPerformanceFrequency(&nFreq); QueryPerformanceCounter(&nBeginTime); double time_val = 0.0; #else gettimeofday(&t1, NULL); #endif #endif for (int index = 0; index < OBJ_SCALE; ++index) { vector erase_obj_key; hp_analysis_res *result = nullptr; human_fea_result * result_f = nullptr; int obj_batch_count = 0; for (int i = 0; i < OBJ_BATCH_COUNT / OBJ_SCALE; i++) { OBJ_KEY cur_obj_key = count_person.front(); count_person.pop(); auto iter = snapShotInfo.find(cur_obj_key); if (iter == snapShotInfo.end() || iter->second.snapShotLittle.width != HP_WIDTH || iter->second.snapShotLittle.height != HP_HEIGHT || iter->second.snapShotLittle.frame == NULL || iter->second.index.index != 0) { printf("=================== height frame error or not find ======================\n"); if (iter != snapShotInfo.end()) { if (iter->second.snapShotLittle.frame) { cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } snapShotInfo.erase(cur_obj_key); } erase_snapshotImage(cur_obj_key); continue; } //printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~count_person = %d\n", count_person.size()); erase_obj_key.push_back(cur_obj_key); batch_hp[i].set_data(HP_WIDTH, HP_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); ++obj_batch_count; } if (hp_analysis_cf == SY_CONFIG_OPEN) { result = new hp_analysis_res[obj_batch_count]{}; HumanParsing_Process(hp_handle, batch_hp, obj_batch_count, result); } if (hf_recg_cf == SY_CONFIG_OPEN) { result_f = new human_fea_result[obj_batch_count]{}; NonVehicleFea_Process(nvf_handle, batch_hp, obj_batch_count, result_f); } #ifdef LOG_INFO #ifdef _MSC_VER QueryPerformanceCounter(&nEndTime); time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; std::printf("HumanParsing_Process: %.2f ms \n", time_val); #else /* gettimeofday(&t2, NULL); time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; printf("HumanParsing_Process = %lf ms\n", time_val); */ #endif #endif //删除已经进行保存和二次属性分析的目标 int resIndex = 0; for (auto iter_key : erase_obj_key) { auto iter = snapShotInfo.find(iter_key); hp_result curRes{}; if (hp_analysis_cf == SY_CONFIG_OPEN) memcpy(&curRes.res_objs, result[resIndex].res_objs, sizeof(classify_obj_res)* HP_FIR_INDEX_SIZE); if (hf_recg_cf == SY_CONFIG_OPEN) memcpy(curRes.feature, result_f[resIndex].human_fea, sizeof(int8)* HF_FEA_SIZE); ++resIndex; snapshot_res_callback(iter_key, &curRes); if (iter->second.snapShotLittle.frame) { cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } snapShotInfo.erase(iter); } erase_obj_key.clear(); vector().swap(erase_obj_key); if (result != nullptr) { delete[] result; result = nullptr; } if (result_f != nullptr) { delete[] result_f; result_f = nullptr; } #ifdef LOG_INFO #ifdef _MSC_VER QueryPerformanceCounter(&nEndTime); time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; std::printf("total: %.2f ms \n", time_val); #else /* gettimeofday(&t2, NULL); time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; printf("HumanParsing_Process = %lf ms\n", time_val); */ #endif std::cout << "----- end HumanParsing_Process -----" << std::endl; #endif } } } void snapshot_helper::hp_analysis(OBJ_KEY obj_key) { count_person.push(obj_key); } void snapshot_helper::hcp_analysis() { if (count_bike.size() >= OBJ_BATCH_COUNT) { for (int index = 0; index < OBJ_SCALE; ++index) { vector erase_obj_key; #ifdef LOG_INFO std::cout << "----- begin HumanCarParsing_Process -----" << endl; #ifdef _MSC_VER LARGE_INTEGER nFreq, nBeginTime, nEndTime; LARGE_INTEGER nSaveBeginTime, nSaveEndTime; QueryPerformanceFrequency(&nFreq); QueryPerformanceCounter(&nBeginTime); double time_val = 0.0; #else gettimeofday(&t1, NULL); #endif #endif int obj_batch_count = 0; hcp_analysis_result *result = nullptr; human_fea_result * result_f = nullptr; for (int i = 0; i < OBJ_BATCH_COUNT/ OBJ_SCALE; i++) { OBJ_KEY cur_obj_key = count_bike.front(); count_bike.pop(); auto iter = snapShotInfo.find(cur_obj_key); if (iter == snapShotInfo.end() || iter->second.snapShotLittle.width != HCP_WIDTH || iter->second.snapShotLittle.height != HCP_HEIGHT || iter->second.snapShotLittle.frame == NULL || (1 != iter->second.index.index && 2 != iter->second.index.index)) { printf("=================== height frame error or not find ======================\n"); if (iter != snapShotInfo.end()) { if (iter->second.snapShotLittle.frame) { cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } snapShotInfo.erase(cur_obj_key); } erase_snapshotImage(cur_obj_key); continue; } erase_obj_key.push_back(cur_obj_key); batch_hcp[i].set_data(HCP_WIDTH, HCP_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); ++obj_batch_count; } //printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~count_bike = %d\n", count_bike.size()); if (hcp_analysis_cf == SY_CONFIG_OPEN) { result = new hcp_analysis_result[obj_batch_count]{}; HumanCarParsing_Process(hcp_handle, batch_hcp, obj_batch_count, result); } if (hcf_recg_cf == SY_CONFIG_OPEN) { result_f = new human_fea_result[obj_batch_count]{}; NonVehicleFea_Process(nvf_handle, batch_hcp, obj_batch_count, result_f); } #ifdef LOG_INFO #ifdef _MSC_VER QueryPerformanceCounter(&nEndTime); time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; printf("HumanCarParsing_Process: %.2f ms \n", time_val); #else /* gettimeofday(&t2, NULL); time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; printf("HumanCarParsing_Process = %lf ms\n", time_val); */ #endif cout << "----- end HumanCarParsing_Process -----" << endl; #endif int resIndex = 0; for (auto iter_key : erase_obj_key) { auto iter = snapShotInfo.find(iter_key); hcp_result curRes{}; if (hcp_analysis_cf == SY_CONFIG_OPEN) memcpy(&curRes.res_objs, result[resIndex].res_objs, sizeof(classify_obj_res)* HCP_FIR_INDEX_SIZE); if (hcf_recg_cf == SY_CONFIG_OPEN) memcpy(curRes.feature, result_f[resIndex].human_fea, sizeof(int8)* HCF_FEA_SIZE); resIndex++; snapshot_res_callback(iter_key, &curRes); if (iter->second.snapShotLittle.frame) { cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } snapShotInfo.erase(iter); } erase_obj_key.clear(); vector().swap(erase_obj_key); if (result != nullptr) { delete[] result; result = nullptr; } if (result_f != nullptr) { delete[] result_f; result_f = nullptr; } } } } void snapshot_helper::hcp_analysis(OBJ_KEY obj_key) { count_bike.push(obj_key); } void snapshot_helper::vehicle_analysis(OBJ_KEY obj_key) { count_vehicle_v.push_back(obj_key); } bool snapshot_helper::vehicle_color_analysis() { if (vehicle_analysis_cf == SY_CONFIG_OPEN) { //printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~count_vehicle_v = %d\n", count_vehicle_v.size()); for (int index = 0; index < OBJ_SCALE; ++index) { #ifdef LOG_INFO cout << "----- begin VehicleColor_Process -----" << endl; #ifdef _MSC_VER LARGE_INTEGER nFreq, nBeginTime, nEndTime; LARGE_INTEGER nSaveBeginTime, nSaveEndTime; QueryPerformanceFrequency(&nFreq); QueryPerformanceCounter(&nBeginTime); double time_val = 0.0; #else gettimeofday(&t1, NULL); #endif #endif for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE/ OBJ_SCALE; i++) { OBJ_KEY cur_obj_key = count_vehicle_v[i]; auto iter = snapShotInfo.find(cur_obj_key); if (iter == snapShotInfo.end() || iter->second.snapShotLittle.width != VEHICLE_WIDTH || iter->second.snapShotLittle.height != VEHICLE_HEIGHT || iter->second.snapShotLittle.frame == NULL || (8 != iter->second.index.index && (iter->second.index.index < 4 || iter->second.index.index > 6))) { printf("=================== height frame error or not find ======================\n"); if (iter != snapShotInfo.end()) { if (iter->second.snapShotLittle.frame) { cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } snapShotInfo.erase(cur_obj_key); } count_vehicle_v.erase(count_vehicle_v.begin() + i); erase_snapshotImage(cur_obj_key); return false; } batch_vehicle[i].set_data(VEHICLE_WIDTH, VEHICLE_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); } vc_result *vcresult = new vc_result[OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE]{}; VehicleColor_Process(vc_handle, batch_vehicle, OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE, vcresult); #ifdef LOG_INFO #ifdef _MSC_VER QueryPerformanceCounter(&nEndTime); time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; printf("VehicleColor_Process: %.2f ms \n", time_val); #else /* gettimeofday(&t2, NULL); time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; printf("VehicleColor_Process = %lf ms\n", time_val); */ #endif #endif for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE; i++) { auto iter = snapShotInfo.find(count_vehicle_v[i]); if (iter == snapShotInfo.end()) { cout << " cant find" << endl; } else { vehicle_result curRes = {}; memcpy(&curRes.vc_res, &vcresult[i], sizeof(vc_result)); vehicle_result_v.push_back(curRes); } } if (vcresult != NULL) { delete[] vcresult; vcresult = NULL; } } } return true; } bool snapshot_helper::vehicle_plate_dr_analysis() { if (vehicle_analysis_cf == SY_CONFIG_OPEN) { for (int index = 0; index < OBJ_SCALE; ++index) { #ifdef LOG_INFO cout << "----- begin VEHICLEPLATEAnalysis -----" << endl; #ifdef _MSC_VER LARGE_INTEGER nFreq, nBeginTime, nEndTime; LARGE_INTEGER nSaveBeginTime, nSaveEndTime; QueryPerformanceFrequency(&nFreq); QueryPerformanceCounter(&nBeginTime); double time_val = 0.0; #else gettimeofday(&t1, NULL); #endif #endif for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE; i++) { OBJ_KEY cur_obj_key = count_vehicle_v[i]; auto iter = snapShotInfo.find(cur_obj_key); if (iter == snapShotInfo.end() || iter->second.snapShotLittle.width != VEHICLE_WIDTH || iter->second.snapShotLittle.height != VEHICLE_HEIGHT || iter->second.snapShotLittle.frame == NULL || (8 != iter->second.index.index && (iter->second.index.index < 4 || iter->second.index.index > 6))) { printf("=================== height frame error or not find ======================\n"); if (iter != snapShotInfo.end()) { if (iter->second.snapShotLittle.frame) { cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } snapShotInfo.erase(cur_obj_key); } count_vehicle_v.erase(count_vehicle_v.begin() + i); vehicle_result_v.clear(); erase_snapshotImage(cur_obj_key); return false; } batch_vehicle[i].set_data(VEHICLE_WIDTH, VEHICLE_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); } vplate_result *vp_result = new vplate_result[OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE]{}; VehiclePlateDetectRecog_Process(vp_handle, batch_vehicle, OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE, vp_result); #ifdef LOG_INFO #ifdef _MSC_VER QueryPerformanceCounter(&nEndTime); time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; printf("VEHICLEPLATEAnalysis: %.2f ms \n", time_val); #else /* gettimeofday(&t2, NULL); time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; printf("VehicleColor_Process = %lf ms\n", time_val); */ #endif #endif int resIndex = 0; for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE; i++) { auto iter = snapShotInfo.find(count_vehicle_v[i]); if (iter == snapShotInfo.end()) resIndex++; else { vehicle_result &curRes = vehicle_result_v[i]; memcpy(&curRes.vp_res, &vp_result[resIndex], sizeof(vplate_result)); resIndex++; } } if (vp_result != NULL) { delete[] vp_result; vp_result = NULL; } } } return true; } void snapshot_helper::VehicleRecog_Process(sy_img * batch_img, int batchsize, vr_result *&vresult, OBJ_KEY* obj_keys) { int index_head = 0; int index_rear = 0; vector mp_head; vector mp_rear; sy_img * batch_vehicle_head = new sy_img[batchsize]{}; sy_img * batch_vehicle_rear = new sy_img[batchsize]{}; vhd_result * vhd_res = new vhd_result[batchsize]{}; vhd_features_process(vhd_handle, batch_img, batchsize, vhd_res); for (int vc_idx = 0; vc_idx < batchsize; vc_idx++) { OBJ_KEY cur_obj_key = obj_keys[vc_idx]; vhd_result & result = vhd_res[vc_idx]; if (result.obj_count_ == 0) //若没有检测到车头/车尾,即认定为车身,车身直接原图送车尾车型识别 { batch_vehicle_rear[index_rear].w_ = VEHICLE_WIDTH; batch_vehicle_rear[index_rear].h_ = VEHICLE_HEIGHT; batch_vehicle_rear[index_rear].c_ = IMG_CHANNELS; if (batch_vehicle_rear[index_rear].data_ == 0) { cudaMalloc(&batch_vehicle_rear[index_rear].data_, VEHICLE_WIDTH * VEHICLE_HEIGHT * IMG_CHANNELS * sizeof(unsigned char)); } cudaMemcpy(batch_vehicle_rear[index_rear].data_, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame, VEHICLE_WIDTH * VEHICLE_HEIGHT * IMG_CHANNELS * sizeof(unsigned char), cudaMemcpyDeviceToDevice); ++index_rear; mp_rear.push_back(vc_idx); continue; } int max_score_index = 0; //若一张车身图检测到多个车头尾,取置信度最高做车型识别 float max_score = 0.0; for (int c = 0; c < result.obj_count_; ++c) { if (result.obj_results_[c].obj_score > max_score) { max_score_index = c; max_score = result.obj_results_[c].obj_score; } } if (result.obj_results_[max_score_index].obj_index == 0) //车头 { int w_imglength = result.obj_results_[max_score_index].obj_rect.width_ * result.obj_results_[max_score_index].obj_rect.height_ *IMG_CHANNELS; if (batch_vehicle_head[index_head].data_ == 0) { cudaMalloc(&batch_vehicle_head[index_head].data_, w_imglength * sizeof(unsigned char)); } cudacommon::CropImgGpu((unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame, VEHICLE_WIDTH, VEHICLE_HEIGHT, batch_vehicle_head[index_head].data_, result.obj_results_[max_score_index].obj_rect.left_, result.obj_results_[max_score_index].obj_rect.top_, result.obj_results_[max_score_index].obj_rect.width_, result.obj_results_[max_score_index].obj_rect.height_); batch_vehicle_head[index_head].w_ = result.obj_results_[max_score_index].obj_rect.width_; batch_vehicle_head[index_head].h_ = result.obj_results_[max_score_index].obj_rect.height_; batch_vehicle_head[index_head].c_ = IMG_CHANNELS; ++index_head; mp_head.push_back(vc_idx); } else if (result.obj_results_[max_score_index].obj_index == 1) //车尾 { int w_imglength = result.obj_results_[max_score_index].obj_rect.width_ * result.obj_results_[max_score_index].obj_rect.height_ *IMG_CHANNELS; if (batch_vehicle_rear[index_rear].data_ == 0) { cudaMalloc(&batch_vehicle_rear[index_rear].data_, w_imglength * sizeof(unsigned char)); } cudacommon::CropImgGpu((unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame, VEHICLE_WIDTH, VEHICLE_HEIGHT, batch_vehicle_rear[index_rear].data_, result.obj_results_[max_score_index].obj_rect.left_, result.obj_results_[max_score_index].obj_rect.top_, result.obj_results_[max_score_index].obj_rect.width_, result.obj_results_[max_score_index].obj_rect.height_); batch_vehicle_rear[index_rear].w_ = result.obj_results_[max_score_index].obj_rect.width_; batch_vehicle_rear[index_rear].h_ = result.obj_results_[max_score_index].obj_rect.height_; batch_vehicle_rear[index_rear].c_ = IMG_CHANNELS; ++index_rear; mp_rear.push_back(vc_idx); } } cudaDeviceSynchronize();//将会一直处于阻塞状态,直到前面所有请求的任务已经被全部执行完毕 if (index_head != 0) { vr_result *vrresult = new vr_result[index_head]{}; VehicleRecognition_Process(vr_handle, batch_vehicle_head, index_head, vrresult); int resIndex = 0; for (auto & item : mp_head) { vr_result &curRes = vresult[item]; memcpy(&vresult[item], &vrresult[resIndex], sizeof(vr_result)); resIndex++; } delete[] vrresult; vrresult = NULL; } if (index_rear != 0) { vr_result *vrresult = new vr_result[index_rear]{}; VehicleRearRecg_Process(vrr_handle, batch_vehicle_rear, index_rear, vrresult); int resIndex = 0; for (auto & item : mp_rear) { vr_result &curRes = vresult[item]; memcpy(&vresult[item], &vrresult[resIndex], sizeof(vr_result)); resIndex++; } delete[] vrresult; vrresult = NULL; } if (vhd_res != NULL) { delete[] vhd_res; vhd_res = NULL; } for (size_t i = 0; i < batchsize; i++) { if (batch_vehicle_head[i].data_ != NULL) { cudaFree(batch_vehicle_head[i].data_); batch_vehicle_head[i].data_ = NULL; } } delete[] batch_vehicle_head; batch_vehicle_head = NULL; for (size_t i = 0; i < batchsize; i++) { if (batch_vehicle_rear[i].data_ != NULL) { cudaFree(batch_vehicle_rear[i].data_); batch_vehicle_rear[i].data_ = NULL; } } delete[] batch_vehicle_rear; batch_vehicle_rear = NULL; return; } bool snapshot_helper::vehicle_recg_analysis() { if (vehicle_analysis_cf == SY_CONFIG_OPEN || vcf_recg_cf == SY_CONFIG_OPEN) { for (int index = 0; index < OBJ_SCALE; ++index) { #ifdef LOG_INFO cout << "----- begin VehicleColor_Process -----" << endl; #ifdef _MSC_VER LARGE_INTEGER nFreq, nBeginTime, nEndTime; LARGE_INTEGER nSaveBeginTime, nSaveEndTime; QueryPerformanceFrequency(&nFreq); QueryPerformanceCounter(&nBeginTime); double time_val = 0.0; #else gettimeofday(&t1, NULL); #endif #endif for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE; i++) { OBJ_KEY cur_obj_key = count_vehicle_v[i]; auto iter = snapShotInfo.find(cur_obj_key); if (iter == snapShotInfo.end() || iter->second.snapShotLittle.width != VEHICLE_WIDTH || iter->second.snapShotLittle.height != VEHICLE_HEIGHT || iter->second.snapShotLittle.frame == NULL || (8 != iter->second.index.index && (iter->second.index.index < 4 || iter->second.index.index > 6))) { printf("=================== height frame error or not find ======================\n"); if (iter != snapShotInfo.end()) { if (iter->second.snapShotLittle.frame) { cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } snapShotInfo.erase(cur_obj_key); } count_vehicle_v.erase(count_vehicle_v.begin() + i); vehicle_result_v.clear(); erase_snapshotImage(cur_obj_key); return false; } batch_vehicle[i].set_data(VEHICLE_WIDTH, VEHICLE_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); } if (vehicle_analysis_cf == SY_CONFIG_OPEN) { int index_head = 0; int index_rear = 0; map mp_head; map mp_rear; sy_img * batch_vehicle_head = new sy_img[OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE]{}; sy_img * batch_vehicle_rear = new sy_img[OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE]{}; vhd_result * vhd_res = new vhd_result[OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE]{}; vhd_features_process(vhd_handle, batch_vehicle, OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE, vhd_res); for (int vc_idx = 0; vc_idx < OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE; vc_idx++) { OBJ_KEY cur_obj_key = count_vehicle_v[vc_idx]; vhd_result & result = vhd_res[vc_idx]; if (result.obj_count_ == 0) //若没有检测到车头/车尾,即认定为车身,车身直接原图送车尾车型识别 { batch_vehicle_rear[index_rear].w_ = VEHICLE_WIDTH; batch_vehicle_rear[index_rear].h_ = VEHICLE_HEIGHT; batch_vehicle_rear[index_rear].c_ = IMG_CHANNELS; //batch_vehicle_rear[index_rear].data_ = (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame; if (batch_vehicle_rear[index_rear].data_ == 0) { cudaMalloc(&batch_vehicle_rear[index_rear].data_, VEHICLE_WIDTH * VEHICLE_HEIGHT * IMG_CHANNELS * sizeof(unsigned char)); } cudaMemcpy(batch_vehicle_rear[index_rear].data_, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame, VEHICLE_WIDTH * VEHICLE_HEIGHT * IMG_CHANNELS * sizeof(unsigned char), cudaMemcpyDeviceToDevice); ++index_rear; mp_rear.insert({ vc_idx, cur_obj_key }); continue; } int max_score_index = 0; //若一张车身图检测到多个车头尾,取置信度最高做车型识别 float max_score = 0.0; for (int c = 0; c < result.obj_count_; ++c) { if (result.obj_results_[c].obj_score > max_score) { max_score_index = c; max_score = result.obj_results_[c].obj_score; } } if (result.obj_results_[max_score_index].obj_index == 0) //车头 { int w_imglength = result.obj_results_[max_score_index].obj_rect.width_ * result.obj_results_[max_score_index].obj_rect.height_ *IMG_CHANNELS; if (batch_vehicle_head[index_head].data_ == 0) { cudaMalloc(&batch_vehicle_head[index_head].data_, w_imglength * sizeof(unsigned char)); } cudacommon::CropImgGpu((unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame, VEHICLE_WIDTH, VEHICLE_HEIGHT, batch_vehicle_head[index_head].data_, result.obj_results_[max_score_index].obj_rect.left_, result.obj_results_[max_score_index].obj_rect.top_, result.obj_results_[max_score_index].obj_rect.width_, result.obj_results_[max_score_index].obj_rect.height_); batch_vehicle_head[index_head].w_ = result.obj_results_[max_score_index].obj_rect.width_; batch_vehicle_head[index_head].h_ = result.obj_results_[max_score_index].obj_rect.height_; batch_vehicle_head[index_head].c_ = IMG_CHANNELS; ++index_head; mp_head.insert({ vc_idx, cur_obj_key }); } else if (result.obj_results_[max_score_index].obj_index == 1) //车尾 { int w_imglength = result.obj_results_[max_score_index].obj_rect.width_ * result.obj_results_[max_score_index].obj_rect.height_ *IMG_CHANNELS; if (batch_vehicle_rear[index_rear].data_ == 0) { cudaMalloc(&batch_vehicle_rear[index_rear].data_, w_imglength * sizeof(unsigned char)); } cudacommon::CropImgGpu((unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame, VEHICLE_WIDTH, VEHICLE_HEIGHT, batch_vehicle_rear[index_rear].data_, result.obj_results_[max_score_index].obj_rect.left_, result.obj_results_[max_score_index].obj_rect.top_, result.obj_results_[max_score_index].obj_rect.width_, result.obj_results_[max_score_index].obj_rect.height_); batch_vehicle_rear[index_rear].w_ = result.obj_results_[max_score_index].obj_rect.width_; batch_vehicle_rear[index_rear].h_ = result.obj_results_[max_score_index].obj_rect.height_; batch_vehicle_rear[index_rear].c_ = IMG_CHANNELS; ++index_rear; mp_rear.insert({ vc_idx, cur_obj_key }); } } cudaDeviceSynchronize();//将会一直处于阻塞状态,直到前面所有请求的任务已经被全部执行完毕 if (index_head != 0) { vr_result *vrresult = new vr_result[index_head]{}; VehicleRecognition_Process(vr_handle, batch_vehicle_head, index_head, vrresult); int resIndex = 0; for (auto & item : mp_head) { auto iter = snapShotInfo.find(item.second); if (iter == snapShotInfo.end()) resIndex++; //cout << iter_key.videoID << " " < only_vf_result; //仅仅只做vf的分析结果 only_vf_result.resize(OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE); if (vcf_recg_cf == SY_CONFIG_OPEN) { int8 ** fea = new int8*[OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE] {}; for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE; ++i) { fea[i] = new int8[FEATURESIZE]{}; memset(fea[i], 0, sizeof(int8) * FEATURESIZE); } vf_features_process(vf_handle, batch_vehicle, OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE, fea); int resIndex = 0; for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE; i++) { auto iter = snapShotInfo.find(count_vehicle_v[i]); //for (auto & item : mp_head) //{ //auto iter = snapShotInfo.find(item.second); if (iter == snapShotInfo.end()) { resIndex++; cerr << count_vehicle_v[i].videoID << " " << count_vehicle_v[i].objID << " cant find" << endl; } else { int8 * feaRes = fea[resIndex]; if (vehicle_analysis_cf == SY_CONFIG_CLOSE) { vehicle_result &curRes = only_vf_result[i]; memcpy(curRes.feature, feaRes, sizeof(int8) *FEATURESIZE); resIndex++; } else if (vehicle_analysis_cf == SY_CONFIG_OPEN) { vehicle_result &curRes = vehicle_result_v[i]; memcpy(curRes.feature, feaRes, sizeof(int8) *FEATURESIZE); resIndex++; } } } if (fea != NULL) { for (int b = 0; b < OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE; b++) { if (fea[b] != NULL) { delete[] fea[b]; fea[b] = NULL; } } delete[] fea; fea = NULL; } } for (int c = 0; c < OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE; c++) { auto iter = snapShotInfo.find(count_vehicle_v[c]); if (vehicle_analysis_cf == SY_CONFIG_CLOSE) { vehicle_result &curRes = only_vf_result[c]; snapshot_res_callback(iter->first, &curRes); } else if (vehicle_analysis_cf == SY_CONFIG_OPEN) { vehicle_result &curRes = vehicle_result_v[c]; snapshot_res_callback(iter->first, &curRes); } if (iter->second.snapShotLittle.frame) { cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } snapShotInfo.erase(iter); } count_vehicle_v.erase(count_vehicle_v.begin(), count_vehicle_v.begin() + OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE); if (vehicle_analysis_cf == SY_CONFIG_OPEN) vehicle_result_v.erase(vehicle_result_v.begin(), vehicle_result_v.begin() + OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE); } } return true; } void snapshot_helper::snapshot_res_callback(OBJ_KEY obj_key,/* OBJ_VALUE obj_value,*/ void* analysisRes) { char snapShotName[260] = {}; OBJ_VALUE &obj_value = snapShotInfo[obj_key]; video_object_snapshot newVideoObj{}; newVideoObj.task_id = obj_key.videoID; newVideoObj.object_id = obj_key.objID; int cur_task_id = newVideoObj.task_id; newVideoObj.left = obj_value.box.left /** tasks[cur_task_id].taskHeightWidthRatio.width*/; newVideoObj.right = obj_value.box.right /** tasks[cur_task_id].taskHeightWidthRatio.width*/; newVideoObj.top = obj_value.box.top /** tasks[cur_task_id].taskHeightWidthRatio.height*/; newVideoObj.bottom = obj_value.box.bottom /** tasks[cur_task_id].taskHeightWidthRatio.height*/; newVideoObj.confidence = obj_value.confidence; if (m_task_info[obj_key.videoID].image_folder != NULL) sprintf(snapShotName, "%s%d.jpg", m_task_info[obj_key.videoID].image_folder, newVideoObj.object_id); else sprintf(snapShotName, ""); strcpy(newVideoObj.video_image_path, snapShotName); if (m_task_info[obj_key.videoID].snapshot_folder != NULL) sprintf(snapShotName, "%s%d.jpg", m_task_info[obj_key.videoID].snapshot_folder, newVideoObj.object_id); else sprintf(snapShotName, ""); strcpy(newVideoObj.snapshot_image_path, snapShotName); strcpy(newVideoObj.obj_type, ObjTypes[obj_value.index.index].c_str()); newVideoObj.object_type_index = obj_value.index.index;// add by dyq newVideoObj.progress = 0; if (m_task_info[obj_key.videoID].task_total_framecount == -1 || m_task_info[obj_key.videoID].task_total_framecount == 0) newVideoObj.progress = 0; else newVideoObj.progress = (double)obj_value.frameCount / m_task_info[obj_key.videoID].task_total_framecount; //printf("finish copy res. "); newVideoObj.analysisRes = NULL; if (NULL != analysisRes) { if (0 == obj_value.index.index) { newVideoObj.analysisRes = new hp_result{}; memcpy(newVideoObj.analysisRes, analysisRes, sizeof(hp_result)); } else if (1 == obj_value.index.index || 2 == obj_value.index.index) { newVideoObj.analysisRes = new hcp_result{}; memcpy(newVideoObj.analysisRes, analysisRes, sizeof(hcp_result)); } else if ((8 == obj_value.index.index || (obj_value.index.index >= 4 && obj_value.index.index <= 6)) && obj_value.snapShotLittle.width == VEHICLE_WIDTH && obj_value.snapShotLittle.height == VEHICLE_HEIGHT) { newVideoObj.analysisRes = new vehicle_result{}; memcpy(newVideoObj.analysisRes, analysisRes, sizeof(vehicle_result)); //此处指针应该是浅拷贝 因此不需要释放两次analysisRes和newVideoObj.analysisRes,最终回调之后释放一次即可 } } //printf("finish copy anaysis. "); { std::lock_guard lock(analysisThreadMutex); finished_analysis_ss_info[obj_key] = newVideoObj; } /*if (m_task_info[obj_key.videoID].obj_callback != NULL) m_task_info[obj_key.videoID].obj_callback(&newVideoObj); if (newVideoObj.analysisRes != NULL) { delete newVideoObj.analysisRes; newVideoObj.analysisRes = NULL; }*/ } #include void snapshot_helper::erase_snapshotImage(OBJ_KEY obj_key) { //std::ofstream os("D:\\vptlog1_2.txt", std::ofstream::out | std::ofstream::trunc); //os << unitbuf; //os << obj_key.videoID << " and " << obj_key.objID << endl; bool image_unsave = false; bool sna_unsave = false; std::lock_guard lock(threadMutex); int size = snapshotImageQueue.size(); for (int i = 0; i < size; ++i) { auto item = snapshotImageQueue.front(); snapshotImageQueue.pop(); if (item.obj_key == obj_key) { if (!item.is_image) sna_unsave = true; else image_unsave = true; if (item.flag == true && item.image.data != NULL) { delete[] item.image.data; item.image.data = NULL; } } else { snapshotImageQueue.push(item); } } if (!sna_unsave) { //os << 1 << endl; finished_save_ss_info.erase(obj_key); char snapShotName[260] = {}; sprintf(snapShotName, "%s/%d.jpg", m_task_info[obj_key.videoID].snapshot_folder, obj_key.objID); remove(snapShotName); //os << snapShotName << endl; } if (!image_unsave) { //os << 2 << endl; char snapShotName[260] = {}; sprintf(snapShotName, "%s/%d.jpg", m_task_info[obj_key.videoID].image_folder, obj_key.objID); remove(snapShotName); //os << snapShotName << endl; } //os << 3 << endl; } //SNAPSHOT_IMAGE_UNIT cur_image; #ifndef _MSC_VER #include #endif DWORD SnapshotImageWriteThreadProcess(LPVOID param) { snapshot_helper *pThreadParam = (snapshot_helper *)param; while (true) { //auto begintime = std::chrono::system_clock::now(); /* if (!pThreadParam->snapshotImageQueue.empty()) { SNAPSHOT_IMAGE_UNIT cur_image = {}; { { std::lock_guard lock(pThreadParam->threadMutex); cur_image = pThreadParam->snapshotImageQueue.front(); pThreadParam->snapshotImageQueue.pop(); } if (false == cur_image.is_image) { std::lock_guard lock(pThreadParam->finishedSaveThreadMutex); pThreadParam->finished_save_ss_info.insert(cur_image.obj_key); } pThreadParam->finishedSaveCondVar.notify_one(); cv::resize(cur_image.image, cur_image.image, cv::Size(cur_image.original_size.original_width, cur_image.original_size.original_height)); cv::imwrite(cur_image.file_name, cur_image.image); if (cur_image.flag == true && cur_image.image.data != NULL) { delete[] cur_image.image.data; cur_image.image.data = NULL; } }*/ //std::unique_lock lock(pThreadParam->threadMutex); std::unique_lock l(pThreadParam->threadMutex); if (!pThreadParam->snapshotImageQueue.empty()) { //printf("++++++++++++++++++++++++++++++++++++++ snapshotImageQueue.size = %d\n", pThreadParam->snapshotImageQueue.size()); SNAPSHOT_IMAGE_UNIT cur_image = pThreadParam->snapshotImageQueue.front(); pThreadParam->snapshotImageQueue.pop(); l.unlock(); vector compression_params; compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params.push_back(30); cv::Mat image; cv::resize(cur_image.image, image, cv::Size(cur_image.original_size.original_width, cur_image.original_size.original_height)); cv::imwrite(cur_image.file_name, image, compression_params); if (cur_image.flag == true && cur_image.image.data != NULL) { delete[]cur_image.image.data; cur_image.image.data = NULL; #ifndef _MSC_VER malloc_trim(0); #endif // delete[] image.data; // image.data = NULL; } image.release(); if (false == cur_image.is_image) { std::unique_lock ll(pThreadParam->finishedThreadMutex); pThreadParam->finished_save_ss_info_que.push(cur_image.obj_key); } } else { l.unlock(); std::this_thread::sleep_for(std::chrono::milliseconds(10)); } } return 0; } DWORD SnapshotThreadProcess(LPVOID param) { snapshot_helper *pThreadParam = (snapshot_helper *)param; //std::ofstream os("./vptlog1.txt", std::ofstream::out | std::ofstream::trunc); //os << unitbuf; //try { while (true) { //if (!pThreadParam->snapshotImageQueue.empty()) //{ // SNAPSHOT_IMAGE_UNIT cur_image = {}; // { // std::unique_lock lock(pThreadParam->threadMutex); // std::unique_lock l(pThreadParam->writeThreadMutex); // while (!pThreadParam->snapshotImageQueue.empty()) // { // cur_image = pThreadParam->snapshotImageQueue.front(); // pThreadParam->snapshotImageQueue.pop(); // pThreadParam->cur_image_queue.push_back(cur_image); // } // } // //pThreadParam->writeThreadCondVar.notify_one(); //} std::unique_lock l(pThreadParam->finishedThreadMutex); while (!pThreadParam->finished_save_ss_info_que.empty()) { pThreadParam->finished_save_ss_info.insert(pThreadParam->finished_save_ss_info_que.front()); pThreadParam->finished_save_ss_info_que.pop(); } l.unlock(); for (auto iter = pThreadParam->finished_save_ss_info.begin(); iter != pThreadParam->finished_save_ss_info.end();) { std::lock_guard lock(pThreadParam->analysisThreadMutex); if (pThreadParam->finished_analysis_ss_info.find(*iter) != pThreadParam->finished_analysis_ss_info.end()) { if (pThreadParam->m_task_info[iter->videoID].obj_callback != NULL) { //os << iter->videoID << " " << iter->objID << "; "; std::lock_guard l(pThreadParam->callback_tx); pThreadParam->m_task_info[iter->videoID].obj_callback(&pThreadParam->finished_analysis_ss_info[*iter]); } { if (pThreadParam->finished_analysis_ss_info[*iter].analysisRes != NULL) { delete pThreadParam->finished_analysis_ss_info[*iter].analysisRes; pThreadParam->finished_analysis_ss_info[*iter].analysisRes = NULL; } pThreadParam->finished_analysis_ss_info.erase(pThreadParam->finished_analysis_ss_info.find(*iter)); } iter = pThreadParam->finished_save_ss_info.erase(iter); } else iter++; } boost::this_thread::sleep(boost::posix_time::milliseconds(10)); } } //catch (...) { std::cout << "Save Process Thread is Finished" << std::endl; } return 0; } int snapshot_helper::save_snapshot(bool is_image, OBJ_KEY obj_key, char* filename, char* mode, float* imgData, int width, int height, int taskID, int objID, int recFlag, int left = 0, int top = 0, int right = 0, int bottom = 0) { if (recFlag) { SNAPSHOT_IMAGE_UNIT cur_image(height, width, CV_32FC3, imgData); cv::rectangle(cur_image.image, cv::Rect(left, top, right - left, bottom - top), cv::Scalar(0, 0, 255), 2, 1, 0); cur_image.file_name = filename; cur_image.flag = true; cur_image.original_size.original_width = width; cur_image.original_size.original_height = height; cur_image.obj_key = obj_key; cur_image.is_image = is_image; //newVideoImg.copyTo(cur_image.image); //auto begintime = std::chrono::system_clock::now(); { std::lock_guard lock(threadMutex); snapshotImageQueue.push(cur_image); } // auto endtime = std::chrono::system_clock::now(); // auto costtime = std::chrono::duration_cast(endtime - begintime).count(); // printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cost time = %d\n", costtime); //newVideoImg.release(); } else { cv::Mat newSnapshot(height, width, CV_32FC3, imgData); SNAPSHOT_IMAGE_UNIT cur_image(height, width, CV_32FC3, imgData); cur_image.file_name = filename; cur_image.flag = true; cur_image.original_size.original_width = (right - left); cur_image.original_size.original_height = (bottom - top); cur_image.obj_key = obj_key; cur_image.is_image = is_image; //newSnapshot.copyTo(cur_image.image); //auto begintime = std::chrono::system_clock::now(); { std::lock_guard lock(threadMutex); snapshotImageQueue.push(cur_image); } // auto endtime = std::chrono::system_clock::now(); // auto costtime = std::chrono::duration_cast(endtime - begintime).count(); // printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cost time = %d\n", costtime); //newSnapshot.release(); } return 1; } int snapshot_helper::save_snapshot(bool is_image, OBJ_KEY obj_key, char* filename, char* mode, unsigned char* imgData, int width, int height, int taskID, int objID, int recFlag, int left = 0, int top = 0, int right = 0, int bottom = 0) { if (recFlag) { SNAPSHOT_IMAGE_UNIT cur_image(height, width, CV_8UC3, imgData); cv::rectangle(cur_image.image, cv::Rect(left, top, right - left, bottom - top), cv::Scalar(0, 0, 255), 2, 1, 0); cur_image.file_name = filename; cur_image.flag = true; cur_image.original_size.original_width = width; cur_image.original_size.original_height = height; cur_image.obj_key = obj_key; cur_image.is_image = is_image; //newVideoImg.copyTo(cur_image.image); //auto begintime = std::chrono::system_clock::now(); { std::lock_guard lock(threadMutex); snapshotImageQueue.push(cur_image); } // auto endtime = std::chrono::system_clock::now(); // auto costtime = std::chrono::duration_cast(endtime - begintime).count(); // printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cost time = %d\n", costtime); } else { cv::Mat newSnapshot(height, width, CV_8UC3, imgData); SNAPSHOT_IMAGE_UNIT cur_image = {}; cur_image.file_name = filename; cur_image.flag = false; cur_image.original_size.original_width = (right - left); cur_image.original_size.original_height = (bottom - top); cur_image.obj_key = obj_key; cur_image.is_image = is_image; newSnapshot.copyTo(cur_image.image); //auto begintime = std::chrono::system_clock::now(); { std::lock_guard lock(threadMutex); snapshotImageQueue.push(cur_image); } // auto endtime = std::chrono::system_clock::now(); // auto costtime = std::chrono::duration_cast(endtime - begintime).count(); // printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cost time = %d\n", costtime); newSnapshot.release(); } return 1; } //void snapshot_helper::vehicle_recg_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis) //{ // int count_vehicle_unanalysis = count_vehicle_v.size() - count_vehivle_finishanalysis; //当前数组中还有多少个未进行二次属性分析 // // if (count_vehicle_unanalysis >= OBJ_BATCH_COUNT_VEHICLE && !AttributionAnalysis&& vehicle_analysis_cf == SY_CONFIG_OPEN) // { // AttributionAnalysis = true; // //#ifdef LOG_INFO // cout << "----- begin VehicleColor_Process -----" << endl; // //#ifdef _MSC_VER // LARGE_INTEGER nFreq, nBeginTime, nEndTime; // LARGE_INTEGER nSaveBeginTime, nSaveEndTime; // // QueryPerformanceFrequency(&nFreq); // QueryPerformanceCounter(&nBeginTime); // double time_val = 0.0; //#else // gettimeofday(&t1, NULL); // //#endif //#endif // for (int i = count_vehivle_finishanalysis; i < count_vehivle_finishanalysis + OBJ_BATCH_COUNT_VEHICLE; i++) // { // OBJ_KEY cur_obj_key = count_vehicle_v[i]; // batch_vehicle[i - count_vehivle_finishanalysis].set_data(VEHICLE_WIDTH, VEHICLE_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); // } // int index_head = 0; // int index_trail = 0; // int index_other = 0; // map mp_head; // map mp_trail; // map mp_other; // sy_img * batch_vehicle_head = new sy_img[OBJ_BATCH_COUNT_VEHICLE]{}; // sy_img * batch_vehicle_trail = new sy_img[OBJ_BATCH_COUNT_VEHICLE]{}; // sy_img * batch_vehicle_other = new sy_img[OBJ_BATCH_COUNT_VEHICLE]{}; // vhd_result * vhd_res = new vhd_result[OBJ_BATCH_COUNT_VEHICLE]{}; // vhd_features_process(vhd_handle, batch_vehicle, OBJ_BATCH_COUNT_VEHICLE, vhd_res); // for (int vc_idx = count_vehivle_finishanalysis; vc_idx < count_vehivle_finishanalysis + OBJ_BATCH_COUNT_VEHICLE; vc_idx++) // { // OBJ_KEY cur_obj_key = count_vehicle_v[vc_idx]; // vhd_result & result = vhd_res[vc_idx]; // for (int i = 0; i < result.obj_count_; ++i) // { // if (result.obj_results_[i].obj_index == 0 && snapShotInfo[cur_obj_key].snapShotLittle.width == VEHICLE_WIDTH && snapShotInfo[cur_obj_key].snapShotLittle.height == VEHICLE_HEIGHT) // { // int w_imglength = result.obj_results_[i].obj_rect.width_ * result.obj_results_[i].obj_rect.height_ *IMG_CHANNELS; // if (batch_vehicle_head[index_head].data_ == 0) // { // cudaMalloc(&batch_vehicle_head[index_head].data_, w_imglength * sizeof(unsigned char)); // } // cudacommon::CropImgGpu((unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame, VEHICLE_WIDTH, VEHICLE_HEIGHT, // batch_vehicle_head[index_head].data_, result.obj_results_[i].obj_rect.left_, result.obj_results_[i].obj_rect.top_, result.obj_results_[i].obj_rect.width_, result.obj_results_[i].obj_rect.height_); // // batch_vehicle_head[index_head].w_ = result.obj_results_[i].obj_rect.width_; // batch_vehicle_head[index_head].h_ = result.obj_results_[i].obj_rect.height_; // batch_vehicle_head[index_head].c_ = IMG_CHANNELS; // ++index_head; // mp_head.insert({ vc_idx, cur_obj_key }); // break; // } // else if (result.obj_results_[i].obj_index == 1 && snapShotInfo[cur_obj_key].snapShotLittle.width == VEHICLE_WIDTH && snapShotInfo[cur_obj_key].snapShotLittle.height == VEHICLE_HEIGHT) // { // int w_imglength = result.obj_results_[i].obj_rect.width_ * result.obj_results_[i].obj_rect.height_ *IMG_CHANNELS; // if (batch_vehicle_trail[index_trail].data_ == 0) // { // cudaMalloc(&batch_vehicle_trail[index_trail].data_, w_imglength * sizeof(unsigned char)); // } // cudacommon::CropImgGpu((unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame, VEHICLE_WIDTH, VEHICLE_HEIGHT, // batch_vehicle_trail[index_trail].data_, result.obj_results_[i].obj_rect.left_, result.obj_results_[i].obj_rect.top_, result.obj_results_[i].obj_rect.width_, result.obj_results_[i].obj_rect.height_); // // batch_vehicle_trail[index_trail].w_ = result.obj_results_[i].obj_rect.width_; // batch_vehicle_trail[index_trail].h_ = result.obj_results_[i].obj_rect.height_; // batch_vehicle_trail[index_trail].c_ = IMG_CHANNELS; // ++index_trail; // mp_trail.insert({ vc_idx, cur_obj_key }); // break; // } // else // { // int w_imglength = VEHICLE_WIDTH * VEHICLE_HEIGHT *IMG_CHANNELS; // cudaMalloc(&batch_vehicle_other[index_other].data_, w_imglength * sizeof(unsigned char)); // cudaMemcpy(batch_vehicle_other[index_other].data_, snapShotInfo[cur_obj_key].snapShotLittle.frame, w_imglength, cudaMemcpyDeviceToDevice); // batch_vehicle_other[index_other].w_ = VEHICLE_WIDTH; // batch_vehicle_other[index_other].h_ = VEHICLE_HEIGHT; // batch_vehicle_other[index_other].c_ = IMG_CHANNELS; // ++index_other; // mp_other.insert({ vc_idx, cur_obj_key }); // break; // } // } // } // cudaDeviceSynchronize();//将会一直处于阻塞状态,直到前面所有请求的任务已经被全部执行完毕 // // if (index_head != 0) // { // vr_result *vrresult = new vr_result[index_head]{}; // // VehicleRecognition_Process(vr_handle, batch_vehicle_head, index_head, vrresult); // // int resIndex = 0; // for (auto & item : mp_head) // //for (auto iter_key : erase_obj_key) // { // auto iter = snapShotInfo.find(item.second); // // if (iter == snapShotInfo.end()) // resIndex++; //cout << iter_key.videoID << " " <= OBJ_BATCH_COUNT && !AttributionAnalysis) // { // //#ifdef LOG_INFO // std::cout << "------ begin HumanParsing_Process -----" << std::endl; //#ifdef _MSC_VER // LARGE_INTEGER nFreq, nBeginTime, nEndTime; // LARGE_INTEGER nSaveBeginTime, nSaveEndTime; // // QueryPerformanceFrequency(&nFreq); // QueryPerformanceCounter(&nBeginTime); // double time_val = 0.0; //#else // gettimeofday(&t1, NULL); // //#endif //#endif // AttributionAnalysis = true; //进行了二次属性分析 // vector erase_obj_key; // // // for (int i = 0; i < OBJ_BATCH_COUNT; i++) // { // OBJ_KEY cur_obj_key = count_person.front(); // erase_obj_key.push_back(cur_obj_key); // // if ((unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame == NULL) // { // cout << "error data! task id: " << cur_obj_key.videoID << " obj id: " << cur_obj_key.objID << endl; // } // // if (snapShotInfo[cur_obj_key].index.index != 0) // printf("=============== index error ==================\n"); // // if (snapShotInfo[cur_obj_key].snapShotLittle.width != HP_WIDTH || snapShotInfo[cur_obj_key].snapShotLittle.height != HP_HEIGHT) // printf("=================== width height error ======================\n"); // // batch_hp[i].set_data(HP_WIDTH, HP_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); // count_person.pop(); // } // // // hp_res *result = nullptr; // if (hp_analysis_cf == SY_CONFIG_OPEN || hf_recg_cf == SY_CONFIG_OPEN) // { // result = new hp_res[OBJ_BATCH_COUNT]{}; // HumanParsing_Process(hp_handle, batch_hp, OBJ_BATCH_COUNT, result); // } // // /* hf_result * result_f = nullptr; // if (hf_handle != nullptr) // { // result_f = new hf_result[OBJ_BATCH_COUNT]{}; // human_features_process(hf_handle, batch_hp, OBJ_BATCH_COUNT, result_f); // }*/ // //#ifdef LOG_INFO //#ifdef _MSC_VER // QueryPerformanceCounter(&nEndTime); // time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; // std::printf("HumanParsing_Process: %.2f ms \n", time_val); //#else // /* // gettimeofday(&t2, NULL); // time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; // printf("HumanParsing_Process = %lf ms\n", time_val); // */ //#endif //#endif // // //删除已经进行保存和二次属性分析的目标 // int resIndex = 0; // for (auto iter_key : erase_obj_key) // { // //printf("begin find. "); // auto iter = snapShotInfo.find(iter_key); // // //printf("end find. "); // if (iter == snapShotInfo.end()) // { // resIndex++; // cout << iter_key.videoID << " " << iter_key.objID << " cant find" << endl; // } // else // { // // hp_result curRes{}; // if (hp_analysis_cf == SY_CONFIG_OPEN) // { // memcpy(&curRes.res_objs, result[resIndex].res_objs, sizeof(classify_obj_res)* HP_FIR_INDEX_SIZE); // } // if (hf_recg_cf == SY_CONFIG_OPEN) // { // memcpy(curRes.feature, result[resIndex].feature, sizeof(float)* HF_FEA_SIZE); // } // // //printf("finish memcpy. "); // //CPUSaveImage(iter_key, snapShotInfo[iter_key]); // // //printf("finish callback. "); // if (hf_recg_cf == SY_CONFIG_OPEN || hp_analysis_cf == SY_CONFIG_OPEN) // { // resIndex++; // snapshot_res_callback(iter_key, &curRes); // if (iter->second.snapShotLittle.frame) // { // cudaFree(iter->second.snapShotLittle.frame); // iter->second.snapShotLittle.frame = NULL; // } // snapShotInfo.erase(iter);//modified by dyq // } // //printf("finish release. \n"); // } // } // // //printf("finish callback\n"); // // erase_obj_key.clear(); // vector().swap(erase_obj_key); // if (hp_analysis_cf == SY_CONFIG_OPEN || hf_recg_cf == SY_CONFIG_OPEN) // { // if (result != nullptr) // { // delete[] result; // result = nullptr; // } // } // // /* if (hf_handle != nullptr) // { // if (result_f != nullptr) // { // delete[] result_f; // } // // }*/ //#ifdef LOG_INFO //#ifdef _MSC_VER // QueryPerformanceCounter(&nEndTime); // time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; // std::printf("total: %.2f ms \n", time_val); //#else // /* // gettimeofday(&t2, NULL); // time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; // printf("HumanParsing_Process = %lf ms\n", time_val); // */ //#endif // std::cout << "----- end HumanParsing_Process -----" << std::endl; //#endif // //printf("real end hp\n"); // // } // } // //} //void snapshot_helper::hcp_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis, bool flag) //{ // if (!flag) // { // count_bike.push(obj_key); // if (count_bike.size() >= OBJ_BATCH_COUNT && !AttributionAnalysis) // { // AttributionAnalysis = true; // vector erase_obj_key; //#ifdef LOG_INFO // std::cout << "----- begin HumanCarParsing_Process -----" << endl; //#ifdef _MSC_VER // LARGE_INTEGER nFreq, nBeginTime, nEndTime; // LARGE_INTEGER nSaveBeginTime, nSaveEndTime; // // QueryPerformanceFrequency(&nFreq); // QueryPerformanceCounter(&nBeginTime); // double time_val = 0.0; //#else // gettimeofday(&t1, NULL); // //#endif //#endif // for (int i = 0; i < OBJ_BATCH_COUNT; i++) // { // OBJ_KEY cur_obj_key = count_bike.front(); // erase_obj_key.push_back(cur_obj_key); // // if (snapShotInfo[cur_obj_key].index.index != 1 && snapShotInfo[cur_obj_key].index.index != 2) // printf("=============== index error ==================\n"); // // if (snapShotInfo[cur_obj_key].snapShotLittle.width != HCP_WIDTH || snapShotInfo[cur_obj_key].snapShotLittle.height != HCP_HEIGHT) // printf("=================== width height error ======================\n"); // // // batch_hcp[i].set_data(HCP_WIDTH, HCP_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); // count_bike.pop(); // } // hcp_res *result = nullptr; // if (hcp_analysis_cf == SY_CONFIG_OPEN || hcf_recg_cf == SY_CONFIG_OPEN) // { // result = new hcp_res[OBJ_BATCH_COUNT]{}; // HumanCarParsing_Process(hcp_handle, batch_hcp, OBJ_BATCH_COUNT, result); // } // //hf_result * result_f = nullptr; // //if (hcf_handle != nullptr) // //{ // // result_f = new hf_result[OBJ_BATCH_COUNT]{}; // // human_features_process(hcf_handle, batch_hcp, OBJ_BATCH_COUNT, result_f); // //} // //#ifdef LOG_INFO //#ifdef _MSC_VER // QueryPerformanceCounter(&nEndTime); // time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; // printf("HumanCarParsing_Process: %.2f ms \n", time_val); //#else // /* // gettimeofday(&t2, NULL); // time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; // printf("HumanCarParsing_Process = %lf ms\n", time_val); // */ //#endif // cout << "----- end HumanCarParsing_Process -----" << endl; //#endif // int resIndex = 0; // for (auto iter_key : erase_obj_key) // { // //printf("begin find. "); // auto iter = snapShotInfo.find(iter_key); // //printf("end find. "); // // if (iter == snapShotInfo.end()) // { // resIndex++; // cout << iter_key.videoID << " " << iter_key.objID << " cant find" << endl; // } // else // { // hcp_result curRes{}; // if (hcp_analysis_cf == SY_CONFIG_OPEN) // { // memcpy(&curRes.res_objs, result[resIndex].res_objs, sizeof(classify_obj_res)* HCP_FIR_INDEX_SIZE); // //printf("hcp res_index = %d\n", result[resIndex].res_objs[0].res_index); // } // if (hcf_recg_cf == SY_CONFIG_OPEN) // { // memcpy(curRes.feature, result[resIndex].feature, sizeof(float)* HCF_FEA_SIZE); // } // // //printf("finish memcpy. "); // //CPUSaveImage(iter_key, snapShotInfo[iter_key]); // // //printf("finish callback. "); // if (hcf_recg_cf == SY_CONFIG_OPEN || hcp_analysis_cf == SY_CONFIG_OPEN) // { // resIndex++; // snapshot_res_callback(iter_key, &curRes); // //printf("finish callback. "); // // if (iter->second.snapShotLittle.frame) // { // cudaFree(iter->second.snapShotLittle.frame); // iter->second.snapShotLittle.frame = NULL; // } // // snapShotInfo.erase(iter);//modified by dyq // } // // //printf("finish release. \n"); // } // } // // //printf("finish callback\n"); // erase_obj_key.clear(); // vector().swap(erase_obj_key); // // if (hcp_analysis_cf == SY_CONFIG_OPEN || hcf_recg_cf == SY_CONFIG_OPEN) // { // if (result != nullptr) // { // delete[] result; // result = nullptr; // } // } // // //if (hcf_handle != nullptr) // //{ // // if (result_f != nullptr) // // { // // delete[] result_f; // // } // // //} // // //printf("real end hcp\n"); // } // } // //} //void snapshot_helper::vehicle_color_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis) //{ // count_vehicle_v.push_back(obj_key); // // int count_vehicle_unanalysis = count_vehicle_v.size() - count_vehivle_finishanalysis; //当前数组中还有多少个未进行二次属性分析 // // if (count_vehicle_unanalysis >= OBJ_BATCH_COUNT_VEHICLE && !AttributionAnalysis&& vehicle_analysis_cf == SY_CONFIG_OPEN) // { // AttributionAnalysis = true; // //#ifdef LOG_INFO // cout << "----- begin VehicleColor_Process -----" << endl; // //#ifdef _MSC_VER // LARGE_INTEGER nFreq, nBeginTime, nEndTime; // LARGE_INTEGER nSaveBeginTime, nSaveEndTime; // // QueryPerformanceFrequency(&nFreq); // QueryPerformanceCounter(&nBeginTime); // double time_val = 0.0; //#else // gettimeofday(&t1, NULL); // //#endif //#endif // for (int i = count_vehivle_finishanalysis; i < count_vehivle_finishanalysis + OBJ_BATCH_COUNT_VEHICLE; i++) // { // OBJ_KEY cur_obj_key = count_vehicle_v[i]; // batch_vehicle[i - count_vehivle_finishanalysis].set_data(VEHICLE_WIDTH, VEHICLE_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); // } // // vc_result *vcresult = new vc_result[OBJ_BATCH_COUNT_VEHICLE]{}; // VehicleColor_Process(vc_handle, batch_vehicle, OBJ_BATCH_COUNT_VEHICLE, vcresult); // //#ifdef LOG_INFO //#ifdef _MSC_VER // QueryPerformanceCounter(&nEndTime); // time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; // printf("VehicleColor_Process: %.2f ms \n", time_val); //#else // /* // gettimeofday(&t2, NULL); // time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; // printf("VehicleColor_Process = %lf ms\n", time_val); // */ //#endif //#endif // // for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE; i++) // //for (auto iter_key : erase_obj_key) // { // auto iter = snapShotInfo.find(count_vehicle_v[i + count_vehivle_finishanalysis]); // if (iter == snapShotInfo.end()) // { // //cout << " cant find" << endl; // } // else // { // vehicle_result curRes = {}; // memcpy(&curRes.vc_res, &vcresult[i], sizeof(vc_result)); // vehicle_result_v.push_back(curRes); // } // } // // if (vcresult != NULL) // { // delete[] vcresult; // vcresult = NULL; // } // } //} //void snapshot_helper::vf_feature() //{ // //if (vehicle_analysis_cf == SY_CONFIG_CLOSE) // //{ // // count_vehivle_finishanalysis = 0; // //} // //count_vf_finishanalysis += OBJ_BATCH_COUNT_VEHICLE; // //std::cerr << "++++++++++++++++++++++++++++++++++vf_feature 2 ++++++++++++++++++++++++++++++++++++++++++++++" << std::endl; // int count_vehicle_unanalysis = count_vehicle_v.size() - count_vehivle_finishanalysis; //当前数组中还有多少个未进行二次属性分析 // if (count_vehicle_unanalysis >= OBJ_BATCH_COUNT_VEHICLE && vcf_recg_cf == SY_CONFIG_OPEN) // //if (count_vehicle_v.size() >= OBJ_BATCH_COUNT_VEHICLE && vhd_handle != nullptr) // { // sy_img * batch_vehicle_f = batch_vehicle_vf; // for (int i = count_vehivle_finishanalysis; i < count_vehivle_finishanalysis + OBJ_BATCH_COUNT_VEHICLE; i++) // { // OBJ_KEY cur_obj_key = count_vehicle_v[i]; // batch_vehicle[i - count_vehivle_finishanalysis].set_data(VEHICLE_WIDTH, VEHICLE_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); // } // // vhd_result * vhd_res = new vhd_result[OBJ_BATCH_COUNT_VEHICLE]{}; // /* for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE; ++i) // { // vcwd_res[i].vhd_info = new vcwd_info[VD_MAXDETECTCOUNT]{}; // vcwd_res[i].vrd_info = new vcwd_info[VD_MAXDETECTCOUNT]{}; // }*/ // vhd_features_process(vhd_handle, batch_vehicle, OBJ_BATCH_COUNT_VEHICLE, vhd_res); // int w_index = 0; // map mp; //检测到的车窗的索引和OBJ_KEY // for (int vc_idx = count_vehivle_finishanalysis; vc_idx < count_vehivle_finishanalysis + OBJ_BATCH_COUNT_VEHICLE; vc_idx++) // { // OBJ_KEY cur_obj_key = count_vehicle_v[vc_idx]; // vhd_result & result = vhd_res[vc_idx - count_vehivle_finishanalysis]; // for (int i = 0; i < result.obj_count_; ++i) //车头 // { // if (result.obj_results_[i].obj_rect.width_ != 0 && snapShotInfo[cur_obj_key].snapShotLittle.width == VEHICLE_WIDTH && snapShotInfo[cur_obj_key].snapShotLittle.height == VEHICLE_HEIGHT) // { // int w_imglength = VEHICLE_WIDTH * VEHICLE_HEIGHT *IMG_CHANNELS; // if (batch_vehicle_f[w_index].data_ == 0) // { // cudaMalloc(&batch_vehicle_f[w_index].data_, w_imglength * sizeof(unsigned char)); // } // cudacommon::CropImgGpu((unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame, VEHICLE_WIDTH, VEHICLE_HEIGHT, // batch_vehicle_f[w_index].data_, result.obj_results_[i].obj_rect.left_, result.obj_results_[i].obj_rect.top_, result.obj_results_[i].obj_rect.width_, result.obj_results_[i].obj_rect.height_); // // batch_vehicle_f[w_index].w_ = result.obj_results_[i].obj_rect.width_; // batch_vehicle_f[w_index].h_ = result.obj_results_[i].obj_rect.height_; // batch_vehicle_f[w_index].c_ = IMG_CHANNELS; // ++w_index; // mp.insert({ vc_idx, cur_obj_key }); // break; // } // } // } // cudaDeviceSynchronize();//将会一直处于阻塞状态,直到前面所有请求的任务已经被全部执行完毕 // if (w_index == 0) // { // if (vhd_res != NULL) // { // delete[] vhd_res; // vhd_res = NULL; // } // return; // } // // float ** fea = new float*[w_index] {}; // for (int i = 0; i < w_index; ++i) // { // fea[i] = new float[FEATURESIZE] {}; // } // vf_features_process(vf_handle, batch_vehicle_f, w_index, fea); // if (vehicle_analysis_cf == SY_CONFIG_CLOSE) // { // //std::cerr << "*****************************vf_feature 1 *******************************************"<second.snapShotLittle.frame) // { // cudaFree(iter->second.snapShotLittle.frame); // iter->second.snapShotLittle.frame = NULL; // } // snapShotInfo.erase(iter); // } // } // count_vehicle_v.erase(count_vehicle_v.begin() + count_vehivle_finishanalysis, count_vehicle_v.begin() + count_vehivle_finishanalysis + OBJ_BATCH_COUNT_VEHICLE); // } // else // { // //std::cerr << "*****************************vf_feature 2 *******************************************"< &mp_head) //{ // if (0 == batch_size) // { // if (vehicle_analysis_cf == SY_CONFIG_OPEN) // { // count_vehivle_finishanalysis += OBJ_BATCH_COUNT_VEHICLE; // } // return; // } // // float ** fea = new float*[batch_size] {}; // for (int i = 0; i < batch_size; ++i) // { // fea[i] = new float[FEATURESIZE] {}; // } // vf_features_process(vf_handle, batch_vehicle_f, batch_size, fea); // if (vehicle_analysis_cf == SY_CONFIG_CLOSE) // { // //std::cerr << "*****************************vf_feature 1 *******************************************"<second.snapShotLittle.frame) // { // cudaFree(iter->second.snapShotLittle.frame); // iter->second.snapShotLittle.frame = NULL; // } // snapShotInfo.erase(iter); // } // } // count_vehicle_v.erase(count_vehicle_v.begin() + count_vehivle_finishanalysis, count_vehicle_v.begin() + count_vehivle_finishanalysis + OBJ_BATCH_COUNT_VEHICLE); // } // else // { // //std::cerr << "*****************************vf_feature 2 *******************************************"<= OBJ_BATCH_COUNT_VEHICLE && !AttributionAnalysis && vcf_recg_cf == SY_CONFIG_OPEN) // //if (count_vehicle_v.size() >= OBJ_BATCH_COUNT_VEHICLE && vhd_handle != nullptr) // { // sy_img * batch_vehicle_f = batch_vehicle_vf; // for (int i = count_vehivle_finishanalysis; i < count_vehivle_finishanalysis + OBJ_BATCH_COUNT_VEHICLE; i++) // { // OBJ_KEY cur_obj_key = count_vehicle_v[i]; // batch_vehicle[i - count_vehivle_finishanalysis].set_data(VEHICLE_WIDTH, VEHICLE_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); // } // // vhd_result * vhd_res = new vhd_result[OBJ_BATCH_COUNT_VEHICLE]{}; // /* for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE; ++i) // { // vcwd_res[i].vhd_info = new vcwd_info[VD_MAXDETECTCOUNT]{}; // vcwd_res[i].vrd_info = new vcwd_info[VD_MAXDETECTCOUNT]{}; // }*/ // vhd_features_process(vhd_handle, batch_vehicle, OBJ_BATCH_COUNT_VEHICLE, vhd_res); // int w_index = 0; // map mp; //检测到的车窗的索引和OBJ_KEY // for (int vc_idx = count_vehivle_finishanalysis; vc_idx < count_vehivle_finishanalysis + OBJ_BATCH_COUNT_VEHICLE; vc_idx++) // { // OBJ_KEY cur_obj_key = count_vehicle_v[vc_idx]; // vhd_result & result = vhd_res[vc_idx - count_vehivle_finishanalysis]; // for (int i = 0; i < result.obj_count_; ++i) //车头 // { // if (result.obj_results_[i].obj_rect.width_ != 0 && snapShotInfo[cur_obj_key].snapShotLittle.width == VEHICLE_WIDTH && snapShotInfo[cur_obj_key].snapShotLittle.height == VEHICLE_HEIGHT) // { // int w_imglength = VEHICLE_WIDTH * VEHICLE_HEIGHT *IMG_CHANNELS; // if (batch_vehicle_f[w_index].data_ == 0) // { // cudaMalloc(&batch_vehicle_f[w_index].data_, w_imglength * sizeof(unsigned char)); // } // cudacommon::CropImgGpu((unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame, VEHICLE_WIDTH, VEHICLE_HEIGHT, // batch_vehicle_f[w_index].data_, result.obj_results_[i].obj_rect.left_, result.obj_results_[i].obj_rect.top_, result.obj_results_[i].obj_rect.width_, result.obj_results_[i].obj_rect.height_); // // batch_vehicle_f[w_index].w_ = result.obj_results_[i].obj_rect.width_; // batch_vehicle_f[w_index].h_ = result.obj_results_[i].obj_rect.height_; // batch_vehicle_f[w_index].c_ = IMG_CHANNELS; // ++w_index; // mp.insert({ vc_idx, cur_obj_key }); // break; // } // } // } // cudaDeviceSynchronize();//将会一直处于阻塞状态,直到前面所有请求的任务已经被全部执行完毕 // if (w_index == 0) // { // if (vhd_res != NULL) // { // delete[] vhd_res; // vhd_res = NULL; // } // return; // } // // float ** fea = new float*[w_index] {}; // for (int i = 0; i < w_index; ++i) // { // fea[i] = new float[FEATURESIZE] {}; // } // vf_features_process(vf_handle, batch_vehicle_f, w_index, fea); // if (vehicle_analysis_cf == SY_CONFIG_CLOSE) // { // //std::cerr << "*****************************vf_feature 1 *******************************************"<second.snapShotLittle.frame) // { // cudaFree(iter->second.snapShotLittle.frame); // iter->second.snapShotLittle.frame = NULL; // } // snapShotInfo.erase(iter); // } // } // count_vehicle_v.erase(count_vehicle_v.begin() + count_vehivle_finishanalysis, count_vehicle_v.begin() + count_vehivle_finishanalysis + OBJ_BATCH_COUNT_VEHICLE); // } // else // { // //std::cerr << "*****************************vf_feature 2 *******************************************"<= OBJ_BATCH_COUNT_VEHICLE && count_vehicle_v.size() >= OBJ_BATCH_COUNT_VEHICLE && !AttributionAnalysis && vehicle_analysis_cf == SY_CONFIG_OPEN) // { // AttributionAnalysis = true; // //#ifdef LOG_INFO // cout << "----- begin VEHICLEPLATEAnalysis -----" << endl; // //#ifdef _MSC_VER // LARGE_INTEGER nFreq, nBeginTime, nEndTime; // LARGE_INTEGER nSaveBeginTime, nSaveEndTime; // // QueryPerformanceFrequency(&nFreq); // QueryPerformanceCounter(&nBeginTime); // double time_val = 0.0; //#else // gettimeofday(&t1, NULL); // //#endif //#endif // for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE; i++) // { // OBJ_KEY cur_obj_key = count_vehicle_v[i]; // batch_vehicle[i].set_data(VEHICLE_WIDTH, VEHICLE_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); // } // vplate_result *vp_result = nullptr; // if (vehicle_analysis_cf == SY_CONFIG_OPEN) // { // vp_result = new vplate_result[OBJ_BATCH_COUNT_VEHICLE]{}; // VehiclePlateDetectRecog_Process(vp_handle, batch_vehicle, OBJ_BATCH_COUNT_VEHICLE, vp_result); // } // //#ifdef LOG_INFO //#ifdef _MSC_VER // QueryPerformanceCounter(&nEndTime); // time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; // printf("VEHICLEPLATEAnalysis: %.2f ms \n", time_val); //#else // /* // gettimeofday(&t2, NULL); // time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; // printf("VehicleColor_Process = %lf ms\n", time_val); // */ //#endif //#endif // // //printf("begin copy\n"); // // int resIndex = 0; // for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE; i++) // //for (auto iter_key : erase_obj_key) // { // auto iter = snapShotInfo.find(count_vehicle_v[i]); // // if (iter == snapShotInfo.end()) // resIndex++; // else // { // vehicle_result &curRes = vehicle_result_v[i]; // // //VP // memcpy(&curRes.vp_res, &vp_result[resIndex], sizeof(vplate_result)); // // //CPUSaveImage(count_vehicle_v[i], snapShotInfo[count_vehicle_v[i]]); // snapshot_res_callback(count_vehicle_v[i], &curRes); // // //注释掉是之后释放 因为快照可能还在异步的保存 // /* // if (curRes.vr_res.vehicle_brand != NULL) // { // delete[] curRes.vr_res.vehicle_brand; // curRes.vr_res.vehicle_brand = NULL; // } // if (curRes.vr_res.vehicle_subbrand != NULL) // { // delete[] curRes.vr_res.vehicle_subbrand; // curRes.vr_res.vehicle_subbrand = NULL; // } // if (curRes.vr_res.vehicle_issue_year != NULL) // { // delete[] curRes.vr_res.vehicle_issue_year; // curRes.vr_res.vehicle_issue_year = NULL; // } // if (curRes.vr_res.vehicle_type != NULL) // { // delete[] curRes.vr_res.vehicle_type; // curRes.vr_res.vehicle_type = NULL; // } // if (curRes.vr_res.freight_ton != NULL) // { // delete[] curRes.vr_res.freight_ton; // curRes.vr_res.freight_ton = NULL; // }*/ // // if (iter->second.snapShotLittle.frame) // { // cudaFree(iter->second.snapShotLittle.frame); // iter->second.snapShotLittle.frame = NULL; // } // // //delete by lm 20180803 checkCudaErrors(cuCtxPopCurrent(NULL)); // snapShotInfo.erase(iter);//modified by dyq // resIndex++; // } // } // // //printf("end copy\n"); // vehicle_result_v.erase(vehicle_result_v.begin(), vehicle_result_v.begin() + OBJ_BATCH_COUNT_VEHICLE); // count_vehicle_v.erase(count_vehicle_v.begin(), count_vehicle_v.begin() + OBJ_BATCH_COUNT_VEHICLE); // // count_vehivle_finishanalysis -= OBJ_BATCH_COUNT_VEHICLE; //前OBJ_BATCH_COUNT_VEHICLE个快照已经完成二次属性分析 // if (vehicle_analysis_cf == SY_CONFIG_OPEN) // { // if (vp_result != NULL) // { // delete[] vp_result; // vp_result = NULL; // } // } // //if (vhd_handle != nullptr) // //{ // // for (int i = 0; i < w_index; ++i) // // { // // delete[] fea[i]; // // //cudaFree(batch_vehicle_f[w_index].data_); // // } // // delete[] fea; // // fea = nullptr; // //} // // // printf("real finish vpdr\n"); // } //} //针对车头特征的备份 //map mp_head; //车头 //int8 ** fea = nullptr; //int w_index = 0; //if (vcf_recg_config == SY_CONFIG_OPEN) //{ // vhd_result * vhd_res = new vhd_result[vehicle_batch_count]{}; // vhd_features_process(vhd_handle, finish_vehicle_img, vehicle_batch_count, vhd_res); // // sy_img * vehicle_head_imgs = new sy_img[vehicle_batch_count]{}; // // for (int vc_idx = 0; vc_idx < vehicle_batch_count; vc_idx++) // { // OBJ_KEY cur_obj_key = vehicle_keys[vc_idx]; // vhd_result & result = vhd_res[vc_idx]; // // int max_score_index = -1; // float max_score = 0.0; // // for (int c = 0; c < result.obj_count_; c++) // { // if (result.obj_results_[c].obj_score > max_score && result.obj_results_[c].obj_index == 0) // { // max_score = result.obj_results_[c].obj_score; // max_score_index = c; // } // } // // if (max_score_index != -1) // { // int w_imglength = result.obj_results_[max_score_index].obj_rect.width_ * result.obj_results_[max_score_index].obj_rect.height_ *IMG_CHANNELS; // // if (vehicle_head_imgs[w_index].data_ == 0) // cudaMalloc(&vehicle_head_imgs[w_index].data_, w_imglength * sizeof(unsigned char)); // // cudacommon::CropImgGpu((unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame, VEHICLE_WIDTH, VEHICLE_HEIGHT, // vehicle_head_imgs[w_index].data_, result.obj_results_[max_score_index].obj_rect.left_, result.obj_results_[max_score_index].obj_rect.top_, // result.obj_results_[max_score_index].obj_rect.width_, result.obj_results_[max_score_index].obj_rect.height_); // // vehicle_head_imgs[w_index].w_ = result.obj_results_[max_score_index].obj_rect.width_; // vehicle_head_imgs[w_index].h_ = result.obj_results_[max_score_index].obj_rect.height_; // vehicle_head_imgs[w_index].c_ = IMG_CHANNELS; // ++w_index; // mp_head.insert({ vc_idx, cur_obj_key }); // } // } // // cudaDeviceSynchronize();//将会一直处于阻塞状态,直到前面所有请求的任务已经被全部执行完毕 // // if (w_index != 0) // { // fea = new int8*[w_index] {}; // for (int ii = 0; ii < w_index; ++ii) // { // fea[ii] = new int8[FEATURESIZE]{}; // } // vf_features_process(vf_handle, vehicle_head_imgs, w_index, fea); // } // // for (size_t ii = 0; ii < vehicle_batch_count; ii++) // { // if (vehicle_head_imgs[ii].data_ != NULL) // { // cudaFree(vehicle_head_imgs[ii].data_); // vehicle_head_imgs[ii].data_ = NULL; // } // // } // delete[] vehicle_head_imgs; // vehicle_head_imgs = NULL; // // if (vhd_res != NULL) // { // if (w_index != 0) // { // delete[] vhd_res; // vhd_res = NULL; // } // } //}