VPTTest.cppthread2 22 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
#include <vector>
#include <iostream>
#include <fstream>
#include <time.h>
#ifdef _MSC_VER
#include "../VPT/VPT.h"
#include <windows.h>
#include <cv.h>
#include <highgui.h>
#include <opencv2/opencv.hpp>
#else
#include "VPT.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif
//#include "../VPT/header.h"

#ifndef _MSC_VER
#include<time.h>
#include <sys/time.h>
#include <unistd.h>
#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(&macro_tv_start_##name,NULL);
#define MACRO_COUNT_TIME_END(name,___total_count___) gettimeofday(&macro_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->video_id << " " << 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

void *pthread_1(void *arg)
{
   //字体初始化
	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;

	
	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 = 3;
	vparam.maxResultCount = maxResultCount;        //限制算法内部输出的最大前景个数
	vparam.SnaoshotParameter = &ssparam;
#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;
	}



	int batchsize = 5;
	double totalTime = 0.0;
	string videos[10] = { "qst.avi", "qst.avi", "qst.avi", "qst.avi", "ruijin.avi", "test2.mp4", "151624-vv-1.avi", "qst.avi", "qst.avi" ,"qst.avi"};
	//其他变量
	Mat img[batchsize];
	VideoCapture cap[batchsize];
	VideoWriter writer[batchsize];
	ofstream file("res.txt");
	for (int b = 0; b < batchsize; b++)
	{
		cap[b].open(videos[b]);
		cap[b].read(img[b]);
		std::string save_path = "result_" + to_string(b) + ".avi"; 
		writer[b].open(save_path, CV_FOURCC('D', 'I', 'V', 'X'), 25.0, Size(img[b].cols, img[b].rows));
	}
	

	//结果变量
	VPT_Result *batch_result = new VPT_Result[batchsize];
	for (int b = 0; b < batchsize; b++)
	{
		batch_result[b].objCount = 0;
		batch_result[b].obj = new VPT_ObjInfo[maxResultCount]; //设置外部接收结果的最大前景个数
	}

	int start = 0;
	int start_ = 0;
	for (int b = 0; b < batchsize; b++)
	{
		cap[b].set(CV_CAP_PROP_POS_FRAMES, start_);
		start_ += 80;
	}

	while (frameCount < 800) {
		cout << "---------------- " << frameCount << " -----------------" << endl;
		if(frameCount == 200) batchsize = 3; ///////
		if(frameCount == 400) batchsize = 2; ///////
		if(frameCount == 600) batchsize = 4; ///////
		xjs_batch_img *batch_img = new xjs_batch_img[batchsize];
		start++;
		for (int b = 0; b < batchsize; b++)
		{
			if(cap[b].read(img[b])) {
				// cv::Mat tmp_img = img.clone();
				std::string video_key = "task_" + to_string(b);
				if(frameCount == 200 && b == 2) video_key = "taskx_" + to_string(b); /////
				// std:cout << "video_key:" << video_key << std::endl;
				batch_img[b].set_data(img[b].cols, img[b].rows, img[b].channels(), img[b].data, video_key, frameCount);
			}	
		}
#ifdef _MSC_VER
		QueryPerformanceCounter(&nBeginTime);
#else
		MACRO_COUNT_TIME_START(VPT_Process_batch);
#endif
		VPT_Process_batch(tools, batch_img, batchsize, &batch_result, true);
#ifdef _MSC_VER
		QueryPerformanceCounter(&nEndTime);
		totalTime += (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart;
		printf("Total Time: %.2fms  \n", (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart);
#else
		MACRO_COUNT_TIME_END(VPT_Process_batch, 1);
#endif
		for (int b = 0; b < batchsize; b++) {
			for (int c = 0; c < batch_result[b].objCount; c++)
			{
				char str_i[100];
				sprintf(str_i, "%d_%.2f", batch_result[b].obj[c].id, batch_result[b].obj[c].confidence);
				int colorIndex = batch_result[b].obj[c].index;

				file << start << " " << batch_img[b].video_key_ << " " << batch_result[b].obj[c].id << " " << batch_result[b].obj[c].index << " " << batch_result[b].obj[c].left << " " <<
					batch_result[b].obj[c].top << " " << batch_result[b].obj[c].right << " " << batch_result[b].obj[c].bottom << endl;

				rectangle(img[b], cvPoint(batch_result[b].obj[c].left - 5, batch_result[b].obj[c].top - 15), cvPoint(batch_result[b].obj[c].right + 5, batch_result[b].obj[c].bottom + 10), cv::Scalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), 3, 1);
				cv::putText(img[b], str_i, cv::Point(batch_result[b].obj[c].left, batch_result[b].obj[c].top), fontFace, fontScale, cv::Scalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), thickness, 8);
			}
			cv::resize(img[b], imgResized, cv::Size(1280, 720));
			writer[b] << img[b];

		}
		
		img_show = true;
		frameCount++;
		if (batch_img != nullptr) {
			delete[] batch_img;
			batch_img = nullptr;
		}

	}

	cout << "AVG TIME: " << totalTime / 5000 << endl;

	//释放
	show = false;
	for (int b = 0; b < batchsize; b++)
	{
		delete[] batch_result[b].obj; 
		cap[b].release();
		writer[b].release();
	}
	delete[] batch_result; 

	VPT_Release(&tools);


#ifdef _MSC_VER
	system("pause");
#endif
	//return 0;
}

void *pthread_2(void *arg)
{
   //字体初始化
	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;

	
	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 = 2;
	vparam.maxResultCount = maxResultCount;        //限制算法内部输出的最大前景个数
	vparam.SnaoshotParameter = &ssparam;
#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;
	}



	int batchsize = 5;
	double totalTime = 0.0;
	string videos[10] = { "qst.avi", "qst.avi", "qst.avi", "qst.avi", "ruijin.avi", "test2.mp4", "151624-vv-1.avi", "qst.avi", "qst.avi" ,"qst.avi"};
	//其他变量
	Mat img[batchsize];
	VideoCapture cap[batchsize];
	VideoWriter writer[batchsize];
	ofstream file("res.txt");
	for (int b = 0; b < batchsize; b++)
	{
		cap[b].open(videos[b]);
		cap[b].read(img[b]);
		std::string save_path = "result2_" + to_string(b) + ".avi"; 
		writer[b].open(save_path, CV_FOURCC('D', 'I', 'V', 'X'), 25.0, Size(img[b].cols, img[b].rows));
	}
	

	//结果变量
	VPT_Result *batch_result = new VPT_Result[batchsize];
	for (int b = 0; b < batchsize; b++)
	{
		batch_result[b].objCount = 0;
		batch_result[b].obj = new VPT_ObjInfo[maxResultCount]; //设置外部接收结果的最大前景个数
	}

	int start = 0;
	int start_ = 0;
	for (int b = 0; b < batchsize; b++)
	{
		cap[b].set(CV_CAP_PROP_POS_FRAMES, start_);
		start_ += 80;
	}

	while (frameCount < 800) {
		cout << "---------------- " << frameCount << " -----------------" << endl;
		if(frameCount == 200) batchsize = 3; ///////
		if(frameCount == 400) batchsize = 2; ///////
		if(frameCount == 600) batchsize = 4; ///////
		xjs_batch_img *batch_img = new xjs_batch_img[batchsize];
		start++;
		for (int b = 0; b < batchsize; b++)
		{
			if(cap[b].read(img[b])) {
				// cv::Mat tmp_img = img.clone();
				std::string video_key = "task2_" + to_string(b);
				if(frameCount == 200 && b == 2) video_key = "task2x_" + to_string(b); /////
				// std:cout << "video_key:" << video_key << std::endl;
				batch_img[b].set_data(img[b].cols, img[b].rows, img[b].channels(), img[b].data, video_key, frameCount);
			}	
		}
#ifdef _MSC_VER
		QueryPerformanceCounter(&nBeginTime);
#else
		MACRO_COUNT_TIME_START(VPT_Process_batch);
#endif
		VPT_Process_batch(tools, batch_img, batchsize, &batch_result, true);
#ifdef _MSC_VER
		QueryPerformanceCounter(&nEndTime);
		totalTime += (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart;
		printf("Total Time: %.2fms  \n", (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart);
#else
		MACRO_COUNT_TIME_END(VPT_Process_batch, 1);
#endif
		for (int b = 0; b < batchsize; b++) {
			for (int c = 0; c < batch_result[b].objCount; c++)
			{
				char str_i[100];
				sprintf(str_i, "%d_%.2f", batch_result[b].obj[c].id, batch_result[b].obj[c].confidence);
				int colorIndex = batch_result[b].obj[c].index;

				file << start << " " << batch_img[b].video_key_ << " " << batch_result[b].obj[c].id << " " << batch_result[b].obj[c].index << " " << batch_result[b].obj[c].left << " " <<
					batch_result[b].obj[c].top << " " << batch_result[b].obj[c].right << " " << batch_result[b].obj[c].bottom << endl;

				rectangle(img[b], cvPoint(batch_result[b].obj[c].left - 5, batch_result[b].obj[c].top - 15), cvPoint(batch_result[b].obj[c].right + 5, batch_result[b].obj[c].bottom + 10), cv::Scalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), 3, 1);
				cv::putText(img[b], str_i, cv::Point(batch_result[b].obj[c].left, batch_result[b].obj[c].top), fontFace, fontScale, cv::Scalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), thickness, 8);
			}
			cv::resize(img[b], imgResized, cv::Size(1280, 720));
			writer[b] << img[b];

		}
		
		img_show = true;
		frameCount++;
		if (batch_img != nullptr) {
			delete[] batch_img;
			batch_img = nullptr;
		}

	}

	cout << "AVG TIME: " << totalTime / 5000 << endl;

	//释放
	show = false;
	for (int b = 0; b < batchsize; b++)
	{
		delete[] batch_result[b].obj; 
		cap[b].release();
		writer[b].release();
	}
	delete[] batch_result; 

	VPT_Release(&tools);


#ifdef _MSC_VER
	system("pause");
#endif
	//return 0;
}


int main(int argc, char** argv)
{
	int iter = 2;
	while(iter--)
	{
		pthread_t tid1;//定义子线程标识符
		pthread_create(&tid1,NULL,pthread_1,NULL);//pthread_1即线程执行函数
		printf("child pthread1 create\n");
		
		pthread_t tid2;//定义子线程标识符
		pthread_create(&tid2,NULL,pthread_2,NULL);//pthread_1即线程执行函数
		printf("child pthread2 create\n");
		
		pthread_t tid3;//定义子线程标识符
		pthread_create(&tid3,NULL,pthread_1,NULL);//pthread_1即线程执行函数
		printf("child pthread3 create\n");
		
		pthread_join(tid1,NULL);
		printf("child pthread1 exit\n");
			
		pthread_join(tid2,NULL);
		printf("child pthread2 exit\n");
			
		pthread_join(tid3,NULL);
		printf("child pthread3 exit\n");
	}

	printf("\n all finish \n");
	return 0;
	
	
if(0) {
	
	
	//字体初始化
	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;
	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 = atoi(argv[2]);// 0;
	vparam.thres = 0.5;
	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;
	}

#if 0
	//其他变量
	Mat img;
	VideoCapture cap;
#ifdef _MSC_VER
	cap.open(argv[1]);
#else
	cap.open("qst.avi");
	//cap.open(argv[1]);
#endif
	cap.read(img);
	VideoWriter writer("result.avi", CV_FOURCC('D', 'I', 'V', 'X'), 25.0, Size(img.cols, img.rows));
	
	
	//结果变量
	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;
	cap.set(CV_CAP_PROP_POS_FRAMES, start);

	double totalTime = 0.0;
	//检测

	ofstream file("res.txt");

	while (cap.read(img) && frameCount < 80)
	{
		start++;
		cout << "---------------- " << frameCount << " -----------------" << endl;

#ifdef _MSC_VER
		QueryPerformanceCounter(&nBeginTime);
#else
		MACRO_COUNT_TIME_START(vpt_process);
#endif
		VPT_Process(tools, img.data, img.cols, img.rows, img.channels(), frameCount, &result, true);

#ifdef _MSC_VER
		QueryPerformanceCounter(&nEndTime);
		totalTime += (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart;
		printf("Total Time: %.2fms  \n", (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart);
#else
		MACRO_COUNT_TIME_END(vpt_process, 1);
#endif
		for (int c = 0; c < result.objCount; c++)
		{
			char str_i[100];

			sprintf(str_i, "%d_%.2f", result.obj[c].id, result.obj[c].confidence);
			int colorIndex = result.obj[c].index;


			file << start << " " << result.obj[c].id << " " << result.obj[c].index << " " << result.obj[c].left << " " <<
				result.obj[c].top << " " << result.obj[c].right << " " << result.obj[c].bottom << endl;

			rectangle(img, cvPoint(result.obj[c].left - 5, result.obj[c].top - 15), cvPoint(result.obj[c].right + 5, result.obj[c].bottom + 10), cv::Scalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), 3, 1);
			cv::putText(img, str_i, cv::Point(result.obj[c].left, result.obj[c].top), fontFace, fontScale, cv::Scalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), thickness, 8);
		}

		cv::resize(img, imgResized, cv::Size(1280, 720));
		writer << img;
		img_show = true;
		frameCount++;
	}
	cout << "AVG TIME: " << totalTime / 5000 << endl;

	//释放
	show = false;
	delete[] result.obj; 
#else
	
	int batchsize = 10;
	double totalTime = 0.0;
	string videos[10] = { "qst.avi", "qst.avi", "qst.avi", "qst.avi", "ruijin.avi", "test2.mp4", "151624-vv-1.avi", "qst.avi", "qst.avi" ,"qst.avi"};
	//其他变量
	Mat img[batchsize];
	VideoCapture cap[batchsize];
	VideoWriter writer[batchsize];
	ofstream file("res.txt");
	for (int b = 0; b < batchsize; b++)
	{
		cap[b].open(videos[b]);
		cap[b].read(img[b]);
		std::string save_path = "result_" + to_string(b) + ".avi"; 
		writer[b].open(save_path, CV_FOURCC('D', 'I', 'V', 'X'), 25.0, Size(img[b].cols, img[b].rows));
	}
	

	//结果变量
	VPT_Result *batch_result = new VPT_Result[batchsize];
	for (int b = 0; b < batchsize; b++)
	{
		batch_result[b].objCount = 0;
		batch_result[b].obj = new VPT_ObjInfo[maxResultCount]; //设置外部接收结果的最大前景个数
	}

	int start = 0;
	int start_ = 0;
	for (int b = 0; b < batchsize; b++)
	{
		cap[b].set(CV_CAP_PROP_POS_FRAMES, start_);
		start_ += 80;
	}

	while (frameCount < 100) {
		cout << "---------------- " << frameCount << " -----------------" << endl;
		if(frameCount == 200) batchsize = 3; ///////
		if(frameCount == 400) batchsize = 2; ///////
		if(frameCount == 600) batchsize = 4; ///////
		xjs_batch_img *batch_img = new xjs_batch_img[batchsize];
		start++;
		for (int b = 0; b < batchsize; b++)
		{
			if(cap[b].read(img[b])) {
				// cv::Mat tmp_img = img.clone();
				std::string video_key = "task_" + to_string(b);
				if(frameCount == 200 && b == 2) video_key = "taskx_" + to_string(b); /////
				// std:cout << "video_key:" << video_key << std::endl;
				batch_img[b].set_data(img[b].cols, img[b].rows, img[b].channels(), img[b].data, video_key, frameCount);
			}	
		}
#ifdef _MSC_VER
		QueryPerformanceCounter(&nBeginTime);
#else
		MACRO_COUNT_TIME_START(VPT_Process_batch);
#endif
		VPT_Process_batch(tools, batch_img, batchsize, &batch_result, true);
#ifdef _MSC_VER
		QueryPerformanceCounter(&nEndTime);
		totalTime += (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart;
		printf("Total Time: %.2fms  \n", (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart);
#else
		MACRO_COUNT_TIME_END(VPT_Process_batch, 1);
#endif
		for (int b = 0; b < batchsize; b++) {
			for (int c = 0; c < batch_result[b].objCount; c++)
			{
				char str_i[100];
				sprintf(str_i, "%d_%.2f", batch_result[b].obj[c].id, batch_result[b].obj[c].confidence);
				int colorIndex = batch_result[b].obj[c].index;

				file << start << " " << batch_img[b].video_key_ << " " << batch_result[b].obj[c].id << " " << batch_result[b].obj[c].index << " " << batch_result[b].obj[c].left << " " <<
					batch_result[b].obj[c].top << " " << batch_result[b].obj[c].right << " " << batch_result[b].obj[c].bottom << endl;

				rectangle(img[b], cvPoint(batch_result[b].obj[c].left - 5, batch_result[b].obj[c].top - 15), cvPoint(batch_result[b].obj[c].right + 5, batch_result[b].obj[c].bottom + 10), cv::Scalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), 3, 1);
				cv::putText(img[b], str_i, cv::Point(batch_result[b].obj[c].left, batch_result[b].obj[c].top), fontFace, fontScale, cv::Scalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), thickness, 8);
			}
			cv::resize(img[b], imgResized, cv::Size(1280, 720));
			writer[b] << img[b];

		}
		
		img_show = true;
		frameCount++;
		if (batch_img != nullptr) {
			delete[] batch_img;
			batch_img = nullptr;
		}

	}

	cout << "AVG TIME: " << totalTime / 5000 << endl;

	//释放
	show = false;
	for (int b = 0; b < batchsize; b++)
	{
		delete[] batch_result[b].obj; 
		cap[b].release();
		writer[b].release();
	}
	delete[] batch_result; 
#endif	

	VPT_Release(&tools);

	return 0; }
}