aboutsummaryrefslogtreecommitdiff
path: root/blobtrack.cpp
diff options
context:
space:
mode:
authorAntoine Villeret <avilleret@users.sourceforge.net>2013-10-08 09:22:34 +0000
committerAntoine Villeret <avilleret@users.sourceforge.net>2013-10-08 09:22:34 +0000
commit0b7297ea1006f908aa75b1d107f607d52ecb6735 (patch)
tree651ae83b578a03491e5201e098a94f3a7a5e1bf8 /blobtrack.cpp
parent8a20431fd758bac1a278328ed7b691f363638168 (diff)
remove highgui dependency
svn path=/trunk/externals/pix_opencv/; revision=17212
Diffstat (limited to 'blobtrack.cpp')
-rw-r--r--blobtrack.cpp387
1 files changed, 0 insertions, 387 deletions
diff --git a/blobtrack.cpp b/blobtrack.cpp
index f678502..5015034 100644
--- a/blobtrack.cpp
+++ b/blobtrack.cpp
@@ -245,390 +245,3 @@ void print_params(CvVSModule* pM, const char* module, const char* log_name)
if(log) fclose(log);
} /* print_params */
-
-int main(int argc, char* argv[])
-{ /* Main function: */
- CvCapture* pCap = NULL;
- CvBlobTrackerAutoParam1 param = {0}; // TODO need more params
- CvBlobTrackerAuto* pTracker = NULL;
-
- float scale = 1;
- const char* scale_name = NULL;
- char* yml_name = NULL;
- char** yml_video_names = NULL;
- int yml_video_num = 0;
- char* avi_name = NULL;
- const char* fg_name = NULL;
- char* fgavi_name = NULL;
- char* btavi_name = NULL;
- const char* bd_name = NULL;
- const char* bt_name = NULL;
- const char* btgen_name = NULL;
- const char* btpp_name = NULL;
- const char* bta_name = NULL;
- char* bta_data_name = NULL;
- char* track_name = NULL;
- char* comment_name = NULL;
- char* FGTrainFrames = NULL;
- char* log_name = NULL;
- char* savestate_name = NULL;
- char* loadstate_name = NULL;
- const char* bt_corr = NULL;
- DefModule_FGDetector* pFGModule = NULL;
- DefModule_BlobDetector* pBDModule = NULL;
- DefModule_BlobTracker* pBTModule = NULL;
- DefModule_BlobTrackPostProc* pBTPostProcModule = NULL;
- DefModule_BlobTrackGen* pBTGenModule = NULL;
- DefModule_BlobTrackAnalysis* pBTAnalysisModule = NULL;
-
- cvInitSystem(argc, argv);
-
- if(argc < 2)
- { /* Print help: */
- int i;
- printf("blobtrack [fg=<fg_name>] [bd=<bd_name>]\n"
- " [bt=<bt_name>] [btpp=<btpp_name>]\n"
- " [bta=<bta_name>\n"
- " [bta_data=<bta_data_name>\n"
- " [bt_corr=<bt_corr_way>]\n"
- " [btgen=<btgen_name>]\n"
- " [track=<track_file_name>]\n"
- " [scale=<scale val>] [noise=<noise_name>] [IVar=<IVar_name>]\n"
- " [FGTrainFrames=<FGTrainFrames>]\n"
- " [btavi=<avi output>] [fgavi=<avi output on FG>]\n"
- " <avi_file>\n");
-
- printf(" <bt_corr_way> is the method of blob position correction for the \"Blob Tracking\" module\n"
- " <bt_corr_way>=none,PostProcRes\n"
- " <FGTrainFrames> is number of frames for FG training\n"
- " <track_file_name> is file name for save tracked trajectories\n"
- " <bta_data> is file name for data base of trajectory analysis module\n"
- " <avi_file> is file name of avi to process by BlobTrackerAuto\n");
-
- puts("\nModules:");
-#define PR(_name,_m,_mt)\
- printf("<%s> is \"%s\" module name and can be:\n",_name,_mt);\
- for(i=0; _m[i].nickname; ++i)\
- {\
- printf(" %d. %s",i+1,_m[i].nickname);\
- if(_m[i].description)printf(" - %s",_m[i].description);\
- printf("\n");\
- }
-
- PR("fg_name",FGDetector_Modules,"FG/BG Detection");
- PR("bd_name",BlobDetector_Modules,"Blob Entrance Detection");
- PR("bt_name",BlobTracker_Modules,"Blob Tracking");
- PR("btpp_name",BlobTrackPostProc_Modules, "Blob Trajectory Post Processing");
- PR("btgen_name",BlobTrackGen_Modules, "Blob Trajectory Generation");
- PR("bta_name",BlobTrackAnalysis_Modules, "Blob Trajectory Analysis");
-#undef PR
- return 0;
- } /* Print help. */
-
- { /* Parse arguments: */
- int i;
- for(i=1; i<argc; ++i)
- {
- int bParsed = 0;
- size_t len = strlen(argv[i]);
-#define RO(_n1,_n2) if(strncmp(argv[i],_n1,strlen(_n1))==0) {_n2 = argv[i]+strlen(_n1);bParsed=1;};
- RO("fg=",fg_name);
- RO("fgavi=",fgavi_name);
- RO("btavi=",btavi_name);
- RO("bd=",bd_name);
- RO("bt=",bt_name);
- RO("bt_corr=",bt_corr);
- RO("btpp=",btpp_name);
- RO("bta=",bta_name);
- RO("bta_data=",bta_data_name);
- RO("btgen=",btgen_name);
- RO("track=",track_name);
- RO("comment=",comment_name);
- RO("FGTrainFrames=",FGTrainFrames);
- RO("log=",log_name);
- RO("savestate=",savestate_name);
- RO("loadstate=",loadstate_name);
-#undef RO
- {
- char* ext = argv[i] + len-4;
- if( strrchr(argv[i],'=') == NULL &&
- !bParsed &&
- (len>3 && (MY_STRICMP(ext,".avi") == 0 )))
- {
- avi_name = argv[i];
- break;
- }
- } /* Next argument. */
- }
- } /* Parse arguments. */
-
- if(track_name)
- { /* Set Trajectory Generator module: */
- int i;
- if(!btgen_name)btgen_name=BlobTrackGen_Modules[0].nickname;
-
- for(i=0; BlobTrackGen_Modules[i].nickname; ++i)
- {
- if(MY_STRICMP(BlobTrackGen_Modules[i].nickname,btgen_name)==0)
- pBTGenModule = BlobTrackGen_Modules + i;
- }
- } /* Set Trajectory Generato module. */
-
- /* Initialize postprocessing module if tracker
- * correction by postprocessing is required.
- */
- if(bt_corr && MY_STRICMP(bt_corr,"PostProcRes")!=0 && !btpp_name)
- {
- btpp_name = bt_corr;
- if(MY_STRICMP(btpp_name,"none")!=0)bt_corr = "PostProcRes";
- }
-
- { /* Set default parameters for one processing: */
- if(!bt_corr) bt_corr = "none";
- if(!fg_name) fg_name = FGDetector_Modules[0].nickname;
- if(!bd_name) bd_name = BlobDetector_Modules[0].nickname;
- if(!bt_name) bt_name = BlobTracker_Modules[0].nickname;
- if(!btpp_name) btpp_name = BlobTrackPostProc_Modules[0].nickname;
- if(!bta_name) bta_name = BlobTrackAnalysis_Modules[0].nickname;
- if(!scale_name) scale_name = "1";
- }
-
- if(scale_name)
- scale = (float)atof(scale_name);
-
- for(pFGModule=FGDetector_Modules; pFGModule->nickname; ++pFGModule)
- if( fg_name && MY_STRICMP(fg_name,pFGModule->nickname)==0 ) break;
-
- for(pBDModule=BlobDetector_Modules; pBDModule->nickname; ++pBDModule)
- if( bd_name && MY_STRICMP(bd_name,pBDModule->nickname)==0 ) break;
-
- for(pBTModule=BlobTracker_Modules; pBTModule->nickname; ++pBTModule)
- if( bt_name && MY_STRICMP(bt_name,pBTModule->nickname)==0 ) break;
-
- for(pBTPostProcModule=BlobTrackPostProc_Modules; pBTPostProcModule->nickname; ++pBTPostProcModule)
- if( btpp_name && MY_STRICMP(btpp_name,pBTPostProcModule->nickname)==0 ) break;
-
- for(pBTAnalysisModule=BlobTrackAnalysis_Modules; pBTAnalysisModule->nickname; ++pBTAnalysisModule)
- if( bta_name && MY_STRICMP(bta_name,pBTAnalysisModule->nickname)==0 ) break;
-
- /* Create source video: */
- if(avi_name)
- pCap = cvCaptureFromFile(avi_name);
-
- if(pCap==NULL)
- {
- printf("Can't open %s file\n",avi_name);
- return -1;
- }
-
-
- { /* Display parameters: */
- int i;
- FILE* log = log_name?fopen(log_name,"at"):NULL;
- if(log)
- { /* Print to log file: */
- fprintf(log,"\n=== Blob Tracking pipline in processing mode===\n");
- if(avi_name)
- {
- fprintf(log,"AVIFile: %s\n",avi_name);
- }
- fprintf(log,"FGDetector: %s\n", pFGModule->nickname);
- fprintf(log,"BlobDetector: %s\n", pBDModule->nickname);
- fprintf(log,"BlobTracker: %s\n", pBTModule->nickname);
- fprintf(log,"BlobTrackPostProc: %s\n", pBTPostProcModule->nickname);
- fprintf(log,"BlobCorrection: %s\n", bt_corr);
-
- fprintf(log,"Blob Trajectory Generator: %s (%s)\n",
- pBTGenModule?pBTGenModule->nickname:"None",
- track_name?track_name:"none");
-
- fprintf(log,"BlobTrackAnalysis: %s\n", pBTAnalysisModule->nickname);
- fclose(log);
- }
-
- printf("\n=== Blob Tracking pipline in %s mode===\n","processing");
- if(yml_name)
- {
- printf("ConfigFile: %s\n",yml_name);
- printf("BG: %s\n",yml_video_names[0]);
- printf("FG: ");
- for(i=1;i<(yml_video_num);++i){printf("%s",yml_video_names[i]);if((i+1)<yml_video_num)printf("|");};
- printf("\n");
- }
- if(avi_name)
- {
- printf("AVIFile: %s\n",avi_name);
- }
- printf("FGDetector: %s\n", pFGModule->nickname);
- printf("BlobDetector: %s\n", pBDModule->nickname);
- printf("BlobTracker: %s\n", pBTModule->nickname);
- printf("BlobTrackPostProc: %s\n", pBTPostProcModule->nickname);
- printf("BlobCorrection: %s\n", bt_corr);
-
- printf("Blob Trajectory Generator: %s (%s)\n",
- pBTGenModule?pBTGenModule->nickname:"None",
- track_name?track_name:"none");
-
- printf("BlobTrackAnalysis: %s\n", pBTAnalysisModule->nickname);
-
- } /* Display parameters. */
-
- { /* Create autotracker module and its components: */
- param.FGTrainFrames = FGTrainFrames?atoi(FGTrainFrames):0;
-
- /* Create FG Detection module: */
- param.pFG = pFGModule->create();
- if(!param.pFG)
- puts("Can not create FGDetector module");
- param.pFG->SetNickName(pFGModule->nickname);
- set_params(argc, argv, param.pFG, "fg", pFGModule->nickname);
-
- /* Create Blob Entrance Detection module: */
- param.pBD = pBDModule->create();
- if(!param.pBD)
- puts("Can not create BlobDetector module");
- param.pBD->SetNickName(pBDModule->nickname);
- set_params(argc, argv, param.pBD, "bd", pBDModule->nickname);
-
- /* Create blob tracker module: */
- param.pBT = pBTModule->create();
- if(!param.pBT)
- puts("Can not create BlobTracker module");
- param.pBT->SetNickName(pBTModule->nickname);
- set_params(argc, argv, param.pBT, "bt", pBTModule->nickname);
-
- /* Create blob trajectory generation module: */
- param.pBTGen = NULL;
- if(pBTGenModule && track_name && pBTGenModule->create)
- {
- param.pBTGen = pBTGenModule->create();
- param.pBTGen->SetFileName(track_name);
- }
- if(param.pBTGen)
- {
- param.pBTGen->SetNickName(pBTGenModule->nickname);
- set_params(argc, argv, param.pBTGen, "btgen", pBTGenModule->nickname);
- }
-
- /* Create blob trajectory post processing module: */
- param.pBTPP = NULL;
- if(pBTPostProcModule && pBTPostProcModule->create)
- {
- param.pBTPP = pBTPostProcModule->create();
- }
- if(param.pBTPP)
- {
- param.pBTPP->SetNickName(pBTPostProcModule->nickname);
- set_params(argc, argv, param.pBTPP, "btpp", pBTPostProcModule->nickname);
- }
-
- param.UsePPData = (bt_corr && MY_STRICMP(bt_corr,"PostProcRes")==0);
-
- /* Create blob trajectory analysis module: */
- param.pBTA = NULL;
- if(pBTAnalysisModule && pBTAnalysisModule->create)
- {
- param.pBTA = pBTAnalysisModule->create();
- param.pBTA->SetFileName(bta_data_name);
- }
- if(param.pBTA)
- {
- param.pBTA->SetNickName(pBTAnalysisModule->nickname);
- set_params(argc, argv, param.pBTA, "bta", pBTAnalysisModule->nickname);
- }
-
- /* Create whole pipline: */
- pTracker = cvCreateBlobTrackerAuto1(&param);
- if(!pTracker)
- puts("Can not create BlobTrackerAuto");
- }
-
- { /* Load states of each module from state file: */
- CvFileStorage* fs = NULL;
- if(loadstate_name)
- fs=cvOpenFileStorage(loadstate_name,NULL,CV_STORAGE_READ);
- if(fs)
- {
- printf("Load states for modules...\n");
- if(param.pBT)
- {
- CvFileNode* fn = cvGetFileNodeByName(fs,NULL,"BlobTracker");
- param.pBT->LoadState(fs,fn);
- }
-
- if(param.pBTA)
- {
- CvFileNode* fn = cvGetFileNodeByName(fs,NULL,"BlobTrackAnalyser");
- param.pBTA->LoadState(fs,fn);
- }
-
- if(pTracker)
- {
- CvFileNode* fn = cvGetFileNodeByName(fs,NULL,"BlobTrackerAuto");
- pTracker->LoadState(fs,fn);
- }
-
- cvReleaseFileStorage(&fs);
- printf("... Modules states loaded\n");
- }
- } /* Load states of each module. */
-
- { /* Print module parameters: */
- struct DefMMM
- {
- CvVSModule* pM;
- const char* name;
- } Modules[] = {
- {(CvVSModule*)param.pFG,"FGdetector"},
- {(CvVSModule*)param.pBD,"BlobDetector"},
- {(CvVSModule*)param.pBT,"BlobTracker"},
- {(CvVSModule*)param.pBTGen,"TrackGen"},
- {(CvVSModule*)param.pBTPP,"PostProcessing"},
- {(CvVSModule*)param.pBTA,"TrackAnalysis"},
- {NULL,NULL}
- };
- int i;
- for(i=0; Modules[i].name; ++i)
- {
- if(Modules[i].pM)
- print_params(Modules[i].pM,Modules[i].name,log_name);
- }
- } /* Print module parameters. */
-
- /* Run pipeline: */
- RunBlobTrackingAuto( pCap, pTracker, fgavi_name, btavi_name );
-
- { /* Save state and release modules: */
- CvFileStorage* fs = NULL;
- if(savestate_name)
- {
- fs=cvOpenFileStorage(savestate_name,NULL,CV_STORAGE_WRITE);
- }
- if(fs)
- {
- cvStartWriteStruct(fs,"BlobTracker",CV_NODE_MAP);
- if(param.pBT)param.pBT->SaveState(fs);
- cvEndWriteStruct(fs);
- cvStartWriteStruct(fs,"BlobTrackerAuto",CV_NODE_MAP);
- if(pTracker)pTracker->SaveState(fs);
- cvEndWriteStruct(fs);
- cvStartWriteStruct(fs,"BlobTrackAnalyser",CV_NODE_MAP);
- if(param.pBTA)param.pBTA->SaveState(fs);
- cvEndWriteStruct(fs);
- cvReleaseFileStorage(&fs);
- }
- if(param.pBT)cvReleaseBlobTracker(&param.pBT);
- if(param.pBD)cvReleaseBlobDetector(&param.pBD);
- if(param.pBTGen)cvReleaseBlobTrackGen(&param.pBTGen);
- if(param.pBTA)cvReleaseBlobTrackAnalysis(&param.pBTA);
- if(param.pFG)cvReleaseFGDetector(&param.pFG);
- if(pTracker)cvReleaseBlobTrackerAuto(&pTracker);
-
- } /* Save state and release modules. */
-
- if(pCap)
- cvReleaseCapture(&pCap);
-
- return 0;
-
-} /* main() */