00001 //*!@file Image/BlobTracker.C A multi-blob tracker */ 00002 // 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Rand Voorhies <voorhies at usc dot edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Image/BlobTracker.C $ 00035 // $Id: BlobTracker.C 14376 2011-01-11 02:44:34Z pez $ 00036 // 00037 00038 #ifndef BLOBTRACKER_C_DEFINED 00039 #define BLOBTRACKER_C_DEFINED 00040 00041 #include "Image/BlobTracker.H" 00042 #include "GUI/DebugWin.H" 00043 00044 00045 BlobTracker::BlobTracker(OptionManager& mgr, 00046 const std::string& descrName, 00047 const std::string& tagName) : 00048 ModelComponent(mgr, descrName, tagName) 00049 { 00050 itsTrackerParams.FGTrainFrames = 0; 00051 00052 //Foreground Detector Module: 00053 // Adaptive background mixture models for real-time tracking. CVPR1999 00054 // itsTrackerParams.pFG = cvCreateFGDetectorBase(CV_BG_MODEL_MOG, NULL); 00055 // Foreground Object Detection from Videos Containing Complex Background. ACM MM2003. 00056 itsTrackerParams.pFG = cvCreateFGDetectorBase(CV_BG_MODEL_FGD, NULL); 00057 //itsTrackerParams.pFG = cvCreateFGDetectorBase(CV_BG_MODEL_FGD_SIMPLE, NULL); 00058 00059 //Blob Detector Module: 00060 // Detect new blob by tracking CC of FG mask 00061 // itsTrackerParams.pBD = cvCreateBlobDetectorCC(); 00062 00063 // Detect new blob by uniform moving of connected components of FG mask 00064 itsTrackerParams.pBD = cvCreateBlobDetectorSimple(); 00065 00066 00067 //Blob Tracker Module: 00068 // Simple connected component tracking 00069 itsTrackerParams.pBT = cvCreateBlobTrackerCC(); 00070 // itsTrackerParams.pBT = cvCreateBlobTrackerCCMSPF(); 00071 00072 // Blob Tracker Tratectory Generation Module 00073 //itsTrackerParams.pBTGen = cvCreateModuleBlobTrackGen1(); 00074 itsTrackerParams.pBTGen = NULL; 00075 00076 //Blob Tracker Post Processor: 00077 // None 00078 itsTrackerParams.pBTPP = NULL; 00079 //itsTrackerParams.pBTPP = cvCreateModuleBlobTrackPostProcKalman(); 00080 00081 //Use Post Processing Data: 00082 // No, don't 00083 itsTrackerParams.UsePPData = 0; 00084 //itsTrackerParams.UsePPData = 1; 00085 00086 //Blob Tracker Trajectory Analysis Module 00087 // None 00088 itsTrackerParams.pBTA = NULL; 00089 00090 itsTracker = cvCreateBlobTrackerAuto1(&itsTrackerParams); 00091 00092 if(!itsTracker) 00093 LFATAL("Could Not Create Blob Tracker!"); 00094 00095 } 00096 00097 BlobTracker::~BlobTracker() 00098 { 00099 } 00100 00101 void BlobTracker::update(Image<PixRGB<byte> > img) 00102 { 00103 IplImage* pImg = img2ipl(img); 00104 LINFO("Attempting to process image %dx%d",img.getWidth(),img.getHeight()); 00105 //Process the new image 00106 itsTracker->Process(pImg); 00107 00108 itsBlobs.clear(); 00109 00110 //Analyze the blobs picked out by the tracker 00111 for(int i=0; i<itsTracker->GetBlobNum(); i++) 00112 { 00113 Blob newBlob; 00114 CvBlob* blob; 00115 Point2D<int> blobCenter; 00116 Dims blobDims; 00117 int blobID; 00118 00119 //Grab the next blob 00120 blob = itsTracker->GetBlob(i); 00121 00122 //Find the blob center 00123 blobCenter = Point2D<int> ( 00124 blob->x, 00125 blob->y 00126 ); 00127 00128 //Find the blob dims 00129 blobDims = Dims( 00130 blob->w, 00131 blob->h 00132 ); 00133 00134 blobID = CV_BLOB_ID(blob); 00135 00136 newBlob.confidence = 0; 00137 newBlob.center = blobCenter; 00138 newBlob.dims = blobDims; 00139 newBlob.id = blobID; 00140 00141 itsBlobs.push_back(newBlob); 00142 } 00143 } 00144 00145 00146 00147 00148 #endif