#include #include #include #include #ifdef _MSC_VER #include "../VPT/VPT.h" #include #include #include #include #else #include "VPT.h" #include #include #include #endif //#include "../VPT/header.h" #ifndef _MSC_VER #include #include #include #define Sleep(a) usleep((a)*1000) #define MACRO_COUNT_TIME_START(name) struct timeval macro_tv_start_##name;\ struct timeval macro_tv_end_##name;\ gettimeofday(¯o_tv_start_##name,NULL); #define MACRO_COUNT_TIME_END(name,___total_count___) gettimeofday(¯o_tv_end_##name,NULL);\ printf("%s time cost: %.2f ms \n", #name, ( (double)(macro_tv_end_##name.tv_sec-macro_tv_start_##name.tv_sec)*1000000+(double)(macro_tv_end_##name.tv_usec-macro_tv_start_##name.tv_usec) )/1000/___total_count___); #endif using namespace cv; using namespace std; //检测种类 const int detectType = 9; //行人 自行车 摩托车 三轮车 小型车 大车 卡车 拖拉机 中巴 string type[detectType] = { "person", "bike", "motor", "tricycle", "car", "bigbus", "lorry", "tractor", "midibus" }; static int color[detectType][3] = { { 41, 244, 222 }, { 255, 128, 0 }, { 100, 13, 244 }, { 255, 215, 0 }, { 18, 220, 87 }, { 0, 128, 0 }, \ {0, 128, 255}, { 255, 0, 0 }, { 91, 46, 0 } }; //返回快照结果回调函数 void SnapshotInfoCallback(VIDEO_OBJECT_SNAPSHOT *videoObjectSnapshot) { cout << videoObjectSnapshot->objectID << " " << videoObjectSnapshot->left << " " << videoObjectSnapshot->right << " " << videoObjectSnapshot->top << " " << videoObjectSnapshot->bottom << " " << videoObjectSnapshot->firstPicPath << " " << videoObjectSnapshot->secondPicPath << " " << videoObjectSnapshot->taskFrameCount << " " << videoObjectSnapshot->objectIndex << endl; } //显示变量 Mat imgResized; bool img_show = false; bool show = true; #ifdef _MSC_VER //显示线程 DWORD WINAPI DiaplayThread(LPVOID param) { LARGE_INTEGER nFreq, nSaveBeginTime, nSaveEndTime; QueryPerformanceFrequency(&nFreq); while (show) { if (img_show) { cv::imshow("RESULT", imgResized); cv::waitKey(1); img_show = false; } Sleep(1); } return 0; } #endif int testPic(int pic_index) { //字体初始化 CvFont font; cvInitFont(&font, CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0, 0, 1, 3); int fontFace = CV_FONT_HERSHEY_COMPLEX; double fontScale = 1; int thickness = 2; //其他变量 Mat img; int frameCount = 0; const int maxResultCount = 100; #ifdef _MSC_VER LARGE_INTEGER nFreq, nBeginTime, nEndTime; QueryPerformanceFrequency(&nFreq); #endif //初始化 //快照保存参数设置 SNAPSHOT_PARAMETER ssparam; ssparam.selectFromMinbox = true; ssparam.selectFromMindistance = true; //1.设置最小检测框,各种类目标小于最小检测框大小时不进行快照的保存 MRECT m_boxsize[DETECTTYPE] = { MRECT(20, 20), MRECT(50, 80), MRECT(50, 80), MRECT(60, 80), MRECT(80, 80), MRECT(90, 90), MRECT(100, 100), MRECT(100, 100), MRECT(100, 100) }; //行人 自行车 摩托车 三轮车 小型车 大车 卡车 拖拉机 中巴 //2.设置目标距离画面边框的最小距离,当目标位置与画面边框小于最小距离时不再更新快照 int m_distance[EDGES] = { 20, 30, 20, 30 }; //left, top, right, bottom memcpy(ssparam.minBoxsize, m_boxsize, sizeof(MRECT)* DETECTTYPE); memcpy(ssparam.minDistance, m_distance, sizeof(int)* EDGES); void * tools = NULL; VPT_PARAM vparam; vparam.gpuid = 1;//atoi(argv[2]); vparam.maxResultCount = maxResultCount; //限制算法内部输出的最大前景个数 vparam.SnaoshotParameter = &ssparam; // vparam.serialize_file = "./serialize_file/"; #ifdef _MSC_VER int res = VPT_Init(&tools, vparam, "G:/TestRes", SnapshotInfoCallback); #else int res = VPT_Init(&tools, vparam, "./", SnapshotInfoCallback); #endif if (res != 0) { cout << "VPT Init Failed!" << endl; system("pause"); return 0; } //结果变量 VPT_Result result; result.obj = new VPT_ObjInfo[maxResultCount]; //设置外部接收结果的最大前景个数 #ifdef _MSC_VER //创建显示线程 DWORD dwThreadID = 0; HANDLE handle_display = CreateThread(NULL, 0, DiaplayThread, 0, 0, &dwThreadID); #endif int start = 0; double totalTime = 0.0; //检测 ofstream file("res.txt"); int totalPic = 15; int i = pic_index; // for(int i=0; i &A, vector &B) { double total = 0; for (int i = 0; i < 256; i++) { total += pow(A[i] - B[i], 2); } return total; } vector fea_a; vector fea_b; vector fea_c; vector fea_a1; vector fea_b1; vector fea_c1; for(int idx=0; idx<256; idx++) { fea_a.push_back(0.1); fea_b.push_back(0.3); fea_c.push_back(0.0); fea_c1.push_back(0.0); } double length_a, length_b, length_c = 0; for (int j = 0; j < fea_a.size(); j++) { length_a += pow(fea_a[j], 2); length_b += pow(fea_b[j], 2); length_c += pow(fea_c[j], 2); if(j<5) printf("j=%d %f %f\n", length_a,length_b) ; } printf("\n"); double ratio_a = sqrt(length_a); double ratio_b = sqrt(length_b); double ratio_c = sqrt(length_c); printf("%f %f %f\n",ratio_a,ratio_b, ratio_c ); for (int j = 0; j < fea_a.size(); j++) { fea_a1.push_back(fea_a[j]/ratio_a); fea_b1.push_back(fea_b[j]/ratio_b); if(j<5) printf("j=%d %f %f\n", fea_a[j]/ratio_a, fea_b[j]/ratio_b) ; } printf("a-b: %f\n", euclideanSimilarity(fea_a1, fea_b1)); printf("a-c: %f\n", euclideanSimilarity(fea_a1, fea_c1)); return 0; */