#ifdef _MSC_VER //#include "stdafx.h" #include #endif #include #include #include #include "time.h" #include #include #include "../VPT/mvpt.h" //#include "../VPT/header.h" #include "sy_common.h" #include "opencv2/opencv.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #ifdef _MSC_VER #include #include #define ACCESS _access #define MKDIR(a) _mkdir((a)) #else #include #include #include #define ACCESS access #define MKDIR(a) mkdir((a),0755) #define TRUE 1 #define FALSE 0 #define Sleep(a) usleep((a)*1000) typedef int BOOL; typedef unsigned int DWORD; typedef void* LPVOID; typedef char _TCHAR; #endif #ifdef _DEBUG #else #pragma comment(lib,"mvpt.lib") //库文件 #endif using namespace std; //行人二次属性分析结果 static string head[5] = { "长发", "短发", "光头", "帽子", "其他" }; static string head_color[9] = { "黑", "白", "灰", "红", "蓝", "黄", "绿", "多色", "其他" }; static string eye[2] = { "未戴眼镜", "戴眼镜" }; static string mouth[2] = { "未戴口罩", "戴口罩" }; static string up[9] = { "T恤", "衬衫", "毛衣", "羽绒服", "大衣", "外套", "连衣裙", "无上衣", "其他" }; static string up_color[9] = { "黑", "白", "灰", "红", "蓝", "黄", "绿", "多色", "其他" }; static string clothing_text[5] = { "纯色", "碎花", "条纹", "格子", "其他" }; static string down[6] = { "长裤", "短裤", "长裙", "短裙", "连衣裙", "其他" }; static string down_color[9] = { "黑", "白", "灰", "红", "蓝", "黄", "绿", "多色", "其他" }; static string bao[5] = { "无包", "单肩包", "背包/双肩包", "手提包/手提物", "拉杆箱/小推车" }; static string sex[3] = { "男", "女", "其他" }; static string age[5] = { "小孩", "青年", "中年", "老年", "其他" }; static string viewpoint[3] = { "正面", "背面", "侧面" }; static string dasan[2] = { "未打伞", "打伞" }; static string child[2] = { "未抱小孩", "抱小孩" }; static string personstate[5] = { "行走", "奔跑", "蹲坐", "推车", "其他" }; //人骑车二次属性分析结果 string hcp_up[12] = { "T恤", "马甲/吊带/背心", "衬衫", "西服", "毛衣", "皮衣/夹克", "羽绒服", "大衣/风衣", "外套", "连衣裙", "无上衣", "其他" }; string hcp_up_color[12] = { "黑", "白", "红", "黄", "蓝", "绿", "紫", "棕", "灰", "橙", "多色", "其他" }; string hcp_down[6] = { "长裤", "短裤", "长裙", "短裙", "连衣裙", "其他" }; string hcp_down_color[12] = { "黑", "白", "红", "黄", "蓝", "绿", "紫", "棕", "灰", "橙", "多色", "其他" }; string hcp_bao[5] = { "无包", "单肩包", "双肩包", "其他", "钱包" }; string hcp_bag_color[12] = { "黑", "白", "红", "黄", "蓝", "绿", "紫", "棕", "灰", "橙", "多色", "其他" }; string hcp_head[6] = { "长发", "短发", "光头", "帽子", "头盔", "其他" }; string hcp_clothing_text[5] = { "纯色", "碎花", "条纹", "格子", "其他" }; string hcp_sex[3] = { "男", "女", "不明" }; string hcp_figure[3] = { "胖", "瘦", "中" }; string hcp_nationality[5] = { "汉族", "维族", "黑人", "白人", "其他" }; string hcp_age[6] = { "幼儿", "儿童", "青年", "中年", "老年", "不明" }; string hcp_eye[4] = { "正常眼睛", "眼镜", "墨镜", "其他" }; string hcp_mouth[3] = { "正常嘴", "戴口罩", "其他" }; string hcp_weibo[3] = { "无围巾", "普通围巾", "包头围巾" }; string hcp_carColor[13] = { "黑", "白", "红", "黄", "蓝", "绿", "紫", "棕", "灰", "橙", "多色", "其他", "银" }; string hcp_orient[3] = { "正面", "背面", "侧面" }; string hcp_drivenum[4] = { "0人", "1人", "2人", "更多人" }; string hcp_dasan[2] = { "无", "有" }; string hcp_take[2] = { "无", "物品" }; //车辆二次属性分析结果 static char colorLabel[14][8] = { "棕", "橙", "灰", "白", "粉", "紫", "红", "绿", "蓝", "金", "银", "青", "黄", "黑" }; #define PRINTF_ATTRIRES void videoObjInfoCallback(video_object_info *obj_info) { //检测结果处理函数 /*cout << "ObjInfo " << obj_info->task_id << " " << obj_info->task_frame_count << " " << obj_info->object_id << " " << obj_info->left << " " << obj_info->top << " " << obj_info->right << " " << obj_info->bottom << " " << obj_info->index << " " << obj_info->confidence << endl;*/ } #include std::queue results; static int index = 0; void videoObjSnapshotCallback(video_object_snapshot *snapshot_info) { //检测快照结果处理函数 /*cout << "snapshot " << snapshot_info->task_id << " " << snapshot_info->object_id << " " << snapshot_info->video_image_path << " " << snapshot_info->snapshot_image_path << " " << snapshot_info->object_type_index << " " << snapshot_info->progress << " " << snapshot_info->confidence << " " << snapshot_info->left << " " << snapshot_info->right << " " << snapshot_info->top << " " << snapshot_info->bottom << endl;*/ //输出二次属性分析结果 if (snapshot_info->analysisRes != NULL) { if (0 == snapshot_info->object_type_index) { hp_result * result = (hp_result *)snapshot_info->analysisRes; hp_res *resHP = &result->res_objs; #ifdef PRINTF_ATTRIRES if (result->feature != 0) { cout << "feature[0] :" << result->feature[0] << endl; cout << "feature[1] :" << result->feature[1] << endl; cout << "feature[2] :" << result->feature[2] << endl; cout << "feature[3] :" << result->feature[3] << endl; cout << "feature[4] :" << result->feature[4] << endl; } cv::Mat resImg = cv::imread(snapshot_info->snapshot_image_path); string resFileName = "picHP/" + to_string(index++) + "_"; for (int i = 0; i < HP_FIR_INDEX_SIZE; i++) { int resIndex = resHP->res_objs[i].res_index; switch (i) { case 0: cout << head[resIndex] << " "; resFileName += head[resIndex]; resFileName += "_"; break; case 1: cout << head_color[resIndex] << " "; resFileName += head_color[resIndex]; resFileName += "_"; break; case 2: cout << eye[resIndex] << " "; resFileName += eye[resIndex]; resFileName += "_"; break; case 3: cout << mouth[resIndex] << " "; resFileName += mouth[resIndex]; resFileName += "_"; break; case 4: cout << up[resIndex] << " "; resFileName += up[resIndex]; resFileName += "_"; break; case 5: cout << up_color[resIndex] << " "; resFileName += up_color[resIndex]; resFileName += "_"; break; case 6: cout << clothing_text[resIndex] << " "; resFileName += clothing_text[resIndex]; resFileName += "_"; break; case 7: cout << down[resIndex] << " "; resFileName += down[resIndex]; resFileName += "_"; break; case 8: cout << down_color[resIndex] << " "; resFileName += down_color[resIndex]; resFileName += "_"; break; case 9: cout << bao[resIndex] << " "; resFileName += bao[resIndex]; resFileName += "_"; break; case 10: cout << sex[resIndex] << " "; resFileName += sex[resIndex]; resFileName += "_"; break; case 11: cout << age[resIndex] << " "; resFileName += age[resIndex]; resFileName += "_"; break; case 12: cout << viewpoint[resIndex] << " "; resFileName += viewpoint[resIndex]; resFileName += "_"; break; case 13: cout << dasan[resIndex] << " "; resFileName += dasan[resIndex]; resFileName += "_"; break; case 14: cout << child[resIndex] << " "; resFileName += child[resIndex]; resFileName += "_"; break; case 15: cout << personstate[resIndex] << " "; resFileName += personstate[resIndex]; resFileName += "_"; break; default: break; } } cout << endl << endl; resFileName += ".jpg"; cv::imwrite(resFileName, resImg); #endif } else if (1 == snapshot_info->object_type_index || 2 == snapshot_info->object_type_index) { hcp_result * result = (hcp_result *)snapshot_info->analysisRes; hcp_res *resHP = &result->res_objs; #ifdef PRINTF_ATTRIRES cv::Mat resImg = cv::imread(snapshot_info->snapshot_image_path); string resFileName = "picHCP/" + to_string(index++) + "_"; if (result->feature != 0) { cout << "feature[0] :" << result->feature[0] << endl; cout << "feature[1] :" << result->feature[1] << endl; cout << "feature[2] :" << result->feature[2] << endl; cout << "feature[3] :" << result->feature[3] << endl; cout << "feature[4] :" << result->feature[4] << endl; } for (int i = 0; i < HCP_FIR_INDEX_SIZE; i++) { int resIndex = resHP->res_objs[i].res_index; //输出结果 switch (i) { case 0: cout << hcp_up[resIndex] << " "; resFileName += hcp_up[resIndex]; resFileName += "_"; break; case 1: cout << hcp_up_color[resIndex] << " "; resFileName += hcp_up_color[resIndex]; resFileName += "_"; break; case 2: cout << hcp_down[resIndex] << " "; resFileName += hcp_down[resIndex]; resFileName += "_"; break; case 3: cout << hcp_down_color[resIndex] << " "; resFileName += hcp_down_color[resIndex]; resFileName += "_"; break; case 4: cout << bao[resIndex] << " "; resFileName += bao[resIndex]; resFileName += "_"; break; case 5: cout << hcp_bag_color[resIndex] << " "; resFileName += hcp_bag_color[resIndex]; resFileName += "_"; break; case 6: cout << hcp_head[resIndex] << " "; resFileName += hcp_head[resIndex]; resFileName += "_"; break; case 7: cout << hcp_clothing_text[resIndex] << " "; resFileName += hcp_clothing_text[resIndex]; resFileName += "_"; break; case 8: cout << hcp_sex[resIndex] << " "; resFileName += hcp_sex[resIndex]; resFileName += "_"; break; case 9: cout << hcp_figure[resIndex] << " "; resFileName += hcp_figure[resIndex]; resFileName += "_"; break; case 10: cout << hcp_nationality[resIndex] << " "; resFileName += hcp_nationality[resIndex]; resFileName += "_"; break; case 11: cout << hcp_age[resIndex] << " "; resFileName += hcp_age[resIndex]; resFileName += "_"; break; case 12: cout << hcp_eye[resIndex] << " "; resFileName += hcp_eye[resIndex]; resFileName += "_"; break; case 13: cout << hcp_mouth[resIndex] << " "; resFileName += hcp_mouth[resIndex]; resFileName += "_"; break; case 14: cout << hcp_weibo[resIndex] << " "; resFileName += hcp_weibo[resIndex]; resFileName += "_"; break; case 15: cout << hcp_carColor[resIndex] << " "; resFileName += hcp_carColor[resIndex]; resFileName += "_"; break; case 16: cout << hcp_orient[resIndex] << " "; resFileName += hcp_orient[resIndex]; resFileName += "_"; break; case 17: cout << hcp_drivenum[resIndex] << " "; resFileName += hcp_drivenum[resIndex]; resFileName += "_"; break; case 18: cout << hcp_dasan[resIndex] << " "; resFileName += hcp_dasan[resIndex]; resFileName += "_"; break; case 19: cout << hcp_take[resIndex] << " "; resFileName += hcp_take[resIndex]; resFileName += "_"; break; default: break; } } cout << endl << endl; cout << endl << endl; resFileName += ".jpg"; cv::imwrite(resFileName, resImg); #endif } else if (8 == snapshot_info->object_type_index || (snapshot_info->object_type_index >= 4 && snapshot_info->object_type_index <= 6)) { vehicle_result *resHP = (vehicle_result *)snapshot_info->analysisRes; if (resHP->feature != 0) { cout << "feature[0] :" << resHP->feature[0] << endl; cout << "feature[1] :" << resHP->feature[1] << endl; cout << "feature[2] :" << resHP->feature[2] << endl; cout << "feature[3] :" << resHP->feature[3] << endl; cout << "feature[4] :" << resHP->feature[4] << endl; } if (resHP->vp_res.type > 20 || resHP->vp_res.type < 0) { return; } #ifdef PRINTF_ATTRIRES cv::Mat resImg = cv::imread(snapshot_info->snapshot_image_path); string resFileName = "picV/" + to_string(index++) + "_"; //VC cout << "VC: " << resHP->vc_res.res_index << " " << colorLabel[resHP->vc_res.res_index] << " " << resHP->vc_res.res_prob << endl; resFileName = resFileName + colorLabel[resHP->vc_res.res_index] + "_" + to_string(resHP->vc_res.res_prob); //VP if (resHP->vp_res.rect.left_ != -1) { cout << "VP: " << resHP->vp_res.rect.left_ << " " << resHP->vp_res.rect.top_ << " " << resHP->vp_res.rect.width_ << " " << resHP->vp_res.rect.height_ << endl; resFileName = resFileName + "_" + to_string(resHP->vp_res.rect.left_) + "_" + to_string(resHP->vp_res.rect.top_) + "_" + to_string(resHP->vp_res.rect.width_) + "_" + to_string(resHP->vp_res.rect.height_) + "_"; for (int m = 0; m < 7; m++) { printf("%s", resHP->vp_res.recg[m].character); resFileName += resHP->vp_res.recg[m].character; } resFileName = resFileName + "_" + to_string(resHP->vp_res.num_score) + "_" + to_string(resHP->vp_res.detect_score) + "_"; printf(" numScore = %.2f, detectScore = %.2f\n", resHP->vp_res.num_score, resHP->vp_res.detect_score); } //VR cout << "VP: " << endl; if (resHP->vr_res.vehicle_brand != NULL) { cout << " 车辆品牌 - " << resHP->vr_res.vehicle_brand << endl; resFileName += resHP->vr_res.vehicle_brand; } if (resHP->vr_res.vehicle_subbrand != NULL) { cout << " 车辆子品牌 - " << resHP->vr_res.vehicle_subbrand << endl; resFileName += resHP->vr_res.vehicle_subbrand; } if (resHP->vr_res.vehicle_issue_year != NULL) { cout << " 车辆年款 - " << resHP->vr_res.vehicle_issue_year << endl; resFileName += resHP->vr_res.vehicle_issue_year; } if (resHP->vr_res.vehicle_type != NULL) { cout << " 车辆类型 - " << resHP->vr_res.vehicle_type << endl; resFileName += resHP->vr_res.vehicle_type; } if (resHP->vr_res.freight_ton != NULL) { cout << " 货车吨级 - " << resHP->vr_res.freight_ton << endl; resFileName += resHP->vr_res.freight_ton; } cout << " " << resHP->vr_res.name_score << endl; resFileName = resFileName + "_" + to_string(resHP->vr_res.name_score); cout << endl << endl; resFileName += ".jpg"; cv::imwrite(resFileName, resImg); #endif } } video_object_snapshot *videoObjectSnapshot = snapshot_info; video_object_snapshot tmp; tmp.object_id = videoObjectSnapshot->object_id; tmp.task_id = videoObjectSnapshot->task_id; memcpy(tmp.snapshot_image_path, videoObjectSnapshot->snapshot_image_path, 256); tmp.object_type_index = videoObjectSnapshot->object_type_index; memcpy(tmp.obj_type, videoObjectSnapshot->obj_type, 64); tmp.progress = videoObjectSnapshot->progress; tmp.left = videoObjectSnapshot->left; tmp.top = videoObjectSnapshot->top; tmp.right = videoObjectSnapshot->right; tmp.bottom = videoObjectSnapshot->bottom; tmp.confidence = videoObjectSnapshot->confidence; if (0 == videoObjectSnapshot->object_type_index) { if (videoObjectSnapshot->analysisRes) { tmp.analysisRes = new hp_res{}; memcpy(tmp.analysisRes, videoObjectSnapshot->analysisRes, sizeof(hp_res)); } } else if (1 == videoObjectSnapshot->object_type_index || 2 == videoObjectSnapshot->object_type_index) { if (videoObjectSnapshot->analysisRes) { tmp.analysisRes = new hcp_res{}; memcpy(tmp.analysisRes, videoObjectSnapshot->analysisRes, sizeof(hcp_res)); } } else if (8 == videoObjectSnapshot->object_type_index || (videoObjectSnapshot->object_type_index >= 4 && videoObjectSnapshot->object_type_index <= 6)) { if (videoObjectSnapshot->analysisRes) { tmp.analysisRes = new vehicle_result{}; memcpy(tmp.analysisRes, videoObjectSnapshot->analysisRes, sizeof(vehicle_result)); } } results.push(tmp); cout << "snapshot " << snapshot_info->task_id << " " << snapshot_info->object_id << " " << snapshot_info->video_image_path << " " << snapshot_info->snapshot_image_path << " " << snapshot_info->object_type_index << " " << snapshot_info->progress << " " << snapshot_info->confidence << " " << snapshot_info->left << " " << snapshot_info->right << " " << snapshot_info->top << " " << snapshot_info->bottom << endl; } void videoRTViewCallback(unsigned char* imageData, int imageHeight, int imageWiddth) { //实时查看画面处理函数 //--------回调函数串行运行,请勿在此做例如显示等耗时的操作,以下操作仅供测试--------// /* cv::Mat resultImage(imageHeight, imageWiddth, CV_8UC3, imageData); cv::imshow("view", resultImage); cv::waitKey(1); */ } //操作句柄 void *handle; int curFinishTask = 0; void videoFinishCallback(const int taskID) { curFinishTask++; cout << "**** Task " << taskID << " is Finished! ****" << endl; } static int total_index = 0; int main(int argc, char **argv) { //初始化参数设置 mvpt_param vptParam; vptParam.hp_analysis_config = SY_CONFIG_OPEN; vptParam.hcp_analysis_config = SY_CONFIG_OPEN; vptParam.vehicle_analysis_config = SY_CONFIG_OPEN; vptParam.hf_recg_config = SY_CONFIG_OPEN; vptParam.hcf_recg_config = SY_CONFIG_OPEN; vptParam.vcf_recg_config = SY_CONFIG_OPEN; //是否开启车辆特征识别 vptParam.vrdbpath = "D:\\vehicle_struct\\vehicle_structure_platform.git\\db\\CarBodyFeature.db"; //"../../db/CarBodyFeature.db";// argv[2]; vptParam.task_obj_info_callback_func = videoObjInfoCallback; vptParam.task_finish_callbackfunc = videoFinishCallback; vptParam.gpuid = 0;//atoi(argv[3]); int flag = mvpt_init(&handle, vptParam); if (0 != flag) { printf("Init Failed! Error Code: %d\n", flag); system("pause"); return 0; } for (int i = 0; i < 20; i++) { //指定检测目标视频抽帧图片(保存时显存占用很大) char resultFolder[260]; sprintf(resultFolder, "res/%d", total_index); //指定检测目标快照抠图保存路径 char resultFolderLittle[260]; sprintf(resultFolderLittle, "resLittle0812/%d", total_index++); //设置最小检测框,直接指定sy_rect的宽高即可,各种类目标小于最小检测框大小时不进行快照的保存和后续二次属性分析 sy_rect m_boxsize[DETECTTYPE] = { sy_rect(0,0,40, 90), sy_rect(0,0,50, 80), sy_rect(0,0,50, 80), sy_rect(0,0,60, 80), sy_rect(0,0,80, 80), sy_rect(0,0,90, 90), sy_rect(0,0,100, 100), sy_rect(0,0,100, 100), sy_rect(0,0,100, 100) }; //行人 自行车 摩托车 三轮车 小型车 大车 卡车 拖拉机 中巴 task_param tparam; tparam.result_folder = NULL; tparam.result_folder_little = resultFolderLittle; tparam.video_filename = "D:\\test.mp4"; // "D:/TestData/人车物/测试视频7.mp4"; ;// argv[1]; memcpy(tparam.minBoxsize, m_boxsize, sizeof(sy_rect)* DETECTTYPE); tparam.rt_view_callback_func = videoRTViewCallback; tparam.obj_snapshot_callback_func = videoObjSnapshotCallback; int newTaskID = add_task(handle, tparam); Sleep(2000); } /*pause_task(handle, 0); Sleep(2000); restart_task(handle, 0); Sleep(2000); pause_task(handle, 1); Sleep(2000); restart_task(handle, 1); Sleep(2000); finish_task(handle, 1); Sleep(2000); rt_view_task(handle, 2); Sleep(50000); finish_view_task(handle);*/ while (1) { Sleep(100); } mvpt_release(&handle); return 0; }