#include #include "../../DxDecoder/DxDecoderWrap.h" #include "common.h" #include #include #include #include #include #include #include #include "ImageSaveCache.h" #include "SnapShotFrameCache.h" using namespace std; #define EDGESIZE 4 #define HP_WIDTH 112 #define HP_HEIGHT 224 #define HCP_WIDTH 224 #define HCP_HEIGHT 224 #define VEHICLE_WIDTH 320 #define VEHICLE_HEIGHT 320 //#define OBJ_BATCH_COUNT 20//定义多少个目标组成一组batch送入二次分析的算法 //#define OBJ_BATCH_COUNT_VEHICLE 10 //定义多少个目标组成一组batch送入二次分析的算法 #define IMG_CHANNELS 3 #ifndef _MSC_VER #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #define Sleep(a) usleep((a)*1000) //typedef int BOOL; #define BOOL bool typedef unsigned int DWORD; typedef void* LPVOID; #endif struct AABBBOX { int left; int top; int right; int bottom; }; //struct OBJ_KEY { // int videoID; // int objID; // // bool operator< (OBJ_KEY const& _A) const // { // if (videoID < _A.videoID) return true; // if (videoID == _A.videoID) return objID < _A.objID; // // return false; // } // bool operator== (OBJ_KEY const& _A) const // { // if (videoID == _A.videoID && objID == _A.objID) // return true; // else // return false; // } //}; struct OBJ_INDEX { int index; int count; //用于对index的计数 }; struct OBJ_VALUE { bool finishTracker; //轨迹结束可以保存了 int frameCount; bool isupdate; int lost; DxGPUFrame snapShot; DxGPUFrame snapShotLittle; AABBBOX box; double confidence; // 置信度 //int index; float lastArea; bitset flags; //标志位,标记快照框应该如何判断,left:0 top:1 right:2 bottom:3 OBJ_INDEX index; }; struct TASK_INFO { char* image_folder; char* snapshot_folder; int task_total_framecount; SNAPSHOT_CALLBACK obj_callback; TASK_INFO() :image_folder(NULL), snapshot_folder(NULL), obj_callback(NULL) {} }; struct OBJ_SIZE { int original_width; int original_height; }; struct SNAPSHOT_IMAGE_UNIT { cv::Mat image; bool flag; string file_name; OBJ_SIZE original_size; OBJ_KEY obj_key; bool is_image; SNAPSHOT_IMAGE_UNIT(int height, int width, int type, float* data) :image(height, width, type, data) {} SNAPSHOT_IMAGE_UNIT(int height, int width, int type, unsigned char* data) :image(height, width, type, data) {} SNAPSHOT_IMAGE_UNIT() {} }; enum { HP_ANALYSIS, HCP_ANALYSIS, VC_ANALYSIS }; //enum class VC_ANALYSIS_TYPE { // VC_ANALYSIS, // VR_VF_ANALYSIS, // VPDR_ANALYSIS //}; enum class V_ANALYSIS_TYPE { VC_ANALYSIS, VR_VF_ANALYSIS, VPDR_ANALYSIS }; extern string ObjTypes[]; extern string ObjTypesEnglish[]; class snapshot_helper { private: queue count_person; queue count_bike; queue count_vehicle; //map snapShotInfo_hpf; //map snapShotInfo_hcpf; vector count_vehicle_v; //车的二次属性分析拆为三部分时,不再使用队列,只能使用数组 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; void * hp_handle = nullptr; void * hcp_handle = nullptr; void * vc_handle = nullptr; void * vp_handle = nullptr; void * vr_handle = nullptr; void * vrr_handle = nullptr; void * vhd_handle = nullptr; void * vf_handle = nullptr; sy_command hp_analysis_cf; sy_command hcp_analysis_cf; sy_command vehicle_analysis_cf; sy_command hf_recg_cf; sy_command hcf_recg_cf; sy_command vcf_recg_cf; void * hf_handle = nullptr; void * hcf_handle = nullptr; sy_command vehicle_recg_cf; sy_command vehicle_plate_det_recg_cf; int count_vehivle_finishanalysis = 0; int OBJ_BATCH_COUNT = 0; int OBJ_BATCH_COUNT_VEHICLE = 0; boost::thread ProcessSnapshotThread; public: SnapShotFrameCache snapShotCache; map snapShotInfo; queue snapshotImageQueue; map finished_analysis_ss_info; set finished_save_ss_info; unordered_map m_task_info; ImageSaveCache ImgSaveCache; std::deque cur_image_queue; std::mutex threadMutex; std::mutex writeThreadMutex; std::mutex analysisThreadMutex; std::condition_variable writeThreadCondVar; //VC_ANALYSIS_TYPE vc_analysis; V_ANALYSIS_TYPE v_analysis; void 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); void snapshot_helper_release(); void add_task_info(int new_task_id, TASK_INFO new_task_info); void delete_task_info(int new_task_id, TASK_INFO new_task_info); int 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, int top, int right, int bottom); int 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, int top, int right, int bottom); int save_snapshot(OBJ_KEY obj_key); void save_without_analysis(OBJ_KEY obj_key); void erase_snapshotImage(OBJ_KEY obj_key); //整体的三种二次属性分析 void hp_analysis(OBJ_KEY obj_key); void hcp_analysis(OBJ_KEY obj_key); void vehicle_analysis(OBJ_KEY obj_key); void hp_analysis(); void hcp_analysis(); bool vehicle_color_analysis(); bool vehicle_recg_analysis(); bool vehicle_plate_dr_analysis(); void vf_feature(); void vf_feature(sy_img *batch_vehicle_f, int batch_size, map &mp_head); void 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); //针对车拆开的二次属性分析 void VehicleRecog_Process(sy_img * batch_img, int batchsize, vr_result *&vresult, OBJ_KEY* obj_keys); void object_attri_analysis(); void snapshot_res_callback(OBJ_KEY obj_key,/* OBJ_VALUE obj_value,*/ void* analysisRes = NULL); void hp_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis, bool flag); void hcp_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis, bool flag); void vehicle_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis, bool flag); void vf_feature(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis); void hf_features(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis, bool flag); void vehicle_color_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis); void vehicle_plate_dr_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis); void vehicle_recg_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis); };