📄 main.c.bak
字号:
memset(gpBits2, 0, ImageMaxX*ImageMaxY*3);
//display half image
if (gbClickInitFlag==TRUE && gcImgCurrentHalf!=NULL){
roi.x = 0;
roi.y = ImageMaxY/2;
roi.width = gcImgCurrentHalf->width;
roi.height = gcImgCurrentHalf->height;
cvSetImageROI(gImgDisplayDebug, roi);
cvCopy(gcImgCurrentHalf, gImgDisplayDebug, NULL);
}
//display klt features image
if (gbKltFlag==TRUE)
{
IplImage *imgFeature = klt_GetFeatureImage();
if (gbClickInitFlag==TRUE && gbTrackMood==TRUE && imgFeature!=NULL){
roi.x = ImageMaxX/2;
roi.y = ImageMaxY/2;
roi.width = gcImgCurrentHalf->width;
roi.height = gcImgCurrentHalf->height;
cvSetImageROI(gImgDisplayDebug, roi);
cvCopy(imgFeature, gImgDisplayDebug, NULL);
}
}
//display foreground image
{
IplImage *imgForeground = gTkResult.FGImage;
//if (gbClickInitFlag==TRUE && gbTrackMood==TRUE && imgForeground!=NULL){
if (gbClickInitFlag==TRUE && imgForeground!=NULL){
roi.x = 0;
roi.y = 0;
roi.width = gcImgCurrentHalf->width;
roi.height = gcImgCurrentHalf->height;
cvSetImageROI(gImgDisplayDebug, roi);
cvSetImageCOI(gImgDisplayDebug, 2);
cvCopy(imgForeground, gImgDisplayDebug, NULL);
cvSetImageCOI(gImgDisplayDebug, 0);
}
}
//paint image
AppPaint2(hwndCtl2, GetDC(hwndCtl2));
}
///////////////////////////////////////////////////////////////////////////////
void dis_DrawRect(HWND hwnd, RECT rect)
//display current rect in main window
{
HDC hdc;
// LOGBRUSH lb;
HPEN hPen, hPenOld;
//display rect track window
if (gbClickInitFlag==FALSE) return;
hdc = GetDC(hwnd);
// // Initialize the pen's brush.
// lb.lbStyle = BS_SOLID;
// lb.lbColor = RGB(255,0,0);
// lb.lbHatch = 0;
// define new pen
//hPen = ExtCreatePen(PS_COSMETIC | PS_SOLID, 1, &lb, 0, NULL);
hPen = CreatePen(PS_SOLID, giPenWidth, crPenColor);
hPenOld = SelectObject(hdc, hPen);
//flip back rect for display purpose
rect.top = ImageMaxY + ButtonHeight - rect.top;
rect.bottom = ImageMaxY + ButtonHeight - rect.bottom;
//if the rect buttom is in Button Area, ignore it.
if(rect.bottom<=ButtonHeight) rect.bottom = ButtonHeight+1;
//draw rect
MoveToEx(hdc, rect.left, rect.top, NULL);
LineTo(hdc, rect.right, rect.top);
LineTo(hdc, rect.right, rect.bottom);
LineTo(hdc, rect.left, rect.bottom);
LineTo(hdc, rect.left, rect.top);
//recover old pen
SelectObject(hdc, hPenOld);
DeleteObject(hPen);
//release Device Context
ReleaseDC(hwnd, hdc);
}
///////////////////////////////////////////////////////////////////////////////
void dis_DrawTraceLine(HWND hwnd, FPOINT* pts, int ptCount, int penStyle, int penWidth, COLORREF penColor)
//display current rect in main window
{
HDC hdc;
// LOGBRUSH lb;
HPEN hPen, hPenOld;
int i;
POINT predictPt;
int frameNum=(int)(gEffectNum*0.6); //predict ahead number of frames;
//display rect track window
if (gbClickInitFlag==FALSE) return;
hdc = GetDC(hwnd);
// define new pen
//hPen = ExtCreatePen(PS_COSMETIC | PS_SOLID, 1, &lb, 0, NULL);
hPen = CreatePen(penStyle, penWidth, penColor);
hPenOld = SelectObject(hdc, hPen);
//draw history line in red
MoveToEx(hdc, gPosDraw[0].x, gPosDraw[0].y, NULL);
for (i=1;i<ptCount;i++){
LineTo(hdc, gPosDraw[i].x, gPosDraw[i].y);
}
if (gbPredictFlag==TRUE)
{
//display predict mood
RECT promptArea;
promptArea.left = 30;
promptArea.top = ButtonHeight+20;
promptArea.right = promptArea.left + 100;
promptArea.bottom = promptArea.top + 100;
DrawText(hdc, "Predict Motion", 14, &promptArea, DT_LEFT);
//predict line in green
hPen = CreatePen(penStyle, penWidth, RGB(0,255,0));
SelectObject(hdc, hPen);
MoveToEx(hdc, gPosDraw[0].x, gPosDraw[0].y, NULL);
for(i=1;i<frameNum;i++){
predictPt.x = gPosDraw[0].x + (int)fn_Round(i*gAvgDx);
predictPt.y = gPosDraw[0].y - (int)fn_Round(i*gAvgDy);
//draw the point if it is not in button area
if(predictPt.y>ButtonHeight&&predictPt.x<ImageMaxX)
LineTo(hdc, predictPt.x, predictPt.y);
}
}
//recover old pen
SelectObject(hdc, hPenOld);
DeleteObject(hPen);
//release Device Context
ReleaseDC(hwnd, hdc);
}
///////////////////////////////////////////////////////////////////////////////
void img_ProcessLClick_Poly()
//Process after click
{
int i;
gbClickInitFlag=FALSE;
gbTrackMood=FALSE;
if (giClickCount<4){
return;
}
//calculate other points
for(i=0;i<4;i++){
gaClickPointDisplay[i].x = gaClickPoint[i].x;
gaClickPointDisplay[i].y = ImageMaxY+ButtonHeight-gaClickPoint[i].y;
gaClickPointHalf[i].x = gaClickPoint[i].x/2;
gaClickPointHalf[i].y = gaClickPoint[i].y/2;
gaClickPointHalfDisplay[i].x = gaClickPointHalf[i].x;
gaClickPointHalfDisplay[i].y = ImageMaxY+ButtonHeight-gaClickPointHalf[i].y;
}
//initilize/update rec region
gRegionCurrent = CreatePolygonRgn(gaClickPoint, giClickCount, WINDING);
gRegionCurrentHalf = CreatePolygonRgn(gaClickPointHalf, giClickCount, WINDING);
gRegionDisplay = CreatePolygonRgn(gaClickPointDisplay, giClickCount, WINDING);
gRegionDisplayHalf = CreatePolygonRgn(gaClickPointHalfDisplay, giClickCount, WINDING);
//reInit frameNo
giFrameInitial = iio_GetFrameNo();
//reset count
giClickCount=0;
//initialize tracker
gbClickInitFlag=TRUE;
GetRgnBox(gRegionCurrent, &gRectInit);
gRectCurrent.left = gRectInit.left;
gRectCurrent.top = gRectInit.top;
gRectCurrent.right = gRectInit.right;
gRectCurrent.bottom = gRectInit.bottom;
//tracking on half image
gRectCurrentHalf.left = gRectCurrent.left/2;
gRectCurrentHalf.top = gRectCurrent.top/2;
gRectCurrentHalf.right = gRectCurrent.right/2;
gRectCurrentHalf.bottom = gRectCurrent.bottom/2;
gBlobWidthInit = gRectCurrentHalf.right-gRectCurrentHalf.left;
gBlobHeightInit = gRectCurrentHalf.bottom - gRectCurrentHalf.top;
gBlobWidth = gBlobWidthInit;
gBlobHeight = gBlobHeightInit;
//create region mask image, 1 within region and 0 outside region.
img_CreateRegionMask(gRegionCurrentHalf, gImgInitMask);
//Inititilize tracker
switch(gTrackerIndex) {
case 2:
//initial Meanshift Tracker
msw_TrackInit(gcImgCurrentHalf,gImgInitMask, gRectCurrentHalf);
//msw_PrintHistogram("result/modelhist_rect.txt");
break;
case 3:
//template matching Tracker with Correlation
temp_TrackInit_Coeff(gcImgCurrentHalf, gImgInitMask, gRectCurrentHalf);
break;
default:
//tracker 1: HistogramShift - Enhanced meanshift by Foreground/Bkground
//readin customized bin number
//his_ReadHistBinsFromFile();
//initial HistogramShift Tracker
//his_TrackInit(gcImgCurrentHalf, gImgInitMask, gRectCurrentHalf);
his_TrackInit_Bins(gcImgCurrentHalf, gImgInitMask, gRectCurrentHalf, gRbins, gGbins, gBbins);
}
gTkResult.FGImage = NULL;
//initial klt tracker
klt_TrackInit(gcImgCurrentHalf);
//display rect
dis_ShowImgCurrent();
//prompt log dir name
if (gbLogFlag==TRUE && gBatchFlag==FALSE){
if (dlg_LogDir()==TRUE)
{
//flag to build sub-directory for report log
gLogDirFlag = TRUE;
}
else{
//cancel log command
gbLogFlag=FALSE;
}
}
//init variable
strcpy(gClickFrameTitle, iio_GetFileTitle());
strcpy(gLastFramePath, iio_GetFilePath());
//update the blob pos array
gPosPredict[0].x = (float)(gRectCurrent.left+gRectCurrent.right)/2;
gPosPredict[0].y = (float)(gRectCurrent.top+gRectCurrent.bottom)/2;
gPosCount=1;
//init zoom acumulative variable
gZoomAccum = 1;
}
///////////////////////////////////////////////////////////////////////////////
void img_ProcessMouseMove(long x, long y)
//Process after click
{
int i;
HDC hdc;
HPEN hpen;
//repaint image
AppPaint(hwndCtl, GetDC(hwndCtl));
hdc = GetDC(hwndCtl);
hpen = CreatePen(PS_SOLID, giPenWidth, crPenColor);
SelectObject(hdc, hpen);
//flip points for display purpose
for (i=0; i<giClickCount;i++){
if (i==0)
MoveToEx(hdc, gaClickPoint[0].x, ImageMaxY+ButtonHeight-gaClickPoint[0].y, NULL);
else
LineTo(hdc, gaClickPoint[i].x, ImageMaxY+ButtonHeight-gaClickPoint[i].y);
}
//hpen = CreatePen(PS_DOT, 1, RGB(255, 0, 0));
//SelectObject(hdc, hpen);
LineTo(hdc, x, y);
if (giClickCount>=3){
LineTo(hdc, gaClickPoint[0].x, ImageMaxY+ButtonHeight-gaClickPoint[0].y);
}
//release Device Context
ReleaseDC(hwndCtl, hdc);
}
///////////////////////////////////////////////////////////////////////////////
void dis_DrawRegion(HWND hwnd, HRGN hRegion)
//display current rect in main window
{
HBRUSH hRrush;
BOOL bResult;
//display track region
if (gbClickInitFlag==FALSE) return;
hRrush = CreateSolidBrush(crPenColor);
bResult = FrameRgn(GetDC(hwnd), hRegion, hRrush, giPenWidth,1);
}
///////////////////////////////////////////////////////////////////////////////
void io_PrintReport()
//Print track report
{
FILE *fileout;
int row, col;
BYTE pixel, threshold;
double maxVal=0;
//build log directory on first entry
if (gLogDirFlag==TRUE){
gLogDirFlag = FALSE;
//log clicked region in .trk file for repeat the same track
_mkdir(gLogDir);
strcpy(gLogFile, gLogDir);
strcat(gLogFile, "\\");
strcat(gLogFile, gClickFrameTitle);
gLogFile[strlen(gLogFile)-4] = '\0'; //get rid of suffix
strcat(gLogFile, ".trk");
fileout = fopen(gLogFile, "w");
fprintf(fileout, "%s\n", gLastFramePath);
fprintf(fileout, "%d %d\n", gaClickPoint[0].x, gaClickPoint[0].y);
fprintf(fileout, "%d %d\n", gaClickPoint[1].x, gaClickPoint[1].y);
fprintf(fileout, "%d %d\n", gaClickPoint[2].x, gaClickPoint[2].y);
fprintf(fileout, "%d %d\n", gaClickPoint[3].x, gaClickPoint[3].y);
fclose(fileout);
}
//write rpt file
if (1){
//get log file name
strcpy(gLogFile, gLogDir);
strcat(gLogFile, "\\");
strcat(gLogFile, iio_GetFileTitle());
gLogFile[strlen(gLogFile)-4] = '\0'; //get rid of suffix
strcat(gLogFile, ".rpt");
//create/open log file
fileout = fopen(gLogFile, "w");
//write report data
fprintf(fileout, "%d\n", (long)tReport.time);
fprintf(fileout, "%s\n", gLastFramePath);
fprintf(fileout, "%s\n", tReport.framePath);
fprintf(fileout, "unknown_xvel\n");
fprintf(fileout, "unknown_yvel\n");
fprintf(fileout, "unknown_azimuth\n");
fprintf(fileout, "unknown_grazing\n");
fprintf(fileout, "unknown_res\n");
fprintf(fileout, "%d\n", tReport.boxX);
fprintf(fileout, "%d\n", tReport.boxY);
fprintf(fileout, "%d\n", tReport.boxWid);
fprintf(fileout, "%d\n", tReport.boxHgt);
//write bitmap
cvMinMaxLoc(gImgBitMap, NULL, &maxVal, NULL, NULL, NULL);
threshold = max(25, (int)(0.1*maxVal));
for (row=tReport.boxY+tReport.boxHgt; row>tReport.boxY; row--){
for (col=tReport.boxX; col<tReport.boxX+tReport.boxWid; col++){
pixel = (BYTE)cvGetReal2D(gImgBitMap,row,col);
//fprintf(fileout, "%3d ", pixel);
if (pixel > threshold)
fprintf(fileout, "1 ");
else
fprintf(fileout, "0 ");
}
fprintf(fileout, "\n");
}
//write affine matrix
fprintf(fileout, "%.10f %.10f %.10f\n", gAffineMatrix[0],gAffineMatrix[1],2*gAffineMatrix[2]);
fprintf(fileout, "%.10f %.10f %.10f\n", gAffineMatrix[3],gAffineMatrix[4],2*gAffineMatrix[5]);
//write image size
fprintf(fileout, "%d\n", tReport.imgWidth);
fprintf(fileout, "%d\n", tReport.imgHeight);
//close log file
fclose(fileout);
}
//update last fraem path
strcpy(gLastFramePath, tReport.framePath);
}
///////////////////////////////////////////////////////////////////////////////
void io_CalcLogDirName(char* outLogDirName)
//get the path of log directory based on video sequence dir name
{
int i; //loop index
char index[10];
char sBufferPath[_MAX_PATH];
char sLogDirPath[_MAX_PATH];
char DirName[30];
char *sFramePath;
//get exe path+"tklog"
strcpy(sLogDirPath, gExeLogPath);
strcat(sLogDirPath, "\\");
//get video dir name
sFramePath = iio_GetFilePath();
iio_CalcFrameDir(sFramePath, DirName);
strcpy(outLogDirName, DirName);
strcat(outLogDirName, "_");
strcat(sLogDirPath, outLogDirName);
//get index
strcpy(sBufferPath, sLogDirPath);
for (i=1;i<=10000;i++){
itoa(i, index, 10);
strcat(sBufferPath, index);
if (_chdir(sBufferPath) != 0){ //directory not exist
//return dir path and name
strcat(outLogDirName, index);
break;
}
else{//directory exist
//backup buffer
strcpy(sBufferPath, sLogDirPath);
}
}
}
///////////////////////////////////////////////////////////////////////////////
int img_PredictMotion()
//Function: predict motion;
//Input: gPosPredict array; gPosCount
//output: gAvgDx; gAvgDy;
{
float dx, dy;
float sumDx=0, sumDy=0;
int i;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -