main.cpp 27.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
#ifdef _MSC_VER

#include <windows.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include "time.h"
#include <vector>
#include <string>
#include "header.h"
#include "mvpt.h"
#include "sy_common.h"
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
// #include "opencv2/imgcodecs/imgcodecs.hpp"

#ifdef _MSC_VER
#include <direct.h>
#include <io.h>
#define ACCESS _access
#define MKDIR(a) _mkdir((a))
#else
#include <unistd.h>
#include <stdarg.h>
#include <sys/stat.h>
#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 std::string head[] = { "长发", "短发", "其他" };
static std::string head_color[] = { "黑", "白", "其他" };
static std::string eye[] = { "未戴眼镜", "戴眼镜" };
static std::string mouth[] = { "未戴口罩", "戴口罩" };
static std::string up[] = { "T恤/背心", "衬衫",  "毛衣", "外套", "连衣裙", "其他" };
static std::string up_color[] = { "黑", "白", "灰", "红", "蓝", "黄", "绿", "多色", "其他" };
static std::string clothing_text[] = { "纯色", "碎花", "条纹/格子", "其他" };
static std::string down[] = { "长裤", "短裤", "长裙", "短裙", "连衣裙", "其他" };
static std::string down_color[] = { "黑", "白", "灰", "红", "蓝", "黄", "绿", "多色", "其他" };
static std::string bao[] = { "无包", "有包" };
static std::string sex[] = { "男", "女", "不明" };
static std::string age[] = { "小孩", "成人", "不明" };
static std::string viewpoint[] = { "正面","背面", "侧面" };
static std::string dasan[] = { "未打伞", "打伞" };
static std::string child[] = { "无", "抱小孩" };
static std::string personstate[] = { "行走/站立", "奔跑", "坐/蹲", "推车", "其他" };


static std::string hcp_head[] = { "长发", "短发", "头盔", "其他" };
static std::string hcp_eye[] = { "未戴眼镜", "戴眼镜" };
static std::string hcp_mouth[] = { "未戴口罩", "戴口罩" };
static std::string hcp_weibo[] = { "未戴围巾", "戴围巾" };
static std::string hcp_up[] = { "T恤/背心", "衬衫", "毛衣", "外套", "连衣裙", "其他" };
static std::string hcp_up_color[] = { "黑", "白", "灰", "红", "蓝", "黄", "绿", "多色", "不明" };
static std::string hcp_clothing_text[] = { "纯色", "碎花", "条纹/格子", "其他" };
static std::string hcp_bao[] = { "无包", "背包" };
static std::string hcp_sex[] = { "男", "女", "不明" };
static std::string hcp_age[] = { "小孩", "成人", "其他" };
static std::string hcp_carColor[] = { "黑", "白", "红", "其他" };
static std::string hcp_orient[] = { "正面", "背面", "侧面" };
static std::string hcp_dasan[] = { "无", "有" };
static std::string hcp_take[] = { "无", "有" };

//车辆二次属性分析结果
static char colorLabel[14][8] = { "棕", "橙", "灰", "白", "粉", "紫", "红", "绿", "蓝", "金", "银", "青", "黄", "黑" };

//人车物检测结果221128byzsh
static std::string vpt_types[] = { "person", "bicycle", "motor", "tricycle", "car", "bus", "truck", "mpv", "midbus", "e_bicycle"};

//设置最小检测框,直接指定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) };  //行人 自行车 摩托车 三轮车 小型车 大车 卡车 拖拉机 中巴 

#define PRINTF_ATTRIRES

																																																										//操作句柄
std::map<int, BOOL> cur_task_status_;

int CreateDir(char *pszDir)
{
	int i = 0;
	int iRet;
	int iLen = strlen(pszDir);
	if (pszDir[iLen - 1] != '\\' && pszDir[iLen - 1] != '/')
	{
		pszDir[iLen] = '/';
		pszDir[iLen + 1] = '\0';
	}
	iLen = strlen(pszDir);

	if (iLen > 2 && ((pszDir[i] == '\\' && pszDir[i + 1] == '\\') || (pszDir[i] == '/' && pszDir[i + 1] == '/')))
	{
		i = 2;
		for (; i <= iLen; i++)
			if (pszDir[i] == '\\' || pszDir[i] == '/')
				break;

		i++;

		for (; i <= iLen; i++)
		{
			if (pszDir[i] == '\\' || pszDir[i] == '/')
			{
				pszDir[i] = '\0';
				//printf("file access %s\n", pszDir);
				iRet = ACCESS(pszDir, 0);
				//printf("file access %d\n", iRet);
				if (iRet != 0)
				{
					//printf("file mkdir %s\n", pszDir);
					iRet = MKDIR(pszDir);
					//printf("file mkdir %d\n", iRet);
					if (iRet != 0)
					{
						printf("Create Folder Failed!");
						return -1;
					}
				}
				pszDir[i] = '/';

			}
		}
		return 0;
	}

	if (pszDir[i] != '\\' && pszDir[i] != '/')
		i = 0;
	else
		i = 1;
	for (; i <= iLen; i++)
	{
		if (pszDir[i] == '\\' || pszDir[i] == '/')
		{
			pszDir[i] = '\0';
			//printf("file access %s\n", pszDir);
			iRet = ACCESS(pszDir, 0);
			//printf("file access %d\n", iRet);
			if (iRet != 0)
			{
				//printf("file mkdir %s\n", pszDir);
				iRet = MKDIR(pszDir);
				//printf("file mkdir %d\n", iRet);
				if (iRet != 0)
				{
					return -1;
				}
			}
			pszDir[i] = '/';

		}
	}
	return 0;
}

void CreateResultFolder(char* resultFolder, const char* jointFolder)
{
	if (strlen(resultFolder) > 240)  //?too long
	{
		printf("Folder Name is too Long!");
		return;
	}
	else if (strlen(resultFolder) < 1)  //?too short
	{
		printf("Folder Name is too Short!");
		return;
	}

	char dir[260];

	sprintf(dir, "%s%s/", resultFolder, jointFolder);
	if (CreateDir(dir) != 0)
	{
		printf("Create Folder Failed!");
		return;
	}
}

void videoObjInfoCallback(void * handle, video_object_info *obj_info)
{
	//检测结果处理函数
	/*cout << "handle :" << handle << " 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;*/
	return;
}

static int obj_index = 0;


static vector<vector<int>> feas;

static int sum = 0;
void videoObjSnapshotCallback(void * handle, video_object_snapshot *snapshot_info)
{
	// printf("snapshot_info: %d \n", sum++);
	if(1) {
		return;
	}
//#ifdef PRINTF_ATTRIRES
// 	cout << "handle :" << handle << " snapshot " << snapshot_info->task_id << " " << snapshot_info->object_id << " " << " " << snapshot_info->task_frame_count << " " <<
// 		snapshot_info->video_image_path << " " << snapshot_info->snapshot_image_path << " " << snapshot_info->face_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;

// //#endif

// 	if (snapshot_info->face_res != nullptr)
// 	{
// 		cout << "face position: " << snapshot_info->face_res->face_position.left_ << " " << snapshot_info->face_res->face_position.top_ << " "
// 			<< snapshot_info->face_res->face_position.width_ << " " << snapshot_info->face_res->face_position.height_ << " "
// 			<< "face socre: " << snapshot_info->face_res->face_pos_score << " " << snapshot_info->face_res->score << " "
// 			<< "face angel: " << snapshot_info->face_res->roll << " " << snapshot_info->face_res->pitch <<" " << snapshot_info->face_res->yaw << " "
// 			<< "face ana: " << snapshot_info->face_res->brightness << " " << snapshot_info->face_res->clarity << " " << snapshot_info->face_res->occlusion << " "
// 			<< "face fea: " << snapshot_info->face_res->facial_fea_point[0].x_ << " " << snapshot_info->face_res->facial_fea_point[1].x_ << " " << snapshot_info->face_res->facial_fea_point[2].x_ << endl;
// 	}


	//按类别保存----------------------------------------------------------------------------------------------------
	cv::Mat resImg = cv::imread(snapshot_info->snapshot_image_path);
	stringstream ss;
	ss << obj_index++;		
	// 置信度小于0.8的motor归到电动车
	if (2 == snapshot_info->object_type_index && snapshot_info->confidence < 0.8) {
		string resFileName = "results/e_bicycle/" + ss.str() + ".jpg";
		cout << "handle: " << handle << " snapshot " << snapshot_info->task_id;
		printf("  %-5d  progress: %.4f ", snapshot_info->task_frame_count, snapshot_info->progress);
		printf(" obj_id: %-4d %.4f %-4d %-4d %-4d %-4d", snapshot_info->object_id, snapshot_info->confidence,snapshot_info->left,snapshot_info->right,snapshot_info->top,snapshot_info->bottom);
		cout << " " << resFileName << " " << " e_bicycle " << endl;;
		cv::imwrite(resFileName, resImg);
	}
	// 置信度小于0.8的midbus归到mpv
	else if (8 == snapshot_info->object_type_index && rand()%2 == 0) {
		string resFileName = "results/mpv/" + ss.str() + ".jpg";
		cout << "handle: " << handle << " snapshot " << snapshot_info->task_id;
		printf("  %-5d  progress: %.4f ", snapshot_info->task_frame_count, snapshot_info->progress);
		printf(" obj_id: %-4d %.4f %-4d %-4d %-4d %-4d", snapshot_info->object_id, snapshot_info->confidence,snapshot_info->left,snapshot_info->right,snapshot_info->top,snapshot_info->bottom);
		cout << " " << resFileName << " " << " mpv " << endl;;
		cv::imwrite(resFileName, resImg);
	}
	else {
		string resFileName = "results/" + vpt_types[snapshot_info->object_type_index] + "/" + ss.str() + ".jpg";
		cout << "handle: " << handle << " snapshot " << snapshot_info->task_id;
		printf("  %-5d  progress: %.4f ", snapshot_info->task_frame_count, snapshot_info->progress);
		printf(" obj_id: %-4d %.4f %-4d %-4d %-4d %-4d", snapshot_info->object_id, snapshot_info->confidence,snapshot_info->left,snapshot_info->right,snapshot_info->top,snapshot_info->bottom);
		cout << " " << resFileName << "  " << vpt_types[snapshot_info->object_type_index] << endl;
		cv::imwrite(resFileName, resImg);
	}
	//-------------------------------------------------------------------------------------------------------------
	
	//输出二次属性分析结果
	if (0)
	// if (snapshot_info->analysisRes != NULL)
	{
		if (0 == snapshot_info->object_type_index)
		{
			hp_result *resHP = (hp_result *)snapshot_info->analysisRes;

#ifdef PRINTF_ATTRIRES

			cv::Mat resImg = cv::imread(snapshot_info->snapshot_image_path);
			stringstream ss;
			ss << obj_index++;
			string resFileName = "picHP/" + ss.str() + "_";
			if (resHP->feature != 0)
			{
				cout << "feature[0] :" << (int)resHP->feature[0] << endl;
				cout << "feature[1] :" << (int)resHP->feature[1] << endl;
				cout << "feature[2] :" << (int)resHP->feature[2] << endl;
				cout << "feature[3] :" << (int)resHP->feature[3] << endl;
				cout << "feature[4] :" << (int)resHP->feature[4] << endl;

			}
			for (int i = 0; i < HP_FIR_INDEX_SIZE; i++)
			{
				int resIndex = resHP->res_objs.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 *resHP = (hcp_result *)snapshot_info->analysisRes;

#ifdef PRINTF_ATTRIRES
			cv::Mat resImg = cv::imread(snapshot_info->snapshot_image_path);
			stringstream ss;
			ss << obj_index++;

			string resFileName = "picHCP/" + ss.str() + "_";
			if (resHP->feature != 0)
			{
				cout << "feature[0] :" << (int)resHP->feature[0] << endl;
				cout << "feature[1] :" << (int)resHP->feature[1] << endl;
				cout << "feature[2] :" << (int)resHP->feature[2] << endl;
				cout << "feature[3] :" << (int)resHP->feature[3] << endl;
				cout << "feature[4] :" << (int)resHP->feature[4] << endl;
			}
			for (int i = 0; i < HCP_FIR_INDEX_SIZE; i++)
			{
				int resIndex = resHP->res_objs.res_objs[i].res_index;
				//输出结果

				switch (i)
				{
				case 0:
					cerr << "res_index0   =  " << resIndex << endl;
					cout << hcp_head[resIndex] << " ";
					resFileName += hcp_head[resIndex];
					resFileName += "_";
					break;
				case 1:
					cerr << "res_index1   =  " << resIndex << endl;
					cout << hcp_eye[resIndex] << " ";
					resFileName += hcp_eye[resIndex];
					resFileName += "_";
					break;
				case 2:
					cerr << "res_index2   =  " << resIndex << endl;
					cout << hcp_mouth[resIndex] << " ";
					resFileName += hcp_mouth[resIndex];
					resFileName += "_";
					break;
				case 3:
					cerr << "res_index3   =  " << resIndex << endl;
					cout << hcp_weibo[resIndex] << " ";
					resFileName += hcp_weibo[resIndex];
					resFileName += "_";
					break;
				case 4:
					cerr << "res_index4   =  " << resIndex << endl;
					cout << hcp_up[resIndex] << " ";
					resFileName += hcp_up[resIndex];
					resFileName += "_";
					break;
				case 5:
					cerr << "res_index5   =  " << resIndex << endl;
					cout << hcp_up_color[resIndex] << " ";
					resFileName += hcp_up_color[resIndex];
					resFileName += "_";
					break;
				case 6:
					cerr << "res_index6   =  " << resIndex << endl;
					cout << hcp_clothing_text[resIndex] << " ";
					resFileName += hcp_clothing_text[resIndex];
					resFileName += "_";
					break;
				case 7:
					cerr << "res_index7   =  " << resIndex << endl;
					cout << hcp_bao[resIndex] << " ";
					resFileName += hcp_bao[resIndex];
					resFileName += "_";
					break;
				case 8:
					cerr << "res_index8   =  " << resIndex << endl;
					cout << hcp_sex[resIndex] << " ";
					resFileName += hcp_sex[resIndex];
					resFileName += "_";
					break;
				case 9:
					cerr << "res_index9   =  " << resIndex << endl;
					cout << hcp_age[resIndex] << " ";
					resFileName += hcp_age[resIndex];
					resFileName += "_";
					break;
				case 10:
					cerr << "res_index10   =  " << resIndex << endl;
					cout << hcp_carColor[resIndex] << " ";
					resFileName += hcp_carColor[resIndex];
					resFileName += "_";
					break;
				case 11:
					cerr << "res_index11   =  " << resIndex << endl;
					cout << hcp_orient[resIndex] << " ";
					resFileName += hcp_orient[resIndex];
					resFileName += "_";
					break;
				case 12:
					cerr << "res_index12   =  " << resIndex << endl;
					cout << hcp_dasan[resIndex] << " ";
					resFileName += hcp_dasan[resIndex];
					resFileName += "_";
					break;
				case 13:
					cerr << "res_index13   =  " << resIndex << endl;
					cout << hcp_take[resIndex] << " ";
					resFileName += hcp_take[resIndex];
					resFileName += "_";
					break;
				default:
					break;
				}
			}

			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;
#ifdef PRINTF_ATTRIRES_CAR
			if (resHP->feature != 0)
			{
				vector<int> cur_fea;
				for (int ii = 0; ii < VEHICLE_FEA_SIZE; ii++)
					cur_fea.push_back((int)resHP->feature[ii]);
				

				for (int c = 0; c < feas.size(); c++)
				{
					auto f = [](vector<int> a, vector<int> b)->bool {
						bool same = true;
						for (int ii = 0; ii < VEHICLE_FEA_SIZE; ii++)
						{
							if (a[ii] != b[ii])
							{
								same = false;
								break;
							}
						}
						return same;
					};

					if (f(cur_fea, feas[c]))
					{
						printf("ERROR: SAME!\n");
						for (int ii = 0; ii < VEHICLE_FEA_SIZE; ii++)
						{
							cout << (int)cur_fea[ii] << " ";
						}
						cout << endl;
						for (int ii = 0; ii < VEHICLE_FEA_SIZE; ii++)
						{
							cout << (int)feas[c][ii] << " ";
						}
						cout << endl;
					}
				}
				
				feas.push_back(cur_fea);

				/*cout << "feature :" << endl;
				for (int ii = 0; ii < 20; ii++)
				{
					cout << (int)resHP->feature[ii] << " ";
				}*/
				/*cout << "feature :" << (int)resHP->feature[0] << endl;
				cout << "feature :" << (int)resHP->feature[1] << endl;
				cout << "feature :" << (int)resHP->feature[2] << endl;
				cout << "feature :" << (int)resHP->feature[3] << endl;
				cout << "feature :" << (int)resHP->feature[4] << endl;*/
			}
#endif
#ifdef PRINTF_ATTRIRES
			cv::Mat resImg = cv::imread(snapshot_info->snapshot_image_path);
			stringstream ss;
			ss << obj_index++;
			string resFileName = "picV/" + ss.str() + "_";

			//VC
			cout << "VC: " << resHP->vc_res.res_index << " " << colorLabel[resHP->vc_res.res_index] << " " << resHP->vc_res.res_prob << endl;
			stringstream sscolor;
			sscolor << resHP->vc_res.res_prob;
			resFileName = resFileName + colorLabel[resHP->vc_res.res_index] + "_" + sscolor.str();

			//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;

				for (int m = 0; m < 7; m++)
				{
					printf("%s", resHP->vp_res.recg[m].character);

					resFileName += resHP->vp_res.recg[m].character;
				}

				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;

			cout << endl << endl;
			resFileName += ".jpg";

			cv::imwrite(resFileName, resImg);
#endif
		}

	}
}


int framecnt = 0;
void videoRTViewCallback(void * handle, unsigned char* imageData, int imageHeight, int imageWiddth)
{
	//实时查看画面处理函数

	//--------回调函数串行运行,请勿在此做例如显示等耗时的操作,以下操作仅供测试--------//
	// cout << "currunt frame no:" << framecnt << endl;
	// cv::Mat resultImage(imageHeight, imageWiddth, CV_8UC3, imageData);
	// cv::imwrite("views/view_" + to_string(framecnt) + ".jpg", resultImage);
	framecnt += 5;
	return;
}


#include <chrono>
#include <thread>
int addTaskCount;
std::chrono::time_point<std::chrono::system_clock> beginTime;
void videoFinishCallback(void * handle, const int taskID)
{
	cout << "==============================完成任务ID: " << taskID << " ============================" << endl;
	// auto itor = cur_task_status_.find(taskID);
	// if (itor != cur_task_status_.end())
	// {
	// 	itor->second = TRUE;
	// }


	// static int finishTaskConut = 0;

	// ++finishTaskConut;
	// if (finishTaskConut >= addTaskCount)
	// {
	// 	auto endTime = std::chrono::system_clock::now();
	// 	auto costTime = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - beginTime).count();
	// 	printf("all task finish ! cost time = %d ms\n", costTime);
	// 	printf("total frame count = %d\n", framecnt);
	// 	printf("per frame cost time = %f ms \n", (float)costTime/framecnt);
	// 	printf("mean fps = %f \n",  1000.0*framecnt/costTime);
	// }
}

//操作句柄
void *handle;
static int total_index = 0;

void create_task(const char * videoFileName, int total_index) {
	//指定检测目标视频抽帧图片(保存时显存占用很大)
	char resultFolder[256];
	sprintf(resultFolder, "snapshots/res_0308/%d", total_index);
	//指定检测目标快照抠图保存路径
	char resultFolderLittle[256];
	sprintf(resultFolderLittle, "snapshots/resLittle_0308/%d", total_index);

	char resultFolderLittleface[256];
	sprintf(resultFolderLittleface, "snapshots/resLittle_face/%d", total_index);

	task_param tparam;
	strcpy(tparam.result_folder, resultFolder);
	strcpy(tparam.result_folder_little, resultFolderLittle);
	strcpy(tparam.result_folder_face, resultFolderLittleface);
	strcpy(tparam.video_filename, videoFileName);
	tparam.on_image_display = false;
	tparam.jpeg_quality = 30; //debug by zsh
	tparam.decMode = 1;  // 关键帧解码

	//tparam.video_filename = argv[total_index%4];
	memcpy(tparam.minBoxsize, m_boxsize, sizeof(sy_rect)* DETECTTYPE);
	tparam.rt_view_callback_func = videoRTViewCallback;
	tparam.obj_snapshot_callback_func = videoObjSnapshotCallback;

	for (int tmp = 0; tmp < 10; tmp ++) {
		string tmp_path = "results/" + vpt_types[tmp];
		CreateResultFolder((char*)tmp_path.c_str(), "");
	}
	
	int newTaskID = add_task(handle, tparam);
	cout << "==============================开始任务ID: " << newTaskID << " ============================" << endl;
	cur_task_status_.insert(make_pair(newTaskID, FALSE));
}

int main(int argc, char* argv[])
{
	if (argc<4)
	{
		cout << "You must input videoFileName, iAddTaskCount and gpuid." << endl;
		return -1;
	}
	const char * videoFileName = argv[1];
	addTaskCount = atoi(argv[2]);
	int gpuID = atoi(argv[3]);

	//初始化参数设置
	mvpt_param vptParam;
	// vptParam.hp_analysis_config = SY_CONFIG_CLOSE;
	// vptParam.hcp_analysis_config = SY_CONFIG_CLOSE;
	// vptParam.vehicle_analysis_config = SY_CONFIG_CLOSE;
	// vptParam.hf_recg_config = SY_CONFIG_CLOSE;
	// vptParam.hcf_recg_config = SY_CONFIG_CLOSE;
	// vptParam.vcf_recg_config = SY_CONFIG_CLOSE;
	// vptParam.face_det_config = SY_CONFIG_CLOSE;

	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.face_det_config = SY_CONFIG_OPEN;

	vptParam.vrdbpath = argv[4];
	//vptParam.vrdbpath = "../../db/mvpt.bin";
	vptParam.auth_license = "sy_va_sub_sdk_2023"; //通用授权
	vptParam.task_obj_info_callback_func = videoObjInfoCallback;
	vptParam.task_finish_callbackfunc = videoFinishCallback;
	vptParam.gpuid = gpuID;
	vptParam.wait_framecount = 30;
	vptParam.serviceID = 0;
	vptParam.limitSize = (10 << 20);
	vptParam.skip_frame = 1;
	strcat(vptParam.name, "gbrealtime");
	strcat(vptParam.path, "./log/");
	int flag = mvpt_init(&handle, vptParam);

	if (0 != flag)
	{
		printf("Init Failed! Error Code: %d\n", flag);
		system("pause");
		return 0;
	}
	beginTime = std::chrono::system_clock::now();

	printf("begin add task\n");
	do {
		if(get_running_task_number(handle) > 0){
			std::this_thread::sleep_for(std::chrono::seconds(1));
			continue;
		}

		// create_task("/home/cmhu/data/video/duan1.avi", total_index);

		// usleep(40000);

		// create_task("/home/cmhu/data/video/Street.uvf", total_index);

		for (int i = 0; i < addTaskCount; i++) {

			create_task(videoFileName, total_index);

			total_index++ ;
			
	#ifdef _MSC_VER
			Sleep(2000);
	#else
			usleep(40000);
	#endif	
		}
	} while(0) ;
	
	printf("-------------------Begin rt_view_task 1 !----------------------\n");
	rt_view_task(handle, 0);
	
	while (getchar() == 'q');
	

	/*
	pause_task(handle, 0);
	Sleep(2000);

	pause_task(handle, 1);
	Sleep(2000);

	pause_task(handle, 2);
	Sleep(2000);

	restart_task(handle, 2);
	Sleep(2000);


	printf("-------------Begin restart_task 1 !----------------\n");
	restart_task(handle, 1);
	Sleep(2000);

	restart_task(handle, 0);
	Sleep(2000);

	pause_task(handle, 1);
	Sleep(2000);

	printf("-------------Begin finish_task!----------------\n");
	finish_task(handle, 2);
	Sleep(2000);

	printf("-------------Begin restart_task 1 !----------------\n");
	restart_task(handle, 1);
	Sleep(2000);

	printf("-------------Begin pause_task 1 !----------------\n");
	pause_task(handle, 1);
	Sleep(2000);

	printf("-------------Begin restart_task 1 !----------------\n");
	restart_task(handle, 1);
	Sleep(2000);

	printf("-------------------Begin rt_view_task 1 !----------------------\n");
	rt_view_task(handle, 1);
	Sleep(200000);

	finish_view_task(handle);

	while (1)
	{
	usleep(40000);
	}
	*/

	int task_index = addTaskCount - 1;
	while (0)
	{
		for (auto itor = cur_task_status_.begin(); itor != cur_task_status_.end();)
		{
			if (itor->second)
			{
				cout << "==============================停止任务ID: " << itor->first << " ============================" << endl;

				itor = cur_task_status_.erase(itor);

				//指定检测目标视频抽帧图片(保存时显存占用很大)
				char resultFolder[256];
				sprintf(resultFolder, "res/%d", total_index);
				//指定检测目标快照抠图保存路径
				char resultFolderLittle[256];
				sprintf(resultFolderLittle, "resLittle/%d", total_index);

				char resultFolderLittleface[256];
				sprintf(resultFolderLittleface, "resLittle_face/%d", total_index++);

				task_param tparam;
				strcpy(tparam.result_folder, resultFolder);
				strcpy(tparam.result_folder_little, resultFolderLittle);
				strcpy(tparam.result_folder_face, resultFolderLittleface);
				strcpy(tparam.video_filename, videoFileName);
				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);

				cout << "==============================开始任务ID: " << newTaskID << " ============================" << endl;

				cur_task_status_.insert(make_pair(newTaskID, FALSE));
#ifdef _MSC_VER
				Sleep(2000);
#else
				usleep(40000);
#endif				
			}
			else
			{
				itor++;
			}
		}
#ifdef _MSC_VER
		Sleep(100);
#else
		usleep(2000);
#endif	
	}
	while (1)
	{
#ifdef _MSC_VER
		Sleep(100);
#else
		usleep(2000);
#endif
	}
	mvpt_release(&handle);

	return 0;
}