⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c.bak

📁 学习跟踪的好程序
💻 BAK
📖 第 1 页 / 共 5 页
字号:
	SetTimer(hwndCtl, TEST_TIMER, 1000, NULL);    /* 2-second timer */
	
	//initial display
	ImageMaxX = iio_ImageMaxX();
	ImageMaxY = iio_ImageMaxY();
	gcImgCurrent = iio_GetInputImage();
	giFrameInitial = iio_GetFrameNo();

	//set window dimension and related parameters
	AppSetDisplay();	

	//mean shift track image with half size
	gcImgCurrentHalf = cvCreateImage(cvSize(ImageMaxX/2, ImageMaxY/2), 8, 3);
	//mask image
	gImgInitMask = cvCreateImage(cvSize(ImageMaxX/2, ImageMaxY/2), 8, 1);
	//bitmap image
	gImgBitMap = cvCreateImage(cvSize(ImageMaxX, ImageMaxY), 8, 1);

	//get half image for processing
	if (gcImgCurrent!=NULL){	
		cvResize(gcImgCurrent, gcImgCurrentHalf, CV_INTER_LINEAR);
	}
	
	gBatchFlag = FALSE;
	switch(rstOpenFile) {
	case 0: 
		//do nothing if error in open file 
		break;
	case 2:
		//initialize .trk file
		giSeqType = 1; //trk
		gbReplayFlag = TRUE;
		giClickCount=4;				
		img_ProcessLClick_Poly();
		
		dis_ShowImgCurrent();

		if (DEBUG==1){
			gbReplayFlag = FALSE;
		}
		break;
	case 3: 
		//batch tracking
		gBatchFlag = TRUE;
		BatchProcess();
		break;
	default:
		//initialize image frame 
		giSeqType = 0; 
		//disalbe playLog
		Functions[8].style = BS_PUSHBUTTON|WS_DISABLED; 
		DrawButtons(hwndCtl, 0, TRUE);	

		dis_ShowImgCurrent();
	}
	
	return TRUE;
}
/*****************************************************************************
 * Name:         AppExit                                                     *
 *****************************************************************************/
void AppExit(void)
{
	//release display buffer
	ReleaseBuffer();

	if(hpalette)
		DeleteObject(hpalette);

	//release imageio buffer
	iio_Exit();

	//release cv images
	cvReleaseImage(&gcImgCurrentHalf);
	cvReleaseImage(&gImgBitMap);
	cvReleaseImage(&gImgInitMask);

	//release tracker memory	
	switch(gTrackerIndex) {
	case 2:
		//initial Meanshift Tracker
		msw_TrackCleanUp();					
		break;
	case 3:
		//template matching Tracker with Correlation
		temp_TrackCleanUp();
		break;
	default:
		//tracker 1: HistogramShift - Enhanced meanshift by Foreground/Bkground		
		his_TrackCleanUp();
	}
}
/*****************************************************************************
 * Name: AppIdle                                                             *
 *****************************************************************************/
BOOL AppIdle(void)
{
//	HDC hdc;
//	HDC hdc2;
	int waitFlag;

	// if this app is and icon, return TRUE and wait for a message
	if (IsIconic(hwndCtl))
		return TRUE;

	// if the user is leaning on the right mouse button let him have priority
	if (GetKeyState(VK_RBUTTON) >= 0)
	{
		//wait 
		//for (int i=1;i<100;i++){
			//wait();
		//}

		//get image
		waitFlag = GetImage();

		//print title		
		return waitFlag;
	}
	else
	{		
		return TRUE;      // background app; nothing to do.
	}	
}
/*****************************************************************************
 * Name: AppPaint                                                            *
 *****************************************************************************/
void AppPaint(HWND hwnd, HDC hdc)
{
	if (hpalette&&(PIXEL_TYPE==PBITS_Y8))
	{
		SelectPalette(hdc, hpalette, TRUE);
		RealizePalette(hdc);
	}

	SetDIBitsToDevice(
		hdc,
		0, ViewOffset, ImageMaxX, ImageMaxY,
		0, 0, 0, ImageMaxY,
		gpBits, (LPBITMAPINFO)&maphead, DIB_RGB_COLORS);
	
	
	if (gbClickInitFlag==FALSE) return;
	
	//draw rect
	if (gbTrackMood==TRUE){
		dis_DrawRect(hwndCtl, gRectCurrent);

		//display past tracked position
		if (DEBUG==1 || (gPosCount>2 && gbAutoPredictFlag==TRUE))
		{		
			dis_DrawTraceLine(hwndCtl, gPosPredict, gPosCount, PS_DASH, 2, RGB(255,0,0));			
		}
	}
	else{	
		dis_DrawRegion(hwnd, gRegionDisplay);
	}
}
/*****************************************************************************
 * Name: AppPaint2                                                            *
 *****************************************************************************/
void AppPaint2(HWND hwnd, HDC hdc)
{
	if (hpalette&&(PIXEL_TYPE==PBITS_Y8))
	//if (hpalette)
	{
		SelectPalette(hdc, hpalette, TRUE);
		RealizePalette(hdc);
	}

	SetDIBitsToDevice(
		hdc,
		0, ViewOffset, ImageMaxX, ImageMaxY,
		0, 0, 0, ImageMaxY,
		gpBits2, (LPBITMAPINFO)&maphead, DIB_RGB_COLORS);

	//draw rect
	if (gbTrackMood==TRUE){
		dis_DrawRect(hwnd, gRectCurrentHalf);
	}
	else{	
		if (gbReplayFlag==FALSE)
			dis_DrawRegion(hwnd, gRegionDisplayHalf);
	}
}
/*****************************************************************************
 * Name:         CtlProc                                                     *
 * Description:  Main window procedure.                                      *
 *****************************************************************************/
LONG WINAPI CtlProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	//MINMAXINFO *lpmmi;
	HDC hdc;
	PAINTSTRUCT ps;	
	int rstOpenFile;
	int clickX, clickY;
	
	switch (message)
	{
	case WM_CREATE:
		GetGlobals(hwnd, lParam);
		SetWindowPos(hwnd, NULL, 0, 0, WindowX, WindowY, SWP_NOMOVE | SWP_SHOWWINDOW | SWP_DRAWFRAME);
		return 0L;

	case WM_SIZE:	
		//size two windows together
		return 0L;

	case WM_PAINT:
		hdc = BeginPaint(hwnd,&ps);
		if (hwnd==hwndCtl)
			AppPaint(hwnd,hdc);
		else if (hwnd==hwndCtl2)
			AppPaint2(hwnd,hdc);
		EndPaint(hwnd,&ps);
		return 0L;

	case WM_TIMER:
		//if(fAcquire)
		{
			if(bTime == 0.0)
			{
				bTime = timeGetTime();
				FrameCount = 0;				
				//ErrorCount = 0;
				return 0L;
			}
			eTime = timeGetTime();
			dTime = eTime - bTime;
			iTime = dTime / CLOCKS_PER_SEC;
			if(iTime > 0)
				FPS = (int)fn_Round((double)FrameCount/iTime);				

			dis_PrintMessage();
			bTime = timeGetTime();
			FrameCount = 0;
		}
		return 0L;
	
	case WM_LBUTTONDOWN:
		if (hwnd == hwndCtl2) return 0L; //no response in debug window
		
		clickX = LOWORD(lParam);
		clickY = HIWORD(lParam);

		if (clickX>=ImageMaxX || clickY<ButtonHeight || clickY>=ImageMaxY+ButtonHeight) return 0L; //x,y out of bound
		
		//get the click point coordinate		
		gaClickPoint[giClickCount].x = LOWORD(lParam);		
		gaClickPoint[giClickCount].y = ImageMaxY-1+ButtonHeight-HIWORD(lParam); // flip the click point for bmp processing				

		giClickCount++;
		//img_ProcessLClick();
		img_ProcessLClick_Poly();

		return 0L;

	case WM_RBUTTONDOWN:		
		return 0L;

	case WM_MOUSEMOVE:		
		if (hwnd!=hwndCtl || giClickCount==0 || giClickCount>3) 
			return 0L;
		
		clickX = LOWORD(lParam);
		clickY = HIWORD(lParam);
		if (clickX>=ImageMaxX || clickY<ButtonHeight || clickY>=ImageMaxY+ButtonHeight) return 0L; //x,y out of bound
	
		img_ProcessMouseMove(LOWORD(lParam), HIWORD(lParam));		
		
		return 0L;
		
	case WM_COMMAND:
		switch(wParam)
		{
		default:
			break;

		case ID_READ:						
			giPlayFlag = 0;

			//open image file by prompt dialog
			rstOpenFile = iio_OpenFileByPrompt();
			if (rstOpenFile==0){ //canceled
				return 0;
			}

			//if no new frame, return
			if (gcImgCurrent==iio_GetInputImage() || iio_GetInputImage()==NULL){
				return 0L;
			}

			gbClickInitFlag=FALSE;
			gbTrackMood=FALSE;

			//update image			
			gcImgCurrent = iio_GetInputImage();
			ImageMaxX = iio_ImageMaxX();
			ImageMaxY = iio_ImageMaxY();
			giFrameInitial = iio_GetFrameNo();

			//HalfSize track image
			cvReleaseImage(&gcImgCurrentHalf);
			gcImgCurrentHalf = cvCreateImage(cvSize(ImageMaxX/2, ImageMaxY/2), 8, 3);
			if (gcImgCurrent!=NULL){			
				cvResize(gcImgCurrent, gcImgCurrentHalf, CV_INTER_LINEAR);
			}

			//mask image
			cvReleaseImage(&gImgInitMask);
			gImgInitMask = cvCreateImage(cvSize(ImageMaxX/2, ImageMaxY/2), 8, 1);
			//bitmap image
			cvReleaseImage(&gImgBitMap);
			gImgBitMap = cvCreateImage(cvSize(ImageMaxX, ImageMaxY), 8, 1);

			//resize display window
			AppSetDisplay();
			
			//display current image
			dis_ShowImgCurrent();

			//reset predict
			gbPredictFlag = FALSE;			
			gPosCount = 0;

			//initilize track for different file type
			switch(rstOpenFile) {
			case 2:
				//create click region if opened a track file
				giSeqType = 1; //trk
				gbReplayFlag = TRUE;
				if (DEBUG==1) gbReplayFlag = FALSE;
				giClickCount=4;				
				img_ProcessLClick_Poly();
				//Functions[7].style = BS_PUSHBUTTON|WS_DISABLED; //disable log
				Functions[8].style = BS_PUSHBUTTON; //enable playLog

				break;
			case 3:
				break;
			default:
				//initialize image frame file
				giSeqType =0;
				gbReplayFlag = FALSE;
				Functions[9].style = BS_PUSHBUTTON|WS_DISABLED; //disalbe playLog
			}			

			return 0L;

		case ID_BROWSEBACK:
			//browse back
			giPlayFlag = 2; 

			//clear track box in tracking
			if (gbReplayFlag==FALSE){			
				gbClickInitFlag = FALSE;
				gbTrackMood=FALSE;
			}
			
			return 0L;

		case ID_TRACKFWD:
			//track forward	
			giPlayFlag = 1; 
			gbTrackMood=TRUE;

			return 0L;

		case ID_STEPFWD:
			giPlayFlag = 0;
			gbTrackMood=TRUE;
			
			//step to next frame	
			img_StepOneFrame(iio_GetFrameNo()+1);			

			return 0L;

		case ID_STOP:
			giPlayFlag = 0;		
			//gbTrackMood=FALSE;
			return 0L;

		case ID_REWIND:				
			img_RewindVideo();
			gbTrackMood=FALSE;
			
			return 0L;

		case ID_PLAYLOG:
			if (giSeqType!=1){ //if not trk file
				return 0L;
			}
			//only work in trk sequence 

			//rewind to intial frame
			giPlayFlag = 0;	
			gbTrackMood=FALSE;
			img_StepOneFrame(giFrameInitial);				

			gbReplayFlag = !gbReplayFlag;
			if (gbReplayFlag==FALSE){				
				//Functions[8].text = "PlayLog"; 
				//update flags				

				//create click region if opened a track file
				giClickCount=4;				
				img_ProcessLClick_Poly();
			}
			else{ 
				//Replay Log files is true	
				gbClickInitFlag = TRUE;
				img_RewindVideo();				
			}

			return 0L;
			
		case ID_KLT:
			gbKltFlag = !gbKltFlag;	
			if (gbKltFlag==TRUE){
				Functions[10].style = BS_PUSHBUTTON; //enable predict
			}
			else{
				gbAutoPredictFlag = FALSE;
				Functions[10].style = BS_PUSHBUTTON|WS_DISABLED; //disalbe predict
			}
			DrawButtons(hwndCtl, 0, TRUE);
			DrawButtons2(hwndCtl2, 0, TRUE);

			return 0L;

		case ID_LOG:						
			if (gbLogFlag==TRUE){	
				//turn off log flag
				gbLogFlag = FALSE;
				return 0L;
			}
			else{
				//turn on Log flag
				gbLogFlag = TRUE;

				//rewind video
				giPlayFlag = 0;
				gbTrackMood=FALSE;

				//reset track Rect
				gRectCurrent = gRectInit;			
				
				//rewind to intial frame
				img_StepOneFrame(giFrameInitial);								
				

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -