├── MultipleCameraTracking.bat
├── MultipleCameraTracking.sh
├── MultipleCameraTracking.vs2008.sln
├── MultipleCameraTracking.vs2008.vcproj
├── README.md
├── config.cfg
├── obj
└── Makefile
├── property_sheets
├── opencv2_3.vsprops
└── opencv2_3_64.vsprops
└── src
├── AdaBoostClassifier.cpp
├── AdaBoostClassifier.h
├── AppearanceBasedInformationFuser.cpp
├── AppearanceBasedInformationFuser.h
├── Camera.cpp
├── Camera.h
├── CameraNetwork.cpp
├── CameraNetwork.h
├── CameraNetworkBase.h
├── ClassifierParameters.h
├── CommonMacros.h
├── Config.cpp
├── Config.h
├── CultureColorHistogram.cpp
├── CultureColorHistogram.h
├── CultureColorHistogramFeatureVector.cpp
├── CultureColorHistogramFeatureVector.h
├── DefaultParameters.h
├── Exception.h
├── Feature.h
├── FeatureParameters.cpp
├── FeatureParameters.h
├── FeatureVector.h
├── GeometryBasedInformationFuser.cpp
├── GeometryBasedInformationFuser.h
├── HaarAndColorHistogramFeatureVector.cpp
├── HaarAndColorHistogramFeatureVector.h
├── HaarFeature.cpp
├── HaarFeature.h
├── HaarFeatureVector.cpp
├── HaarFeatureVector.h
├── MILAnyBoostClassifier.cpp
├── MILAnyBoostClassifier.h
├── MILBoostClassifier.cpp
├── MILBoostClassifier.h
├── MILEnsembleClassifier.cpp
├── MILEnsembleClassifier.h
├── Matrix.cpp
├── Matrix.h
├── MultiDimensionalColorHistogram.cpp
├── MultiDimensionalColorHistogram.h
├── MultiDimensionalColorHistogramFeatureVector.cpp
├── MultiDimensionalColorHistogramFeatureVector.h
├── MultipleCameraTrackingMain.cpp
├── Object.cpp
├── Object.h
├── OnlineStumpsWeakClassifier.cpp
├── OnlineStumpsWeakClassifier.h
├── ParticleFilter.cpp
├── ParticleFilter.h
├── ParticleFilterTracker.cpp
├── ParticleFilterTracker.h
├── PerceptronWeakClassifier.cpp
├── PerceptronWeakClassifier.h
├── Public.cpp
├── Public.h
├── Sample.cpp
├── Sample.h
├── SampleSet.cpp
├── SampleSet.h
├── SimpleTracker.cpp
├── SimpleTracker.h
├── StrongClassifierBase.cpp
├── StrongClassifierBase.h
├── StrongClassifierFactory.cpp
├── StrongClassifierFactory.h
├── Tracker.cpp
├── Tracker.h
├── TrackerParameters.cpp
├── TrackerParameters.h
├── WeakClassifierBase.cpp
├── WeakClassifierBase.h
├── WeightedStumpsWeakClassifier.cpp
└── WeightedStumpsWeakClassifier.h
/MultipleCameraTracking.bat:
--------------------------------------------------------------------------------
1 | MultipleCameraTracking.exe -d config.cfg -p Whether_Calculate_Tracking_Error=0
--------------------------------------------------------------------------------
/MultipleCameraTracking.sh:
--------------------------------------------------------------------------------
1 | #! /bin/sh
2 | export LD_LIBRARY_PATH=/opt/intel/composer_xe_2013_sp1/ipp/lib/intel64:$LD_LIBRARY_PATH
3 | ./MultipleCameraTracking -d config.cfg
4 |
--------------------------------------------------------------------------------
/MultipleCameraTracking.vs2008.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 10.00
3 | # Visual Studio 2008
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MultipleCameraTracking", "MultipleCameraTracking.vs2008.vcproj", "{8321B0CA-7F1A-4168-9806-FE0A9CE5531C}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Debug|x64 = Debug|x64
10 | Release|Win32 = Release|Win32
11 | Release|x64 = Release|x64
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {8321B0CA-7F1A-4168-9806-FE0A9CE5531C}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {8321B0CA-7F1A-4168-9806-FE0A9CE5531C}.Debug|Win32.Build.0 = Debug|Win32
16 | {8321B0CA-7F1A-4168-9806-FE0A9CE5531C}.Debug|x64.ActiveCfg = Debug|x64
17 | {8321B0CA-7F1A-4168-9806-FE0A9CE5531C}.Debug|x64.Build.0 = Debug|x64
18 | {8321B0CA-7F1A-4168-9806-FE0A9CE5531C}.Release|Win32.ActiveCfg = Release|Win32
19 | {8321B0CA-7F1A-4168-9806-FE0A9CE5531C}.Release|Win32.Build.0 = Release|Win32
20 | {8321B0CA-7F1A-4168-9806-FE0A9CE5531C}.Release|x64.ActiveCfg = Release|x64
21 | {8321B0CA-7F1A-4168-9806-FE0A9CE5531C}.Release|x64.Build.0 = Release|x64
22 | EndGlobalSection
23 | GlobalSection(SolutionProperties) = preSolution
24 | HideSolutionNode = FALSE
25 | EndGlobalSection
26 | EndGlobal
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | A multi-camera tracking algorithm using OpenCV. It depends on OpenCv 2.3.1 (http://opencv.org/), Boost libraries (http://www.boost.org/) and Intel IPP (https://software.intel.com/en-us/intel-ipp).
2 |
3 | Usage
4 | ------------
5 |
6 | In order to run the tracker, use the following command:
7 |
8 | ### Windows ###
9 |
10 | MultiCameraTracker.exe -d config.cfg
11 |
12 | (or)
13 |
14 | MultiCameraTracker.bat
15 |
16 | ### Linux ###
17 |
18 | ./MultiCameraTracker -d config.cfg
19 |
20 | (or)
21 |
22 | ./MultiCameraTracker.sh
23 |
24 | Compilation
25 | ------------
26 | Windows: Build the Visual studio project.
27 |
28 | Linux: Run the make file inside the "obj" folder.
29 |
30 | Note: Make sure Intel IPP, OpenCv 2.3.1 and Boost libraries are located in appropriate folders.
31 |
32 | Data
33 | ------------
34 | Here is the sample data folder: https://www.dropbox.com/s/gnheat18lotoi2k/data.tar.gz?dl=0
35 |
36 | Note: Follow a similar folder structure for new scenarios.
37 |
38 | ### Contact ###
39 | [1] Santhoshkumar Sunderrajan( santhosh@ece.ucsb.edu)
40 | Website: http://santhoshsunderrajan.com/
41 |
42 | ### Bibtex ###
43 | If you use the code in any of your research works, please cite the following papers:
44 | ~~~
45 | @inproceedings{ni2010particle,
46 | title={Particle filter tracking with online multiple instance learning},
47 | author={Ni, Zefeng and Sunderrajan, Santhoshkumar and Rahimi, Amir and Manjunath, BS},
48 | booktitle={Pattern Recognition (ICPR), 2010 20th International Conference on},
49 | pages={2616--2619},
50 | year={2010},
51 | organization={IEEE}
52 | }
53 |
54 | @inproceedings{ni2010distributed,
55 | title={Distributed particle filter tracking with online multiple instance learning in a camera sensor network},
56 | author={Ni, Zefeng and Sunderrajan, Santhoshkumar and Rahimi, Amir and Manjunath, BS},
57 | booktitle={Image Processing (ICIP), 2010 17th IEEE International Conference on},
58 | pages={37--40},
59 | year={2010},
60 | organization={IEEE}
61 | }
62 | ~~~
63 |
64 | ### Disclaimer ###
65 | I may have used some good codes from various sources, please feel free to notify me if you find a piece of code that I need to acknowledge.
66 |
--------------------------------------------------------------------------------
/obj/Makefile:
--------------------------------------------------------------------------------
1 | #Compiler
2 | CC=g++
3 |
4 | #IPP=/opt/intel/ipp/6.1.2.051/em64t#IPP location
5 | IPP=/opt/intel/composer_xe_2013_sp1/ipp
6 |
7 | #library
8 | #for opencv 2.1
9 | #LDFLAGS=-lcxcore -lcv -lhighgui -lippiem64t -lippmem64t -lippcvem64t -lippcoreem64t -liomp5 -lpthread -lm
10 | #for opencv2.2 and 2.3 onwards, use the following
11 | LDFLAGS=-L$(IPP)/lib/intel64 -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_objdetect -lopencv_video -lopencv_ml -lippi -lipps -lippcv -lippcore
12 |
13 | #headers
14 | CFLAGS=-c -w -I$(IPP)/include -I/usr/local/include/opencv -I/usr/local/include/ -I/usr/local/include/boost
15 |
16 | SRCDIR=../src
17 | OBJDIR=./
18 |
19 | SOURCES=$(wildcard $(SRCDIR)/*.cpp)
20 |
21 | OBJECTS_TMP := $(SOURCES:.cpp=.o)
22 | OBJECTS := $(subst src,obj, $(OBJECTS_TMP))
23 |
24 | EXECUTABLE = MultipleCameraTracking
25 |
26 | all: $(OBJECTS) $(EXECUTABLE)
27 |
28 | clean:
29 | rm -rf $(EXECUTABLE)
30 | rm ./*.o
31 |
32 | $(EXECUTABLE): $(OBJECTS)
33 | $(CC) $(OBJECTS) $(LDFLAGS) -o $@
34 |
35 | $(OBJECTS): $(SOURCES)
36 | $(CC) $(CFLAGS) $(SOURCES)
37 |
--------------------------------------------------------------------------------
/property_sheets/opencv2_3.vsprops:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
16 |
17 |
--------------------------------------------------------------------------------
/property_sheets/opencv2_3_64.vsprops:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
16 |
17 |
--------------------------------------------------------------------------------
/src/AdaBoostClassifier.h:
--------------------------------------------------------------------------------
1 | #ifndef ADABOOST_H
2 | #define ADABOOST_H
3 |
4 | #include "StrongClassifierBase.h"
5 |
6 | namespace Classifier
7 | {
8 | /****************************************************************
9 | AdaBoostClassifier
10 | Implements AdaBoost based Strong Classifier.
11 | ****************************************************************/
12 | class AdaBoostClassifier : public StrongClassifierBase
13 | {
14 | public:
15 |
16 | //Constructor
17 | AdaBoostClassifier( Classifier::StrongClassifierParametersBasePtr strongClassifierParametersBasePtr );
18 |
19 | //Update the strong classifier
20 | virtual void Update( Classifier::SampleSet& positiveSampleSet,
21 | Classifier::SampleSet& negativeSampleSet );
22 |
23 | //Classify the sample set
24 | virtual vectorf Classify( Classifier::SampleSet& sampleSet,
25 | bool isLogRatioEnabled = true );
26 |
27 | private:
28 |
29 | //Initialize the classifier
30 | void Initialize( Classifier::StrongClassifierParametersBasePtr strongClassifierParametersBasePtr );
31 |
32 | AdaBoostClassifierParametersPtr m_adaBoostClassifierParametersPtr;
33 | vectorf m_alphaList;
34 | float m_sumOfAlphas;
35 | vector m_countFPv;
36 | vector m_countFNv;
37 | vector m_countTPv;
38 | vector m_countTNv; //[selector][feature]
39 | };
40 | }
41 | #endif
--------------------------------------------------------------------------------
/src/AppearanceBasedInformationFuser.cpp:
--------------------------------------------------------------------------------
1 | #include "AppearanceBasedInformationFuser.h"
2 | #include "StrongClassifierFactory.h"
3 | #include "CameraNetworkBase.h"
4 | #include "Config.h"
5 |
6 | #define RANDOM_SAMPLE_SELECTION_THRESHOLD 0.5f
7 | #define MULTIPLE_POSITIVE_BAG 0
8 |
9 | namespace MultipleCameraTracking
10 | {
11 | /********************************************************************
12 | AppearanceBasedInformationFuser
13 | AppearanceBasedInformationFuser fuses information from multiple cameras.
14 | Exceptions:
15 | None
16 | *********************************************************************/
17 | AppearanceBasedInformationFuser::AppearanceBasedInformationFuser( const int objectId,
18 | const int cameraId,
19 | const AppearanceFusionType appearanceFusionType,
20 | Classifier::StrongClassifierParametersBasePtr strongClassifierParametersBasePtr )
21 | : m_objectId( objectId ),
22 | m_cameraId( cameraId ),
23 | m_appearanceFusionType( appearanceFusionType ),
24 | m_strongClassifierParametersBasePtr( strongClassifierParametersBasePtr )
25 | {
26 | try
27 | {
28 | strongClassifierParametersBasePtr->m_learningRate = 0;
29 |
30 | m_strongClassifierBasePtr = Classifier::StrongClassifierFactory::CreateAndInitializeClassifier( ( strongClassifierParametersBasePtr ) );
31 |
32 | ASSERT_TRUE( m_strongClassifierBasePtr.get() != NULL );
33 | }
34 | EXCEPTION_CATCH_AND_ABORT( "Failed to Initialize the AppearanceBasedInformationFuser");
35 | }
36 |
37 | /********************************************************************
38 | LearnAppearanceModel
39 | Learn the appearance model using the positive and negative
40 | samples provided by different cameras.
41 | Exceptions:
42 | None
43 | *********************************************************************/
44 | void AppearanceBasedInformationFuser::LearnGlobalAppearanceModel( CameraNetworkBasePtr cameraNetworkBasePtr )
45 | {
46 | try
47 | {
48 | ASSERT_TRUE( m_strongClassifierBasePtr != NULL );
49 | ASSERT_TRUE( cameraNetworkBasePtr != NULL );
50 |
51 | Classifier::SampleSet positiveSampleSet;
52 | Classifier::SampleSet negativeSampleSet;
53 |
54 | LOG( "Generating Training Sample Sets for Appearance Fusion" );
55 |
56 | cameraNetworkBasePtr->GenerateTrainingSampleSetsForAppearanceFusion( m_objectId,
57 | positiveSampleSet,
58 | negativeSampleSet );
59 |
60 | ASSERT_TRUE( positiveSampleSet.Size() > 0 );
61 | ASSERT_TRUE( negativeSampleSet.Size() > 0 );
62 |
63 | Classifier::SampleSet randomPositiveSampleSet;
64 | Classifier::SampleSet randomNegativeSampleSet;
65 | if( MULTIPLE_POSITIVE_BAG == 0 )
66 | {//randomly remove positive and negative samples for robustness
67 | for ( int sampleIndex = 0; sampleIndex < positiveSampleSet.Size(); sampleIndex++ )
68 | {
69 | if ( randfloat() > RANDOM_SAMPLE_SELECTION_THRESHOLD )
70 | {
71 | randomPositiveSampleSet.PushBackSample( positiveSampleSet[sampleIndex] );
72 | }
73 | }
74 |
75 | for ( int sampleIndex = 0; sampleIndex < negativeSampleSet.Size(); sampleIndex++ )
76 | {
77 | if ( randfloat() > RANDOM_SAMPLE_SELECTION_THRESHOLD )
78 | {
79 | randomNegativeSampleSet.PushBackSample( negativeSampleSet[sampleIndex] );
80 | }
81 | }
82 | m_strongClassifierBasePtr->Update( randomPositiveSampleSet, randomNegativeSampleSet );
83 | }
84 | else
85 | {
86 | m_strongClassifierBasePtr->Update( positiveSampleSet, negativeSampleSet,5 );
87 | }
88 | }
89 | EXCEPTION_CATCH_AND_ABORT( "Failed while learning the global appearance model" );
90 | }
91 |
92 | /********************************************************************
93 | FuseInformation
94 | Fuse information by .
95 | Exceptions:
96 | None
97 | *********************************************************************/
98 | void AppearanceBasedInformationFuser::FuseInformation( Classifier::SampleSet& testSampleSet, vectorf& likelihoodProbabilities )
99 | {
100 | try
101 | {
102 | ASSERT_TRUE( testSampleSet.Size() > 0 );
103 | ASSERT_TRUE( likelihoodProbabilities.size( ) == testSampleSet.Size() );
104 | ASSERT_TRUE( m_strongClassifierBasePtr != NULL );
105 |
106 | likelihoodProbabilities = m_strongClassifierBasePtr->Classify( testSampleSet );
107 |
108 | //Use sigmoidal function
109 | for ( int index = 0; index < likelihoodProbabilities.size(); index++ )
110 | {
111 | likelihoodProbabilities[index] = pow( sigmoid( likelihoodProbabilities[index] ), 1 );
112 | }
113 |
114 | float totalWeight = 0.0f;
115 | for ( int i = 0; i < testSampleSet.Size(); i++ )
116 | {
117 | totalWeight += max( likelihoodProbabilities[i], 0.0f );
118 | }
119 | }
120 | EXCEPTION_CATCH_AND_ABORT( "Failed to Fuse AppearanceBased Information" );
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/src/AppearanceBasedInformationFuser.h:
--------------------------------------------------------------------------------
1 | #ifndef APPERANCE_INFORMATION_FUSER
2 | #define APPERANCE_INFORMATION_FUSER
3 |
4 | #include "StrongClassifierBase.h"
5 | #include "CameraNetworkBase.h"
6 | #include "TrackerParameters.h"
7 | #include "CommonMacros.h"
8 | #include "Matrix.h"
9 | #include "Config.h"
10 |
11 | #include
12 |
13 | namespace MultipleCameraTracking
14 | {
15 | /****************************************************************
16 | AppearanceBasedInformationFuser
17 | AppearanceBasedInformationFuser fuses appearance
18 | information from multiple cameras.
19 | ****************************************************************/
20 | class AppearanceBasedInformationFuser
21 | {
22 | public:
23 | // Constructor
24 | AppearanceBasedInformationFuser( const int objectId,
25 | const int cameraId,
26 | const AppearanceFusionType appearanceFusionType,
27 | Classifier::StrongClassifierParametersBasePtr strongClassifierParametersBasePtr );
28 |
29 | // Learn Global Appearance Model
30 | void LearnGlobalAppearanceModel( CameraNetworkBasePtr cameraNetworkBasePtr );
31 |
32 | // Compute Likelihoods
33 | void FuseInformation( Classifier::SampleSet& testSampleSet,
34 | vectorf& likelihoodProbabilities );
35 |
36 | private:
37 |
38 | DISALLOW_IMPLICIT_CONSTRUCTORS( AppearanceBasedInformationFuser );
39 |
40 | const int m_objectId;
41 | const int m_cameraId;
42 | const AppearanceFusionType m_appearanceFusionType;
43 | Classifier::StrongClassifierBasePtr m_strongClassifierBasePtr;
44 | Classifier::StrongClassifierParametersBasePtr m_strongClassifierParametersBasePtr;
45 | };
46 |
47 | //typedef for boost pointer
48 | typedef boost::shared_ptr AppearanceBasedInformationFuserPtr;
49 | }
50 | #endif
--------------------------------------------------------------------------------
/src/Camera.h:
--------------------------------------------------------------------------------
1 | #ifndef CAMERA_HEADER
2 | #define CAMERA_HEADER
3 |
4 | #include "Matrix.h"
5 | #include "Feature.h"
6 | #include "Tracker.h"
7 | #include "Public.h"
8 | #include "Object.h"
9 | #include "CameraNetworkBase.h"
10 | #include "DefaultParameters.h"
11 | #include "Config.h"
12 |
13 | #include
14 |
15 | using namespace boost;
16 |
17 | namespace MultipleCameraTracking
18 | {
19 | enum ObjectTrackingStatus
20 | {
21 | OBJECT_TRACKING_UN_INITIALIZED = 0,
22 | OBJECT_TRACKING_IN_PROGRESS = 2,
23 | OBJECT_TRACKING_SUSPENDED = 3
24 | };
25 |
26 | /****************************************************************
27 | Camera
28 | This class is the heart of the tracking system.
29 | It holds all the information about cameras, various parameters.
30 | Objects are stored in a list. Objects across camera views are
31 | associated by their objectId.
32 | ****************************************************************/
33 | class Camera
34 | {
35 | public:
36 | //Constructor
37 | Camera( const int cameraId,
38 | const vectori& objectIdList,
39 | CameraTrackingParametersPtr cameraTrackingParametersPtr );
40 |
41 | ~Camera( ){ }
42 |
43 | int GetCameraID( ) const { return m_cameraID; };
44 | ObjectPtr GetObjectPtr( const int objectId ) const;
45 |
46 | Matrixu* GetColorImageMatrix( ){ return m_pCurrentFrameImageMatrixColor; }
47 | Matrixu* GetGrayImageMatrix( ){ return m_pCurrentFrameImageMatrixGray; }
48 | Matrixu* GetHSVImageMatrix( ){ return &m_HSVImageMatrix; }
49 |
50 | //Learn global appearance model using the appearance fuser
51 | void LearnGlobalAppearanceModel( CameraNetworkBasePtr cameraNetworkBasePtr );
52 |
53 | //Get reprojected particles from the ground plane
54 | CvMat* GetReprojectedParticlesForGeometricFusion( const int objectInd );
55 | CvMat* GetAverageImageParticleForGeometricFusion( const int objectInd );
56 |
57 | //Initializes the parameters for the camera
58 | void InitializeCameraParameters( const vectori& objectIdList );
59 |
60 | //initialize all object trackers inside the camera
61 | void InitializeCameraTrackers( );
62 |
63 | //Track all objects inside a Camera Frame
64 | void TrackCameraFrame( int frameInd );
65 |
66 | //Store the particle filter tracker state
67 | void StoreAllParticleFilterTrackerState( int frameInd );
68 |
69 | //Update the particle filter tracker appearance
70 | void LearnLocalAppearanceModel( int frameInd);
71 |
72 | //Save the state on the output trajectory files
73 | void SaveStatesAllFrames( );
74 |
75 | //Update particle weights based on the ground plane kalman filter's pdf
76 | void UpdateParticleWeightsWithGroundPDF( CvMat* pMeanMatrix, CvMat* pCovarianceMatrix, int objectId );
77 |
78 | //Get homography matrix
79 | CvMat* GetHomographyMatrix( ){ return m_pHomographyMatrix; }
80 |
81 | //draw object's predicted foot points on the image
82 | void DrawAllObjectFootPoints( );
83 |
84 | private:
85 |
86 | DISALLOW_IMPLICIT_CONSTRUCTORS( Camera );
87 |
88 | //update display for tracked frame
89 | void DisplayAndSaveTrackedFrame( );
90 |
91 | //update display for training samples
92 | void DisplayAndSaveTrainingSamples();
93 |
94 | //auto-initialize object, occlusion detection, handling, and resumption
95 | void MultipleObjectInteraction( ) { /*implement this*/ };
96 |
97 | // create temporary frame image for displaying, tracking, initialization integral image etc. when necessary
98 | void PrepareCurrentFrameForTracking( int frameInd );
99 |
100 | //camera property
101 | CvMat* m_pHomographyMatrix; //Stores the Homography
102 | int m_cameraID; //Camera ID
103 | vector m_objectPtrList; //List of objects being tracked
104 | vector m_objectStatusList; //List of object status
105 |
106 |
107 | //input data parameters
108 | vector m_videoMatrix; //Input video Sequence for tracking
109 | bool m_sourceIsColorImage; //read input video as color
110 | bool m_readImages; //read images or video stream
111 | Matrixf m_frameMatrix; //Stores starting and ending frame numbers
112 | Matrixf m_initialState; //Initial states for all objects
113 |
114 | Matrixu* m_pCurrentFrameImageMatrixGray; //a pointer to the currently tracked frame (Gray image)
115 | Matrixu* m_pCurrentFrameImageMatrixHSV; //a pointer to the currently tracked frame (HSV image)
116 | Matrixu* m_pCurrentFrameImageMatrixColor;//a pointer to the currently tracked frame (Color image)
117 | Matrixu m_grayScaleImageMatrix; //a temporary black and white image for Haar feature calculation if raw video is color
118 | Matrixu m_HSVImageMatrix; //a temporal HSV image matrix for HSV related feature calculation if hsv is needed.
119 |
120 | //tracking parameters
121 | //the following parameters "typically" passed from the owner CameraNetwork class
122 | CameraTrackingParametersPtr m_cameraTrackingParametersPtr;
123 |
124 | //output results (including displaying)
125 | const char* m_outputDirectoryCstr; //Directory for output result
126 | bool m_displayTrackedVideo; // display video with tracker state (colored box)
127 | bool m_saveTrackedVideo; // save video with tracking box
128 | CvVideoWriter* m_pVideoWriter; // if m_saveTrackedVideo == true
129 | Matrixu m_frameDisplay; //for displaying and saving tracked frame
130 | Matrixu* m_pFrameDisplay;
131 |
132 | bool m_displayTrainingSamples; // display video with training examples
133 | bool m_saveVideoTrainingExamples;//save the training examples
134 | CvVideoWriter* m_pVideoWriterTraining; //for saving training example on frame
135 | Matrixu m_frameDisplayTraining; //for displaying and saving training examples on frame
136 | Matrixu* m_pFrameDisplayTraining;
137 |
138 | vector m_groundTruthMatrixList; //hold the ground truth for each object in the camera
139 | };
140 |
141 | //typedef for camera pointer
142 | typedef boost::shared_ptr CameraPtr;
143 | typedef std::vector CameraPtrList;
144 | }
145 | #endif
--------------------------------------------------------------------------------
/src/CameraNetwork.h:
--------------------------------------------------------------------------------
1 | #ifndef CAMERA_NETWORK_HEADER
2 | #define CAMERA_NETWORK_HEADER
3 |
4 | #include "CameraNetworkBase.h"
5 | #include "Camera.h"
6 | #include "GeometryBasedInformationFuser.h"
7 | #include
8 |
9 | using namespace boost;
10 |
11 | namespace MultipleCameraTracking
12 | {
13 | /****************************************************************
14 | CameraNetwork
15 | Camera Network encapsulates all the functions of a network.
16 | It holds a list of cameras, all the messages to each of the
17 | camera is passed through this class.
18 | ****************************************************************/
19 | class CameraNetwork : public CameraNetworkBase
20 | {
21 | public :
22 |
23 | //Constructor
24 | CameraNetwork( const vectori cameraIdList,
25 | const vectori objectIdList,
26 | CameraTrackingParametersPtr cameraTrackingParametersPtr );
27 |
28 | //Destructor
29 | ~CameraNetwork( );
30 |
31 | //Generates training example for appearance fusion
32 | virtual void GenerateTrainingSampleSetsForAppearanceFusion( const int objectId,
33 | Classifier::SampleSet& positiveSampleSet,
34 | Classifier::SampleSet& negativeSampleSet );
35 |
36 | //Track Objects on a given frame across different views
37 | virtual void TrackObjectsOnCurrentFrame( const int frameInd );
38 |
39 | //Save Camera Network state in a file(if enabled)
40 | virtual void SaveCameraNetworkState( );
41 |
42 | private :
43 |
44 | DISALLOW_IMPLICIT_CONSTRUCTORS( CameraNetwork );
45 |
46 | void FeedbackInformationFromGeometricFusion( int frameIndex );
47 | void FuseGeometrically( int frameIndex );
48 | vector GetHomographyMatrixList( );
49 |
50 | void InitializeCameraNetwork( );
51 | void InitializeGeometricFuser( );
52 |
53 |
54 | const int m_numberOfCameras;
55 | const int m_numberOfObjects;
56 | const vectori m_cameraIdList;
57 | const vectori m_objectIdList;
58 | CameraPtrList m_cameraPtrList;
59 | CameraTrackingParametersPtr m_cameraTrackingParametersPtr;
60 | vector m_groundPlaneParticlesPtrList;
61 | GeometryBasedInformationFuserPtrList m_geometricInformationFuserPtrList;
62 | vector m_videoWriterListGroundParticles;
63 | vector m_videoWriterListKFDistribution;
64 | vector m_videoWriterListGroundParticlesAfterFusion;
65 | };
66 |
67 | //typedef for CameraNetwork pointer
68 | typedef boost::shared_ptr CameraNetworkPtr;
69 | }
70 | #endif
--------------------------------------------------------------------------------
/src/CameraNetworkBase.h:
--------------------------------------------------------------------------------
1 | #ifndef CAMERA_NETWORK_BASE
2 | #define CAMERA_NETWORK_BASE
3 |
4 | #include "CommonMacros.h"
5 | #include "SampleSet.h"
6 |
7 | #include
8 |
9 | namespace MultipleCameraTracking
10 | {
11 | /****************************************************************
12 | CameraNetworkBase
13 | A Base class for CameraNetwork. This is an abstract interface.
14 | Mainly for message passing across different cameras.
15 | ****************************************************************/
16 | class CameraNetworkBase
17 | {
18 | public:
19 | virtual void GenerateTrainingSampleSetsForAppearanceFusion( const int objectId, Classifier::SampleSet& positiveSampleSet, Classifier::SampleSet& negativeSampleSet ) = 0;
20 |
21 | //Save Camera Network state in a file(if enabled)
22 | virtual void SaveCameraNetworkState( ) = 0;
23 |
24 | //Track Objects on a given frame across different views
25 | virtual void TrackObjectsOnCurrentFrame( const int frameIndex ) = 0;
26 | };
27 |
28 | //typedef for CameraNetworkBase pointer - do not use shared_ptr, it will delete the local ptr when it goes out of scope
29 | typedef CameraNetworkBase* CameraNetworkBasePtr;
30 | };
31 | #endif
32 |
--------------------------------------------------------------------------------
/src/ClassifierParameters.h:
--------------------------------------------------------------------------------
1 | #ifndef CLASSIFIER_PARAMETERS_H
2 | #define CLASSIFIER_PARAMETERS_H
3 |
4 | #include "Public.h"
5 | #include "Feature.h"
6 | #include "WeakClassifierBase.h"
7 | #include "DefaultParameters.h"
8 |
9 | namespace Classifier
10 | {
11 | enum StrongClassifierType
12 | {
13 | ONLINE_ADABOOST = 0, // [0] Online AdaBoost (Oza/Grabner)
14 | //ONLINE_STOCHASTIC_BOOST_LR = 1, // [1] Online StochBoost_LR
15 | ONLINE_STOCHASTIC_BOOST_MIL = 2, // [2] Online StochBoost_MIL
16 | ONLINE_ENSEMBLE_BOOST_MIL = 3, // [3] Online Ensemble_MIL
17 | ONLINE_ANY_BOOST_MIL = 4, // [4] ONLINE STOCHBOOST_MIL With anyboost
18 | };
19 |
20 | //Forward Declaration
21 | class StrongClassifierParametersBase;
22 | class AdaBoostClassifierParameters;
23 | class MILBoostClassifierParameters;
24 | class MILEnsembleClassifierParameters;
25 | class MILAnyBoostClassifierParameters;
26 |
27 | //declarations of shared ptr
28 | typedef boost::shared_ptr StrongClassifierParametersBasePtr;
29 | typedef boost::shared_ptr AdaBoostClassifierParametersPtr;
30 | typedef boost::shared_ptr MILBoostClassifierParametersPtr;
31 | typedef boost::shared_ptr MILEnsembleClassifierParametersPtr;
32 | typedef boost::shared_ptr MILAnyBoostClassifierParametersPtr;
33 |
34 | /****************************************************************
35 | StrongClassifierParametersBase
36 | Base class for all the strong classifier parameters.
37 | ****************************************************************/
38 | class StrongClassifierParametersBase
39 | {
40 | public:
41 | StrongClassifierParametersBase( const int numberOfSelectedWeakClassifiers,
42 | const int totalNumberOfWeakClassifiers,
43 | const float percentageOfRetainedWeakClassifiers = 0,
44 | const float learningRate = DEFAULT_GAUSSIAN_WEAK_CLASSIFIER_LEARNING_RATE,
45 | const bool storeFeatureHistory = DEFAULT_STRONG_CLASSIFIER_STORE_FEATURE_HISTORY )
46 | : m_featureParametersPtr( ),
47 | m_weakClassifierType( STUMP ),
48 | m_learningRate( learningRate ),
49 | m_storeFeatureHistory( storeFeatureHistory ),
50 | m_numberOfSelectedWeakClassifiers( numberOfSelectedWeakClassifiers ),
51 | m_totalNumberOfWeakClassifiers( totalNumberOfWeakClassifiers ),
52 | m_percentageOfRetainedWeakClassifiers( percentageOfRetainedWeakClassifiers/100.0f )
53 | {
54 | }
55 |
56 | virtual StrongClassifierType GetClassifierType( ) const = 0;
57 |
58 | Features::FeatureParametersPtr m_featureParametersPtr;
59 | WeakClassifierType m_weakClassifierType;
60 | float m_learningRate;
61 | bool m_storeFeatureHistory;
62 | int m_numberOfSelectedWeakClassifiers;
63 | int m_totalNumberOfWeakClassifiers;
64 | float m_percentageOfRetainedWeakClassifiers;
65 | };
66 |
67 | /****************************************************************
68 | AdaBoostClassifierParameters
69 | Ada boost classifier parameters.
70 | ****************************************************************/
71 | class AdaBoostClassifierParameters : public StrongClassifierParametersBase
72 | {
73 | public:
74 | AdaBoostClassifierParameters( const int numberOfSelectedWeakClassifiers,
75 | const int totalNumberOfWeakClassifiers )
76 | : StrongClassifierParametersBase( numberOfSelectedWeakClassifiers,
77 | totalNumberOfWeakClassifiers )
78 | {
79 | }
80 |
81 | virtual StrongClassifierType GetClassifierType( ) const { return ONLINE_ADABOOST; };
82 | };
83 |
84 | /****************************************************************
85 | MILBoostClassifierParameters
86 | MIL boost classifier parameters.
87 | ****************************************************************/
88 | class MILBoostClassifierParameters : public StrongClassifierParametersBase
89 | {
90 | public:
91 | MILBoostClassifierParameters( const int numberOfSelectedWeakClassifiers,
92 | const int totalNumberOfWeakClassifiers )
93 | : StrongClassifierParametersBase( numberOfSelectedWeakClassifiers,
94 | totalNumberOfWeakClassifiers )
95 | {
96 | }
97 |
98 | virtual StrongClassifierType GetClassifierType( )const { return ONLINE_STOCHASTIC_BOOST_MIL; };
99 | };
100 |
101 | /****************************************************************
102 | MILEnsembleClassifierParameters
103 | MIL Ensemble classifier parameters.
104 | ****************************************************************/
105 | class MILEnsembleClassifierParameters : public StrongClassifierParametersBase
106 | {
107 | public:
108 | MILEnsembleClassifierParameters( const int numberOfSelectedWeakClassifiers,
109 | const int totalNumberOfWeakClassifiers,
110 | const float percentageOfRetainedWeakClassifiers )
111 | : StrongClassifierParametersBase( numberOfSelectedWeakClassifiers,
112 | totalNumberOfWeakClassifiers,
113 | percentageOfRetainedWeakClassifiers )
114 | {
115 | }
116 | virtual StrongClassifierType GetClassifierType( ) const { return ONLINE_ENSEMBLE_BOOST_MIL; };
117 | };
118 |
119 | /****************************************************************
120 | MILAnyBoostClassifierParameters
121 | MIL Boost (AnyBoost) classifier parameters.
122 | ****************************************************************/
123 | class MILAnyBoostClassifierParameters : public StrongClassifierParametersBase
124 | {
125 | public:
126 | MILAnyBoostClassifierParameters( const int numberOfSelectedWeakClassifiers,
127 | const int totalNumberOfWeakClassifiers )
128 | : StrongClassifierParametersBase( numberOfSelectedWeakClassifiers,
129 | totalNumberOfWeakClassifiers )
130 | {
131 | }
132 |
133 | virtual StrongClassifierType GetClassifierType( ) const { return ONLINE_ANY_BOOST_MIL; };
134 | };
135 | }
136 | #endif
--------------------------------------------------------------------------------
/src/CommonMacros.h:
--------------------------------------------------------------------------------
1 | #ifndef COMMONMACROS
2 | #define COMMONMACROS
3 |
4 | #include "Public.h"
5 | #include "Config.h"
6 |
7 | //Template function to Check if the parameter is valid
8 | template
9 | T CheckIfValidParameter( bool predicate, T arg, int line, char* file )
10 | {
11 | if ( predicate )
12 | {
13 | return arg;
14 | }
15 | else
16 | {
17 | abortError( line, file, "Precondition Failed on Parameter" );
18 | }
19 | }
20 |
21 | #define EXCEPTION_CATCH_AND_ABORT(context) \
22 | catch( std::exception& ex ) \
23 | { \
24 | std::cerr << "Context: " << context << " Error Message:" << ex.what() << endl; \
25 | abortError( __LINE__, __FILE__, context ); \
26 | }
27 |
28 | #define EXCEPTION_CATCH_AND_LOG(context) \
29 | catch( std::exception& ex ) \
30 | { \
31 | g_logFile << "Context: " << context << " Error Message:" << ex.what() << endl; \
32 | }
33 |
34 | #if defined(WIN32) || defined(WIN64)
35 | #define ASSERT_TRUE( predicate ) \
36 | if ( (predicate) == false ) \
37 | { \
38 | DebugBreak(); \
39 | abortError( __LINE__, __FILE__, "Assertion Failed." ); \
40 | }
41 | #else
42 | #define ASSERT_TRUE( predicate ) \
43 | if ( (predicate) == false ) \
44 | { \
45 | abortError( __LINE__, __FILE__, "Assertion Failed." ); \
46 | }
47 | #endif
48 |
49 | #define ASSERT_PRECONDITION_PARAMETER( predicate, parameter ) \
50 | CheckIfValidParameter( predicate, parameter, __LINE__, __FILE__ )
51 |
52 | /* A macro to disallow the evil copy constructor and operator= functions
53 | This should be used in the private: declarations for a class */
54 | #define DISALLOW_EVIL_CONSTRUCTORS(TypeName) \
55 | TypeName(const TypeName&); \
56 | void operator=(const TypeName&)
57 |
58 | /*A macro to disallow all the implicit constructors, namely the
59 | default constructor, copy constructor and operator= functions.
60 | This should be used in the private: declarations for a class
61 | that wants to prevent anyone from instantiating it. This is
62 | especially useful for classes containing only static methods.*/
63 | #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
64 | TypeName(); \
65 | DISALLOW_EVIL_CONSTRUCTORS(TypeName)
66 |
67 | #define LOG( context ) \
68 | MultipleCameraTracking::g_logFile << context; \
69 | if ( MultipleCameraTracking::g_verboseMode ) \
70 | cout << context;
71 |
72 | #define LOG_CONSOLE( context ) \
73 | cout << context
74 |
75 | #endif
--------------------------------------------------------------------------------
/src/CultureColorHistogram.cpp:
--------------------------------------------------------------------------------
1 | #include "CultureColorHistogram.h"
2 |
3 | namespace Features
4 | {
5 | /****************************************************************
6 | CultureColorHistogram
7 | Initialize the feature
8 | Exception:
9 | None.
10 | ****************************************************************/
11 | void CultureColorHistogram::Generate( FeatureParametersPtr featureParametersPtr )
12 | {
13 | CultureColorHistogramParametersPtr temp = boost::dynamic_pointer_cast(featureParametersPtr);
14 | m_partPercentageVertical = temp->m_partPercentageVertical;
15 | m_numberOfParts = temp->m_numberOfParts;
16 | }
17 |
18 |
19 | /****************************************************************
20 | CultureColorHistogram
21 | Compute the feature for the sample
22 | Exception:
23 | None.
24 | ****************************************************************/
25 | void CultureColorHistogram::Compute( const Classifier::Sample& sample, vectorf& featureValueList ) const
26 | {
27 | uint scaled_height = cvRound( static_cast(sample.m_height) * sample.m_scaleY );
28 | uint scaled_width =cvRound( static_cast(sample.m_width) * sample.m_scaleX );
29 |
30 | if( sample.GetHSVImage() == NULL )
31 | {
32 | cv::Mat sampleImgHSV;
33 | // create HSV from sample image
34 | sample.GetColorImage()->createIpl(true);
35 | cv::Mat entireImg = sample.GetColorImage()->getIpl();
36 | cv::Rect roi( sample.m_col, sample.m_row, scaled_width, scaled_height );
37 | cv::Mat sampleImg = entireImg(roi);
38 | //cv::imshow(sampleImg, "testCultureColor");
39 | cv::cvtColor( sampleImg, sampleImgHSV, CV_BGR2HSV );
40 | ComputeFeature( sample, sampleImgHSV, featureValueList );
41 | }
42 | else
43 | {
44 | Matrixu * pImgHSV = sample.GetHSVImage();
45 |
46 | // Calculate the size for each part.
47 | vectori partRowList;
48 | int accum = 0, partEnd;
49 |
50 |
51 | partRowList.push_back( 0 );
52 | for (int i = 0; i < m_numberOfParts; i++)
53 | {
54 | accum += m_partPercentageVertical[i];
55 | partEnd = scaled_height*accum/100;
56 | ASSERT_TRUE ( partEnd > partRowList[i] );
57 | partRowList.push_back( partEnd );
58 | }
59 |
60 | // HSV Centroids:
61 | int numBins=11;
62 | // Red Pink purple blue green yellow orange brown bk gray white
63 | int HC[] = {5, 206, 181, 160, 81, 46, 28, 20, 110, 121, 133};
64 | //int SC[] = {206,168, 186, 215, 188, 219, 211, 137, 14, 8, 15};
65 | //int VC[] = {107,120, 117, 129, 104, 122, 137, 97, 2, 101, 237};
66 | int i, j, byte, H=0, S=0, V=0, DistanceToCentroids[11], minimumDist, CC_Histogram[11], indicator;
67 |
68 | // calculate histogram for each part
69 | for( int partIndex = 0; partIndex < m_numberOfParts; partIndex++ )
70 | {
71 | //initialization
72 | for( j = 1; j < numBins; j++)
73 | {
74 | CC_Histogram[j]=0;
75 | DistanceToCentroids[j] = 0;
76 | }
77 |
78 | for ( i = partRowList[partIndex]; i < partRowList[partIndex+1]; i++)
79 | {
80 | for ( j = 0; j < scaled_width; j++ )
81 | {
82 | minimumDist = 999999;
83 | H = (*pImgHSV)( i+sample.m_row, j+sample.m_col, 0 );
84 | //S = (*pImgHSV)( i+sample.m_row, j+sample.m_col, 1 );
85 | //V = (*pImgHSV)( i+sample.m_row, j+sample.m_col, 2 );
86 | for ( int c = 0; c < numBins; c++ )
87 | {
88 | DistanceToCentroids[c]=sqrt(
89 | (double)(H-HC[0])*(double)(H-HC[0])
90 | ); //hue channel only
91 | //+ long double(S-SC[0])*long double(S-SC[0])
92 | //+ long double(V-VC[0])*long double(V-VC[0])
93 |
94 | if( minimumDist > DistanceToCentroids[c] )
95 | {
96 | minimumDist = DistanceToCentroids[c];
97 | indicator = c;
98 | }
99 | }
100 | CC_Histogram[indicator]++;
101 | }
102 | }
103 | for( int c = 0; c < numBins; c++ )
104 | {
105 | featureValueList[partIndex*numBins + c]= CC_Histogram[c];
106 | }
107 | } //for each part
108 |
109 |
110 | }
111 | }
112 |
113 | /****************************************************************
114 | CultureColorHistogram
115 | Compute the feature from sample HSV image of format cv::Mat
116 | Exception:
117 | None.
118 | ****************************************************************/
119 | void CultureColorHistogram::ComputeFeature( const Classifier::Sample& sample, cv::Mat& sampleImgHSV, vectorf& featureValueList ) const
120 | {
121 | // Calculate the size for each part.
122 | vectori partRowList;
123 | int accum = 0, partEnd;
124 |
125 | partRowList.push_back( 0 );
126 | for (int i = 0; i < m_numberOfParts; i++)
127 | {
128 | accum += m_partPercentageVertical[i];
129 | partEnd = sample.m_height*accum/100;
130 | ASSERT_TRUE ( partEnd > partRowList[i] );
131 | partRowList.push_back( partEnd );
132 | }
133 |
134 | // HSV Centroids:
135 | int numBins=11;
136 | // Red Pink purple blue green yellow orange brown bk gray white
137 | int HC[] = {5, 206, 181, 160, 81, 46, 28, 20, 110, 121, 133};
138 | //int SC[] = {206,168, 186, 215, 188, 219, 211, 137, 14, 8, 15};
139 | //int VC[] = {107,120, 117, 129, 104, 122, 137, 97, 2, 101, 237};
140 | int i, j, byte, H=0, S=0, V=0, DistanceToCentroids[11], MinimumDist, CC_Histogram[11], indicator;
141 |
142 | // calculate histogram for each part
143 | for( int partIndex = 0; partIndex < m_numberOfParts; partIndex++ )
144 | {
145 | //initialization
146 | for( j = 1; j < numBins; j++)
147 | {
148 | CC_Histogram[j]=0;
149 | DistanceToCentroids[j] = 0;
150 | }
151 |
152 | for ( i = partRowList[partIndex]; i < partRowList[partIndex+1]; i++)
153 | {
154 | for ( j = 0; j < sample.m_width; j++ )
155 | {
156 | MinimumDist =999999;
157 | H = sampleImgHSV.at( i, j)[0];
158 | //S = sampleImgHSV.at( i, j)[1];
159 | //V = sampleImgHSV.at( i, j)[2];
160 | for ( int c = 0; c < numBins; c++ )
161 | {
162 | DistanceToCentroids[c]=sqrt(
163 | (double)(H-HC[0])*(double)(H-HC[0])
164 | ); //hue channel only
165 | //+ long double(S-SC[0])*long double(S-SC[0])
166 | //+ long double(V-VC[0])*long double(V-VC[0])
167 |
168 | if( MinimumDist > DistanceToCentroids[c] )
169 | {
170 | MinimumDist = DistanceToCentroids[c];
171 | indicator = c;
172 | }
173 | }
174 | CC_Histogram[indicator]++;
175 | }
176 | }
177 | for( int c = 0; c < numBins; c++ )
178 | {
179 | featureValueList[partIndex*numBins + c]= CC_Histogram[c];
180 | }
181 | } //for each part
182 |
183 | }
184 |
185 | }
186 |
--------------------------------------------------------------------------------
/src/CultureColorHistogram.h:
--------------------------------------------------------------------------------
1 | #ifndef CULTURE_COLOR
2 | #define CULTURE_COLOR
3 |
4 | #include "Feature.h"
5 |
6 | namespace Features
7 | {
8 | /****************************************************************
9 | CultureColorHistogram
10 | A multi dimensional culture color histogram obtained by dividing
11 | the blob into horizontal slices (parts) and concatenates the culture
12 | color histogram of each part
13 | ****************************************************************/
14 | class CultureColorHistogram : public Feature
15 | {
16 | public:
17 | CultureColorHistogram( ) { };
18 |
19 | virtual const FeatureType GetFeatureType() const { return CULTURE_COLOR_HISTOGRAM; };
20 |
21 | virtual float Compute( const Classifier::Sample& sample ) const
22 | { abortError( __LINE__, __FILE__, "CultureCoor is of more than one dimension" );; return 0.0f; }
23 |
24 | virtual void Compute( const Classifier::Sample& sample, vectorf& featureValueList ) const;
25 |
26 | virtual void Generate( FeatureParametersPtr featureParametersPtr );
27 |
28 | private:
29 | vectori m_partPercentageVertical; // a list of percentage (of total height) for each part, must add up to 100
30 | uint m_numberOfParts; // number of parts
31 | void ComputeFeature( const Classifier::Sample& sample, cv::Mat& sampleImgHSV, vectorf& featureValueList ) const;
32 | };
33 | }
34 | #endif
--------------------------------------------------------------------------------
/src/CultureColorHistogramFeatureVector.cpp:
--------------------------------------------------------------------------------
1 | #include "CultureColorHistogramFeatureVector.h"
2 | #include "CultureColorHistogram.h"
3 |
4 | namespace Features
5 | {
6 | /****************************************************************
7 | CultureColorHistogramFeatureVector::Generate
8 | Generates FeatureVector based on the specified feature type.
9 | Feature stores the culture color histogram.
10 | Note:parameter "numberOfFeatures" is not used as the size of feature vector
11 | is pre-determined.
12 | Exception:
13 | None
14 | ****************************************************************/
15 | void CultureColorHistogramFeatureVector::Generate( FeatureParametersPtr featureParametersPtr )
16 | {
17 | try
18 | {
19 | ASSERT_TRUE( featureParametersPtr != NULL );
20 |
21 | m_featureParametersPtr = featureParametersPtr;
22 |
23 | m_featurePtr = boost::shared_ptr( new CultureColorHistogram() );
24 |
25 | ASSERT_TRUE( m_featurePtr != NULL );
26 |
27 | m_numberOfCultureColorFeatures = m_featureParametersPtr->GetColorFeatureDimension( );
28 |
29 | m_featurePtr->Generate( m_featureParametersPtr );
30 |
31 | //Update the feature generated flag
32 | m_isFeatureGenerated = true;
33 |
34 | m_startingIndexForFeatureMatrix = m_featureParametersPtr->GetHaarFeatureDimension( );
35 | }
36 | EXCEPTION_CATCH_AND_ABORT( "Error While Generating CultureColorHistogram Feature Vector" );
37 | }
38 |
39 | /****************************************************************
40 | CultureColorHistogramFeatureVector::Compute
41 | Iterate over each sample in the given Classifier::SampleSet
42 | and compute the featurePtr. Store the computed featurePtr value
43 | in the featurePtr vector.
44 | Classifier calls this method with a set of samples for each type.
45 | Exception:
46 | None
47 | ****************************************************************/
48 | void CultureColorHistogramFeatureVector::Compute( Classifier::SampleSet& sampleSet, bool shouldResizeFeatureMatrix )
49 | {
50 | size_t numberOfSamples = sampleSet.Size( );
51 |
52 | ASSERT_TRUE( m_isFeatureGenerated == true );
53 | ASSERT_TRUE( m_numberOfCultureColorFeatures > 0 );
54 |
55 | //return if no sample is available
56 | if ( numberOfSamples == 0 )
57 | {
58 | return;
59 | }
60 |
61 | if ( shouldResizeFeatureMatrix )
62 | {
63 | //resize the feature matrix size to the number of features
64 | sampleSet.ResizeFeatures( m_numberOfCultureColorFeatures );
65 | }
66 |
67 | #pragma omp parallel for
68 | for ( int sampleIndex = 0; sampleIndex < numberOfSamples; sampleIndex++ )
69 | {
70 | vectorf histVector( m_numberOfCultureColorFeatures, 0.0f );
71 | m_featurePtr->Compute( sampleSet[sampleIndex], histVector );
72 |
73 | ASSERT_TRUE( histVector.size( ) == m_numberOfCultureColorFeatures );
74 |
75 | for ( uint featureIndex = m_startingIndexForFeatureMatrix; featureIndex < (m_startingIndexForFeatureMatrix+m_numberOfCultureColorFeatures); featureIndex++ )
76 | {
77 | //store the feature value in the feature matrix
78 | sampleSet.GetFeatureValue( sampleIndex, featureIndex ) = histVector[featureIndex];
79 | }
80 | }
81 | }
82 | }
--------------------------------------------------------------------------------
/src/CultureColorHistogramFeatureVector.h:
--------------------------------------------------------------------------------
1 | #ifndef CULTURE_COLOR_FEATURE_VECTOR_H
2 | #define CULTURE_COLOR_FEATURE_VECTOR_H
3 |
4 | #include "FeatureVector.h"
5 |
6 | namespace Features
7 | {
8 | /****************************************************************
9 | CultureColorHistogramFeatureVector
10 | This is a wrapper class for CultureColorHistogram.
11 | ****************************************************************/
12 | class CultureColorHistogramFeatureVector :virtual public FeatureVector
13 | {
14 | public:
15 | virtual void Generate( FeatureParametersPtr featureParametersPtr );
16 | virtual void Compute( Classifier::SampleSet& sampleSet, bool shouldResizeFeatureMatrix = true );
17 | virtual void SaveVisualizedFeatureVector( const char *dirName ){}
18 |
19 |
20 | virtual const uint GetNumberOfFeatures( ) const { return m_numberOfCultureColorFeatures; }
21 |
22 | private:
23 | FeaturePtr m_featurePtr;
24 | uint m_numberOfCultureColorFeatures;
25 | uint m_startingIndexForFeatureMatrix;
26 | };
27 | }
28 | #endif
--------------------------------------------------------------------------------
/src/DefaultParameters.h:
--------------------------------------------------------------------------------
1 | #ifndef H_DEFAULT_PARAMS
2 | #define H_DEFAULT_PARAMS
3 |
4 | namespace MultipleCameraTracking
5 | {
6 | //default classifier parameters
7 | // #define DEFAULT_TRACKER_INIT_NEG_NUM_TRAIN 65 //default value for SimpleTrackerParameters.m_init_negNumTrain
8 | // #define DEFAULT_TRACKER_INIT_POS_RADIUS_TRAIN 3.0F //default value for SimpleTrackerParameters.m_init_posTrainRadius
9 | #define DEFAULT_TRACKER_INIT_WITH_FACE false //default value for SimpleTrackerParameters.m_initWithFace
10 | #define DEFAULT_TRACKER_DEBUGV false //default value for SimpleTrackerParameters.m_debugv
11 |
12 | #define DEFAULT_PFTRACKER_NOT_USE_SIGMOIDAL true //default TrackerParameters.m_shouldNotUseSigmoid for PFTracker, i.e. use sigmoid function to calculate probability
13 |
14 | #define DEFAULT_HAAR_MINIMUM_NUMBER_OF_RECTANGLES 2
15 | #define DEFAULT_HAAR_MAXIMUM_NUMBER_OF_RECTANGLES 6
16 | #define DEFAULT_HAAR_NUMBER_OF_CHANNELS -1
17 |
18 | #define DEFAULT_GAUSSIAN_WEAK_CLASSIFIER_LEARNING_RATE 0.85f
19 | #define DEFAULT_STRONG_CLASSIFIER_STORE_FEATURE_HISTORY true
20 | }
21 | #endif
--------------------------------------------------------------------------------
/src/Exception.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | namespace Exception
5 | {
6 | /****************************************************************
7 | AssertionFailed
8 | ****************************************************************/
9 | class AssertionFailed: public std::exception
10 | {
11 | AssertionFailed( const unsigned int lineNumber,
12 | const char* fileName,
13 | const char* errorMessage )
14 | : std::exception( ),
15 | m_lineNumber( lineNumber ),
16 | m_fileName( fileName ),
17 | m_errorMessage( errorMessage )
18 | {
19 | }
20 |
21 | virtual const char* what( ) const throw( )
22 | {
23 | return m_errorMessage;
24 | }
25 |
26 | private:
27 | const unsigned int m_lineNumber;
28 | const char* m_fileName;
29 | const char* m_errorMessage;
30 | };
31 |
32 | /****************************************************************
33 | PreconditionFailed
34 | ****************************************************************/
35 | class PreconditionFailed: public std::exception
36 | {
37 | PreconditionFailed( const unsigned int lineNumber,
38 | const char* fileName,
39 | const char* errorMessage )
40 | : std::exception( ),
41 | m_lineNumber( lineNumber ),
42 | m_fileName( fileName ),
43 | m_errorMessage( errorMessage )
44 | {
45 | }
46 |
47 | virtual const char* what( ) const throw( )
48 | {
49 | return m_errorMessage;
50 | }
51 |
52 | private:
53 | const unsigned int m_lineNumber;
54 | const char* m_fileName;
55 | const char* m_errorMessage;
56 | };
57 |
58 | /****************************************************************
59 | ConfigurationParameterNotFound
60 | ****************************************************************/
61 | class ConfigurationParameterNotFound : public std::exception
62 | {
63 | ConfigurationParameterNotFound( const char* parameterName,
64 | const unsigned int lineNumber,
65 | const char* fileName,
66 | const char* errorMessage )
67 | : std::exception( ),
68 | m_parameterName( parameterName ),
69 | m_lineNumber( lineNumber ),
70 | m_fileName( fileName ),
71 | m_errorMessage( errorMessage )
72 | {
73 | }
74 |
75 | virtual const char* what( ) const throw( )
76 | {
77 | return m_errorMessage;
78 | }
79 |
80 | private:
81 | const unsigned int m_lineNumber;
82 | const char* m_fileName;
83 | const char* m_errorMessage;
84 | const char* m_parameterName;
85 | };
86 | }
87 |
--------------------------------------------------------------------------------
/src/Feature.h:
--------------------------------------------------------------------------------
1 | #ifndef H_IMGFTR
2 | #define H_IMGFTR
3 |
4 | #include "FeatureParameters.h"
5 | #include "Matrix.h"
6 | #include "Public.h"
7 | #include "SampleSet.h"
8 | #include "CommonMacros.h"
9 |
10 | #include
11 |
12 | namespace Features
13 | {
14 | //Forward Declaration
15 | class Feature;
16 | class FeatureVector;
17 |
18 | typedef boost::shared_ptr FeaturePtr;
19 | typedef vector FeatureList;
20 |
21 | /****************************************************************
22 | Feature
23 | Base class for Feature.
24 | ****************************************************************/
25 | class Feature
26 | {
27 | public:
28 |
29 | //Pure Virtual function
30 | virtual const FeatureType GetFeatureType( ) const = 0;
31 |
32 | //create (initialize) a feature instance from associated feature parameters
33 | virtual void Generate( FeatureParametersPtr featureParametersPtr ) = 0;
34 |
35 | //compute the feature value for the given sample (for one-dim feature vector)
36 | virtual float Compute( const Classifier::Sample& sample ) const = 0;
37 |
38 | //compute the feature value for the given sample (for multi-dim feature vector)
39 | virtual void Compute( const Classifier::Sample& sample, vectorf& featureValueList ) const = 0;
40 |
41 | //visualize the feature for debugging
42 | virtual Matrixu ToVisualize( int featureIndex = -1 ) { Matrixu empty; return empty; };
43 | };
44 | }
45 | #endif
--------------------------------------------------------------------------------
/src/FeatureParameters.cpp:
--------------------------------------------------------------------------------
1 | #include "FeatureParameters.h"
2 | #include "DefaultParameters.h"
3 |
4 | namespace Features
5 | {
6 | /****************************************************************
7 | HaarFeatureParameters: Haar-Like Feature Parameters
8 | Default Constructor
9 | ****************************************************************/
10 | HaarFeatureParameters::HaarFeatureParameters( uint featureDimensionHaar )
11 | : m_minimumNumberOfRectangles ( DEFAULT_HAAR_MINIMUM_NUMBER_OF_RECTANGLES ),
12 | m_maximumNumberOfRectangles ( DEFAULT_HAAR_MAXIMUM_NUMBER_OF_RECTANGLES ),
13 | m_numberOfChannels( DEFAULT_HAAR_NUMBER_OF_CHANNELS ),
14 | m_featureDimensionHaar( featureDimensionHaar )
15 | {
16 | for ( int channelIndex = 0; channelIndex < 1024; channelIndex++ )
17 | {
18 | m_useChannels[channelIndex] = -1;
19 | }
20 | m_useChannels[0] = 0;
21 | }
22 |
23 | /****************************************************************
24 | CultureColorHistogramParameters
25 | Default Constructor (single part)
26 | ****************************************************************/
27 | CultureColorHistogramParameters::CultureColorHistogramParameters( )
28 | : m_numberOfParts(1),
29 | m_featureDimensionForCultureColor( DEFAULT_CULTURE_COLOR_DIM ),
30 | m_partPercentageVertical( 1, 100 )
31 | {
32 |
33 | }
34 |
35 | /****************************************************************
36 | CultureColorHistogramParameters
37 | Constructor with exact part information ( a list of percentages)
38 | ****************************************************************/
39 | CultureColorHistogramParameters::CultureColorHistogramParameters( vectori partPercentageVertical )
40 | : m_numberOfParts( partPercentageVertical.size() ),
41 | m_featureDimensionForCultureColor( partPercentageVertical.size()*DEFAULT_CULTURE_COLOR_DIM ),
42 | m_partPercentageVertical( partPercentageVertical )
43 | {
44 | int count = 0;
45 | for (int i=0; i < partPercentageVertical.size(); i++)
46 | {
47 | ASSERT_TRUE(partPercentageVertical[i] > 0);
48 | count += partPercentageVertical[i];
49 | }
50 |
51 | ASSERT_TRUE(count == 100);
52 | }
53 | }
--------------------------------------------------------------------------------
/src/FeatureParameters.h:
--------------------------------------------------------------------------------
1 | #ifndef H_FEATURE_PARAMETERS
2 | #define H_FEATURE_PARAMETERS
3 |
4 | #define DEFAULT_CULTURE_COLOR_DIM 11
5 | #define COLOR_NUM_PARTS 1 //1, 2, etc.
6 | #include "Public.h"
7 | #include "CommonMacros.h"
8 | #include
9 |
10 | namespace Features
11 | {
12 | enum FeatureType { HAAR_LIKE = 0,
13 | CULTURE_COLOR_HISTOGRAM = 1,
14 | MULTI_DIMENSIONAL_COLOR_HISTOGRAM = 2,
15 | HAAR_COLOR_HISTOGRAM = 3,
16 | };
17 |
18 | //Forward Declaration
19 | class FeatureParameters;
20 | class HaarFeatureParameters;
21 | class MultiDimensionalColorHistogramParameters;
22 | class CultureColorHistogramParameters;
23 | class HaarAndColorHistogramFeatureParameters;
24 |
25 | //typedef
26 | typedef boost::shared_ptr FeatureParametersPtr;
27 | typedef boost::shared_ptr HaarFeatureParametersPtr;
28 | typedef boost::shared_ptr MultiDimensionalColorHistogramParametersPtr;
29 | typedef boost::shared_ptr CultureColorHistogramParametersPtr;
30 | typedef boost::shared_ptr HaarAndColorHistogramFeatureParametersPtr;
31 |
32 | /*****************************************************************
33 | FeatureParameters
34 | Abstract class for feature parameters.
35 | ****************************************************************/
36 | class FeatureParameters
37 | {
38 | public:
39 | virtual FeatureType GetFeatureType( ) const = 0;
40 | virtual uint GetFeatureDimension( ) const = 0;
41 |
42 | virtual uint GetColorFeatureDimension( ) const = 0;
43 | virtual uint GetHaarFeatureDimension( ) const = 0;
44 |
45 | uint m_width; // original width of the rectangular blob on which the feature is calculated
46 | uint m_height; // original height of the rectangular blob on which the feature is calculated
47 | };
48 |
49 | /****************************************************************
50 | HaarFeatureParameters
51 | General Haar Feature Parameters
52 | ****************************************************************/
53 | class HaarFeatureParameters : virtual public FeatureParameters
54 | {
55 | public:
56 | HaarFeatureParameters( uint featureDimensionHaar );
57 |
58 | virtual FeatureType GetFeatureType() const { return HAAR_LIKE; }
59 |
60 | virtual uint GetFeatureDimension( ) const { return m_featureDimensionHaar; }
61 |
62 | virtual uint GetColorFeatureDimension( ) const { return 0;}
63 | virtual uint GetHaarFeatureDimension( ) const { return m_featureDimensionHaar; }
64 |
65 | friend class HaarFeature;
66 |
67 | protected:
68 | uint m_maximumNumberOfRectangles;
69 | uint m_minimumNumberOfRectangles;
70 | int m_useChannels[1024]; // >=0: used; <0:not used
71 | int m_numberOfChannels; // number of channels used for the computation of feature
72 | uint m_featureDimensionHaar;
73 | };
74 |
75 | /****************************************************************
76 | MultiDimensionalColorHistogramParameters
77 | Multi Dimensional Color Histogram Parameters
78 | ****************************************************************/
79 | class MultiDimensionalColorHistogramParameters : virtual public FeatureParameters
80 | {
81 | public:
82 | MultiDimensionalColorHistogramParameters( bool useHSVColor = false, uint numberOfBins = 8 )
83 | : m_numberOfBins (numberOfBins),
84 | m_numberOfParts( COLOR_NUM_PARTS ),
85 | m_partPercentageVertical( COLOR_NUM_PARTS, 100/COLOR_NUM_PARTS ),
86 | m_featureDimensionColor( numberOfBins * numberOfBins * numberOfBins * m_numberOfParts ),
87 | m_useHSVColorSpace( useHSVColor )
88 | {
89 |
90 | }
91 |
92 | virtual FeatureType GetFeatureType( ) const { return MULTI_DIMENSIONAL_COLOR_HISTOGRAM; };
93 | virtual uint GetFeatureDimension( ) const { return m_featureDimensionColor; }
94 |
95 | virtual uint GetColorFeatureDimension( ) const { return m_featureDimensionColor;}
96 | virtual uint GetHaarFeatureDimension( ) const { return 0; }
97 |
98 | friend class MultiDimensionalColorHistogram;
99 |
100 | protected:
101 | const uint m_numberOfBins; //number of bins for each color
102 | const vectori m_partPercentageVertical; // a list of percentage (of total height) for each part, must add up to 100
103 | const uint m_numberOfParts; // number of parts
104 | const uint m_featureDimensionColor;
105 | const bool m_useHSVColorSpace; // use HSV instead of RGB
106 | };
107 |
108 | /****************************************************************
109 | CultureColorHistogramParameters
110 | Multi-part Culture Color Histogram Parameters
111 | ****************************************************************/
112 | class CultureColorHistogramParameters : virtual public FeatureParameters
113 | {
114 | public:
115 | CultureColorHistogramParameters( );
116 | CultureColorHistogramParameters( vectori partPercentage );
117 | virtual FeatureType GetFeatureType() const { return CULTURE_COLOR_HISTOGRAM; }
118 | virtual uint GetFeatureDimension( ) const { return m_featureDimensionForCultureColor; }
119 |
120 | virtual uint GetColorFeatureDimension( ) const { return m_featureDimensionForCultureColor;}
121 | virtual uint GetHaarFeatureDimension( ) const { return 0; }
122 |
123 | friend class CultureColorHistogram;
124 |
125 | private:
126 | const vectori m_partPercentageVertical; // a list of percentage (of total height) for each part, must add up to 100
127 | const uint m_numberOfParts; // number of parts
128 | const uint m_featureDimensionForCultureColor; // total number of feature dimension
129 | };
130 |
131 | /****************************************************************
132 | HaarAndColorHistogramFeatureParameters
133 | HaarAndColorHistogramFeatureParameters
134 | ****************************************************************/
135 | class HaarAndColorHistogramFeatureParameters : public HaarFeatureParameters,
136 | public MultiDimensionalColorHistogramParameters
137 | {
138 | public:
139 | HaarAndColorHistogramFeatureParameters( uint featureDimensionHaar, bool useHSVColor = false, uint numberOfBins = 8 )
140 | : HaarFeatureParameters( featureDimensionHaar ),
141 | MultiDimensionalColorHistogramParameters( useHSVColor, numberOfBins )
142 | {}
143 |
144 | virtual FeatureType GetFeatureType( ) const { return HAAR_COLOR_HISTOGRAM; };
145 | virtual uint GetFeatureDimension( ) const { return (m_featureDimensionHaar+m_featureDimensionColor); }
146 | virtual uint GetColorFeatureDimension( ) const { return m_featureDimensionColor; }
147 | virtual uint GetHaarFeatureDimension( ) const { return m_featureDimensionHaar; }
148 | };
149 | }
150 | #endif
--------------------------------------------------------------------------------
/src/FeatureVector.h:
--------------------------------------------------------------------------------
1 | #ifndef FEATURE_VECTOR_H
2 | #define FEATURE_VECTOR_H
3 |
4 | #include "FeatureParameters.h"
5 | #include "Feature.h"
6 | #include "SampleSet.h"
7 | #include "CommonMacros.h"
8 |
9 | namespace Features
10 | {
11 | //Forward Declarations
12 | class FeatureVector;
13 | class HaarFeatureVector;
14 | class MultiDimensionalColorHistogramFeatureVector;
15 | class CultureColorHistogramFeatureVector;
16 | class HaarAndColorHistogramFeatureVector;
17 |
18 | typedef boost::shared_ptr FeatureVectorPtr;
19 | typedef boost::shared_ptr HaarFeatureVectorPtr;
20 | typedef boost::shared_ptr MultiDimensionalColorHistogramFeatureVectorPtr;
21 | typedef boost::shared_ptr CultureColorHistogramFeatureVectorPtr;
22 | typedef boost::shared_ptr HaarAndColorHistogramFeatureVectorPtr;
23 |
24 | /****************************************************************
25 | FeatureVector
26 | This is a wrapper class for features.
27 | ****************************************************************/
28 | class FeatureVector
29 | {
30 | public:
31 | FeatureVector( )
32 | : m_featureParametersPtr( ),
33 | m_isFeatureGenerated( false )
34 | {
35 | }
36 |
37 | //Pure virtual functions
38 | virtual void Generate( FeatureParametersPtr featureParametersPtr ) = 0;
39 | virtual void Compute( Classifier::SampleSet& sampleSet, bool shouldResizeFeatureMatrix = true ) = 0;
40 | virtual void SaveVisualizedFeatureVector( const char *dirName ) = 0;
41 |
42 | virtual const uint GetNumberOfFeatures( ) const = 0;
43 |
44 | protected:
45 | FeatureParametersPtr m_featureParametersPtr;
46 | bool m_isFeatureGenerated;
47 | };
48 | }
49 | #endif
--------------------------------------------------------------------------------
/src/GeometryBasedInformationFuser.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | Information fusion based on Expectation Maximization Algorithm in OpenCV
3 | http://opencv.willowgarage.com/documentation/expectation-maximization.html
4 | ********************************************************************************/
5 | #ifndef GEOMETRIC_INFORMATION_FUSER
6 | #define GEOMETRIC_INFORMATION_FUSER
7 |
8 | #include "Matrix.h"
9 | #include "Config.h"
10 | #include "CommonMacros.h"
11 |
12 | #include "ml.h"
13 | #include "highgui.h"
14 | #include "math.h"
15 |
16 | #include
17 |
18 | #define MAX_NUMBER_CAMERA_COLORS 5
19 |
20 | namespace MultipleCameraTracking
21 | {
22 | /***************************************************************************
23 | GeometryBasedInformationFuser
24 |
25 | GeometryBasedInformationFuser fuses information from multiple cameras.
26 | It uses Kalman filter to fuse information from multiple cameras.
27 | It fits a GMM over the shared particles and re-weights the particles
28 | based on GMM distribution.
29 |
30 | Reference:
31 | http://vision.ece.ucsb.edu/publications/view_abstract.cgi?357
32 | ****************************************************************************/
33 | class GeometryBasedInformationFuser
34 | {
35 | public:
36 |
37 | enum GroundPlaneMeasurmentType { HIGHEST_WEIGHT_CLUSTER = 0,
38 | WEIGHTED_AVERAGE_OF_CLUSTERS = 1,
39 | PRINCIPAL_AXIS_INTERSECTION = 2,
40 | };
41 |
42 | GeometryBasedInformationFuser( const unsigned int numberOfCamera,
43 | CvMat* particles,
44 | GroundPlaneMeasurmentType groundPlaneMeasurementType,
45 | vector homographyMatrixList );
46 | ~GeometryBasedInformationFuser( );
47 |
48 |
49 | GroundPlaneMeasurmentType GetGroundPlaneMeasurementType( ){ return m_groundPlaneMeasurementType; }
50 |
51 | void FuseInformation( CvMat* pParticlesMatrix );
52 |
53 | CvMat* GetGroundPlaneKalmanMeanMatrix( int index );
54 | CvMat* GetGroundPlaneKalmanCovarianceMatrix( );
55 |
56 | Matrixu* DisplayOriginalGroundParticles( CvMat* particles, int frameInd = -1 ) ;
57 | Matrixu* DisplayKalmanFilterPdf( CvMat* pMeanMatrix, CvMat* pCovarianceMatrix, int frameInd = -1 );
58 | Matrixu* DisplayGMMGroundParticles( int frameInd = -1, CvMat* particles=NULL );
59 |
60 | //static methods
61 | static void CopyMatrix( CvMat* pSourceMatrix,
62 | CvMat* pDestinationMatrix,
63 | int sourceStartRowIndex = 0,
64 | int destinationStartRowIndex = 0,
65 | int option = 0 );
66 |
67 | static float MultiVariateNormalPdf( CvMat* dataVector, CvMat* meanVector, CvMat* covarianceMatrix );
68 |
69 | //Project the Particles to Ground Plane using the Homography
70 | static CvMat* TransformWithHomography( CvMat* particles, CvMat* pHomographyMatrix );
71 |
72 | //estimate ground plane positions from principle axis
73 | static vectord EstimateGroundPlanePrincipleAxisIntersection( CvMat* pPixelMatrix,
74 | vector homographyMatrixList );
75 | private:
76 |
77 | DISALLOW_IMPLICIT_CONSTRUCTORS( GeometryBasedInformationFuser );
78 |
79 | //set the default EM parameters
80 | void SetDefaultEMParameters( );
81 |
82 | //initialize the Kalman Filter
83 | void InitializeKalman( CvMat* particles );
84 |
85 | //Update the Kalman Filter
86 | void UpdateKalmanFilter( CvMat* measurement, CvMat* measurementCov =NULL );
87 |
88 | //Fuse information by picking the best cluster for measurement
89 | void FuseInformationByPickingTheBestCluster( CvMat* pParticlesMatrix );
90 |
91 | //Fuse information by using weighted average for measurement
92 | void FuseInformationByAveragingClusters( CvMat* pParticlesMatrix );
93 |
94 | //Fuse information using the principal axis intersection
95 | void FuseInformationByUsingPrincipalAxisIntersection( CvMat* pParticlesMatrix );
96 |
97 | //given a point on the ground plane, find its corresponding position on the ground plane image
98 | void MetricToPixels( float xPosFeet, float yPosFeet, int * xPosPixel, int * yPosPixel );
99 |
100 | //given a pixel on the ground plane image, find its corresponding position on the ground plane
101 | void PixelsToMetric( float * xPosFeet, float * yPosFeet, int xPosPixel, int yPosPixel );
102 |
103 | //initialize the ground plane display
104 | void InitializeGroundplaneDisplay( );
105 |
106 | CvEM m_emModel; //EM Model
107 | CvEMParams m_emParamters; //Parameters of the expectation maximization algorithm
108 | CvKalman* m_pKalman; //Kalman Filter
109 | const unsigned int m_numberOfClusters; //Number of Clusters or Gaussian
110 | unsigned int m_numberOfCameras; //Number of Cameras to be fused
111 | //member variables for display purpose
112 | Matrixu m_colorMatrix; //hold the colors to use for different cameras
113 | Matrixu m_GroundPlaneDisplayMatrix;
114 | Matrixu m_GroundPlaneDisplayMatrixKF;
115 | Matrixu m_GroundPlaneDisplayMatrixGMM;
116 | GroundPlaneMeasurmentType m_groundPlaneMeasurementType;
117 | vector m_homographyMatrixList;
118 | };
119 |
120 | //typedef for a boost pointer
121 | typedef boost::shared_ptr GeometryBasedInformationFuserPtr;
122 | typedef std::vector GeometryBasedInformationFuserPtrList;
123 | }
124 | #endif
125 |
--------------------------------------------------------------------------------
/src/HaarAndColorHistogramFeatureVector.cpp:
--------------------------------------------------------------------------------
1 | #include "HaarAndColorHistogramFeatureVector.h"
2 | #include "HaarFeature.h"
3 | #include "MultiDimensionalColorHistogram.h"
4 |
5 | namespace Features
6 | {
7 | /****************************************************************
8 | HaarAndColorHistogramFeatureVector::Generate
9 | Exception:
10 | None
11 | ****************************************************************/
12 | void HaarAndColorHistogramFeatureVector::Generate( FeatureParametersPtr featureParametersPtr )
13 | {
14 | try
15 | {
16 | //Call Generate Features of the HaarFeatureVector
17 | HaarFeatureVector::Generate( featureParametersPtr );
18 | MultiDimensionalColorHistogramFeatureVector::Generate( featureParametersPtr );
19 |
20 | m_numberOfHaarColorFeatures = m_numberOfHaarFeatures + m_numberOfColorFeatures;
21 |
22 | ASSERT_TRUE( m_numberOfHaarColorFeatures > 0 );
23 | }
24 | EXCEPTION_CATCH_AND_ABORT( "Error While Generating MultiDimensionalColorHistogram Feature Vector" );
25 | }
26 |
27 | /****************************************************************
28 | HaarAndColorHistogramFeatureVector::Compute
29 |
30 | Exception:
31 | None
32 | ****************************************************************/
33 | void HaarAndColorHistogramFeatureVector::Compute( Classifier::SampleSet& sampleSet, bool /*shouldResizeFeatureMatrix*/ )
34 | {
35 | try
36 | {
37 | //resize the feature matrix for efficiency
38 | sampleSet.ResizeFeatures( m_numberOfHaarColorFeatures );
39 |
40 | HaarFeatureVector::Compute( sampleSet, false/*shouldResizeFeatureMatrix*/ );
41 | MultiDimensionalColorHistogramFeatureVector::Compute( sampleSet, false/*shouldResizeFeatureMatrix*/ );
42 | }
43 | EXCEPTION_CATCH_AND_ABORT( "Error While Generating MultiDimensionalColorHistogram Feature Vector" );
44 | }
45 | }
--------------------------------------------------------------------------------
/src/HaarAndColorHistogramFeatureVector.h:
--------------------------------------------------------------------------------
1 | #ifndef HAAR_COLOR_FEATURE_VECTOR_H
2 | #define HAAR_COLOR_FEATURE_VECTOR_H
3 |
4 | #include "FeatureVector.h"
5 | #include "HaarFeatureVector.h"
6 | #include "MultiDimensionalColorHistogramFeatureVector.h"
7 |
8 | namespace Features
9 | {
10 | /****************************************************************
11 | HaarAndColorHistogramFeatureVector
12 | This is a wrapper class for HaarAndColorHistogramFeatureVector.
13 | ****************************************************************/
14 | class HaarAndColorHistogramFeatureVector : public HaarFeatureVector,
15 | public MultiDimensionalColorHistogramFeatureVector
16 | {
17 | public:
18 |
19 | virtual void Generate( FeatureParametersPtr featureParametersPtr );
20 | virtual void Compute( Classifier::SampleSet& sampleSet, bool shouldResizeFeatureMatrix = true );
21 | virtual void SaveVisualizedFeatureVector( const char *dirName ){}
22 |
23 | virtual const uint GetNumberOfFeatures( ) const
24 | {
25 | ASSERT_TRUE( m_numberOfHaarColorFeatures != 0 ); return m_numberOfHaarColorFeatures;
26 | }
27 |
28 | private:
29 | uint m_numberOfHaarColorFeatures;
30 | };
31 | }
32 | #endif
--------------------------------------------------------------------------------
/src/HaarFeature.cpp:
--------------------------------------------------------------------------------
1 | #include "HaarFeature.h"
2 |
3 | namespace Features
4 | {
5 | /****************************************************************
6 | HaarFeature::HaarFeature
7 | Constructor
8 | Exception:
9 | None
10 | ****************************************************************/
11 | HaarFeature::HaarFeature( )
12 | : m_channel( 0 )
13 | {
14 | m_width = 0;
15 | m_height = 0;
16 | }
17 |
18 | /****************************************************************
19 | HaarFeature::Generate
20 | Generate a Haar Feature based on the haar feature parameters
21 | (the rectangles and their weights are randomly generated)
22 | Exception:
23 | None
24 | ****************************************************************/
25 | void HaarFeature::Generate( FeatureParametersPtr featureParametersPtr )
26 | {
27 | ASSERT_TRUE( featureParametersPtr != NULL );
28 |
29 | //type cast to haar featurePtr
30 | HaarFeatureParametersPtr haarFeatureParametersPtr = boost::dynamic_pointer_cast( featureParametersPtr );
31 |
32 | m_width = haarFeatureParametersPtr->m_width;
33 | m_height = haarFeatureParametersPtr->m_height;
34 | m_maxSum = 0.0f;
35 |
36 | //choose the random number of rectangles for Haar Feature Generation
37 | int numberOfRectangles = randint(haarFeatureParametersPtr->m_minimumNumberOfRectangles, haarFeatureParametersPtr->m_maximumNumberOfRectangles );
38 | m_rects.resize( numberOfRectangles );
39 | m_weights.resize( numberOfRectangles );
40 | m_rsums.resize( numberOfRectangles );
41 |
42 | for ( int rectangleIndex=0; rectangleIndex < numberOfRectangles; rectangleIndex++ )
43 | {
44 | m_weights[rectangleIndex] = randfloat( )*2 - 1;
45 | m_rects[rectangleIndex].x = randint( 0,(uint)(haarFeatureParametersPtr->m_width-3) );
46 | m_rects[rectangleIndex].y = randint( 0,(uint)(haarFeatureParametersPtr->m_height-3) );
47 | m_rects[rectangleIndex].width = randint(1,(haarFeatureParametersPtr->m_width-m_rects[rectangleIndex].x-2));
48 | m_rects[rectangleIndex].height = randint(1 ,(haarFeatureParametersPtr->m_height-m_rects[rectangleIndex].y-2));
49 | m_rsums[rectangleIndex] = abs( m_weights[rectangleIndex] * (m_rects[rectangleIndex].width+1)*(m_rects[rectangleIndex].height+1)*255);
50 |
51 | ASSERT_TRUE( m_rects[rectangleIndex].x >=0 &&
52 | m_rects[rectangleIndex].y>= 0 &&
53 | m_rects[rectangleIndex].width > 0 &&
54 | m_rects[rectangleIndex].height > 0
55 | )
56 | }
57 |
58 | if ( haarFeatureParametersPtr->m_numberOfChannels < 0 )
59 | {
60 | haarFeatureParametersPtr->m_numberOfChannels = 0;
61 |
62 | for( int k=0; k < 1024; k++ )
63 | {
64 | haarFeatureParametersPtr->m_numberOfChannels += haarFeatureParametersPtr->m_useChannels[k]>=0;
65 | }
66 | }
67 |
68 | m_channel = haarFeatureParametersPtr->m_useChannels[randint(0,haarFeatureParametersPtr->m_numberOfChannels-1)];
69 | }
70 |
71 | /****************************************************************
72 | Feature::ToVisualize
73 | Visualize the Haar-Like feature
74 | Return an image.
75 | Exception:
76 | None
77 | *******************************************************************/
78 | Matrixu HaarFeature::ToVisualize( int featureIndex )
79 | {
80 | Matrixu v(m_height,m_width,3);
81 | v.Set(0);
82 | v._keepIpl = true;
83 |
84 | for( uint k=0; k= 0 )
95 | {
96 | v.display( ("HaarFeature-" + int2str(featureIndex,3)).c_str(), 2 );
97 | cvWaitKey(1);
98 | }
99 |
100 | v._keepIpl = false;
101 |
102 | return v;
103 | }
104 |
105 | /****************************************************************
106 | HaarFeature::Compute
107 | Computes Haar-Like features and stores it in the sampleSet.
108 | Exception:
109 | None
110 | ****************************************************************/
111 | inline float HaarFeature::Compute( const Classifier::Sample& sample ) const
112 | {
113 | //Integral image should be initialized
114 | if ( !sample.m_pImgGray->isInitII() )
115 | {
116 | abortError(__LINE__,__FILE__,"Integral image not initialized before called Compute()");
117 | }
118 |
119 | IppiRect r;
120 | float sum = 0.0f;
121 |
122 | for ( int k=0; k<(int)m_rects.size(); k++ )
123 | {
124 | r = m_rects[k]; // the rectangle in the original scale
125 | //find the scaled rectangle
126 | r.x = cvRound( float(r.x) * sample.m_scaleX ) + sample.m_col;//r.x += sample.m_col;
127 | r.y = cvRound( float(r.y) * sample.m_scaleY ) + sample.m_row;//r.y += sample.m_row;
128 | r.height = cvRound( float(r.height) * sample.m_scaleY );
129 | r.width = cvRound( float(r.width) * sample.m_scaleX );
130 |
131 | sum += m_weights[k] * sample.m_pImgGray->sumRect( r, m_channel );
132 | }
133 |
134 | /* r.x = sample.m_col;
135 | r.y = sample.m_row;
136 | r.width = (int)sample.m_weight;
137 | r.height = (int)sample.m_height; */
138 |
139 | //return (float)(sum);
140 | return (float)(sum/(sample.m_scaleX*sample.m_scaleY)); //return the Haar feature as if the sample is of original scale (1.0)
141 | }
142 |
143 | /****************************************************************
144 | HaarFeature::=
145 | Assignment Operator - deep copy
146 | Exception:
147 | None
148 | ****************************************************************/
149 | inline HaarFeature& HaarFeature::operator= ( const HaarFeature &a )
150 | {
151 | m_width = a.m_width;
152 | m_height = a.m_height;
153 | m_channel = a.m_channel;
154 | m_weights = a.m_weights;
155 | m_rects = a.m_rects;
156 | m_maxSum = a.m_maxSum;
157 | return (*this);
158 | }
159 |
160 | /****************************************************************
161 | HaarFeature::GetExpectedValue
162 | Get Expected value
163 | Exception:
164 | None
165 | ****************************************************************/
166 | inline float HaarFeature::GetExpectedValue() const
167 | {
168 | float sum = 0.0f;
169 | for ( int k=0; k<(int)m_rects.size(); k++ )
170 | {
171 | sum += m_weights[k] * m_rects[k].height * m_rects[k].width * 125;
172 | }
173 | return sum;
174 | }
175 | }
--------------------------------------------------------------------------------
/src/HaarFeature.h:
--------------------------------------------------------------------------------
1 | #ifndef HAAR_FEATURE
2 | #define HAAR_FEATURE
3 |
4 | #include "Feature.h"
5 |
6 | namespace Features
7 | {
8 | /****************************************************************
9 | HaarFeature
10 | Haar type features. Obtained using wavelet based mother basis.
11 | ****************************************************************/
12 | class HaarFeature : public Feature
13 | {
14 | public:
15 | HaarFeature( );
16 |
17 | virtual const FeatureType GetFeatureType() const { return HAAR_LIKE; };
18 |
19 | //randomly generate a feature instance (this) based on feature parameters
20 | virtual void Generate( FeatureParametersPtr featureParametersPtr );
21 |
22 | //copy from another haar feature instance
23 | HaarFeature& operator= ( const HaarFeature& aHaarFeature );
24 |
25 | virtual Matrixu ToVisualize( int featureIndex = -1 );
26 |
27 | float GetExpectedValue() const;
28 |
29 | // Haar-like feature is of one dim
30 | virtual float Compute( const Classifier::Sample& sample ) const;
31 | virtual void Compute( const Classifier::Sample& sample, vectorf& featureValueList ) const
32 | { abortError( __LINE__, __FILE__, "Error: HaarFeature has only one Dimension" );}
33 |
34 | //member variables
35 | static StopWatch m_sw;
36 |
37 | private:
38 | uint m_width;
39 | uint m_height;
40 | uint m_channel;
41 | vectorf m_weights;
42 | vector m_rects;
43 | vectorf m_rsums;
44 | double m_maxSum;
45 | };
46 | }
47 | #endif
--------------------------------------------------------------------------------
/src/HaarFeatureVector.cpp:
--------------------------------------------------------------------------------
1 | #include "HaarFeatureVector.h"
2 | #include "HaarFeature.h"
3 |
4 | namespace Features
5 | {
6 | /****************************************************************
7 | HaarFeatureVector::Generate
8 | Generates FeatureVector based on the specified feature type.
9 | FeatureList stores a list of haar features.
10 | Call to Compute actually calculates the feature values.
11 | Exception:
12 | None
13 | ****************************************************************/
14 | void HaarFeatureVector::Generate( FeatureParametersPtr featureParametersPtr )
15 | {
16 | try
17 | {
18 | ASSERT_TRUE( featureParametersPtr != NULL );
19 |
20 | m_featureParametersPtr = featureParametersPtr;
21 | m_numberOfHaarFeatures = featureParametersPtr->GetHaarFeatureDimension();
22 |
23 | m_featureList.resize( m_numberOfHaarFeatures );
24 |
25 | for ( uint featureIndex = 0; featureIndex < m_numberOfHaarFeatures; featureIndex++ )
26 | {
27 | m_featureList[featureIndex] = boost::shared_ptr( new HaarFeature() );
28 | ASSERT_TRUE( m_featureList[featureIndex] != 0 );
29 | m_featureList[featureIndex]->Generate( m_featureParametersPtr );
30 | }
31 |
32 | //Update the feature generated flag
33 | m_isFeatureGenerated = true;
34 | }
35 | EXCEPTION_CATCH_AND_ABORT( "Error While Generating Haar Feature" );
36 | }
37 |
38 |
39 | /****************************************************************
40 | HaarFeatureVector::Compute
41 | Iterate over each sample in the given Classifier::SampleSet
42 | and compute the featurePtr. Store the computed featurePtr value
43 | in the featurePtr vector.
44 | Classifier calls this method with a set of samples for each type.
45 | Exception:
46 | None
47 | ****************************************************************/
48 | void HaarFeatureVector::Compute( Classifier::SampleSet& sampleSet, bool shouldResizeFeatureMatrix )
49 | {
50 | size_t numberOfSamples = sampleSet.Size( );
51 |
52 | ASSERT_TRUE( m_isFeatureGenerated == true );
53 | ASSERT_TRUE( m_numberOfHaarFeatures > 0 );
54 |
55 | //return if no sample is available
56 | if ( numberOfSamples == 0 )
57 | {
58 | return;
59 | }
60 |
61 | //resize the feature matrix size to the number of features
62 | if ( shouldResizeFeatureMatrix )
63 | {
64 | sampleSet.ResizeFeatures( m_numberOfHaarFeatures );
65 | }
66 |
67 | #pragma omp parallel for
68 | for ( uint featureIndex = 0; featureIndex < m_numberOfHaarFeatures; featureIndex++ )
69 | {
70 | //#pragma omp parallel for
71 | for ( int sampleIndex = 0; sampleIndex < numberOfSamples; sampleIndex++ )
72 | {
73 | ASSERT_TRUE( m_featureList[featureIndex] != NULL );
74 |
75 | //store the feature value in the feature matrix
76 | sampleSet.GetFeatureValue( sampleIndex, featureIndex ) = m_featureList[featureIndex]->Compute( sampleSet[sampleIndex] );
77 | }
78 | }
79 | }
80 |
81 | /****************************************************************
82 | HaarFeatureVector::SaveVisualizedFeatureVector
83 | Save the visualized haar features to a given directory
84 | Exception:
85 | None
86 | ****************************************************************/
87 | void HaarFeatureVector::SaveVisualizedFeatureVector(const char* dirName)
88 | {
89 | char fname[1024];
90 | Matrixu img;
91 | for( uint featureIndex = 0; featureIndex < m_featureList.size(); featureIndex++ )
92 | {
93 | sprintf_s( fname, "%s/HaarFeature%05d.png", dirName, featureIndex );
94 | img = m_featureList[featureIndex]->ToVisualize( );
95 | img.SaveImage(fname);
96 | }
97 | }
98 | }
--------------------------------------------------------------------------------
/src/HaarFeatureVector.h:
--------------------------------------------------------------------------------
1 | #ifndef HAAR_FEATURE_VECTOR_H
2 | #define HAAR_FEATURE_VECTOR_H
3 |
4 | #include "FeatureVector.h"
5 |
6 | namespace Features
7 | {
8 | /****************************************************************
9 | HaarFeatureVector
10 | This is a wrapper class for HaarFeature.
11 | ****************************************************************/
12 | class HaarFeatureVector : virtual public FeatureVector
13 | {
14 | public:
15 | HaarFeatureVector( ){}
16 |
17 | virtual void Generate( FeatureParametersPtr featureParametersPtr );
18 | virtual void Compute( Classifier::SampleSet& sampleSet, bool shouldResizeFeatureMatrix = true );
19 |
20 | virtual void SaveVisualizedFeatureVector( const char * dirname );
21 |
22 | virtual const uint GetNumberOfFeatures( ) const { return m_numberOfHaarFeatures; }
23 |
24 | protected:
25 | FeatureList m_featureList;
26 | uint m_numberOfHaarFeatures;
27 | };
28 | }
29 | #endif
30 |
--------------------------------------------------------------------------------
/src/MILAnyBoostClassifier.h:
--------------------------------------------------------------------------------
1 | #ifndef MIL_ANYBOOST_H
2 | #define MIL_ANYBOOST_H
3 |
4 | #include "StrongClassifierBase.h"
5 |
6 | namespace Classifier
7 | {
8 | /****************************************************************
9 | MILAnyBoostClassifier
10 | The class that implements MIL Anyboost based classifier.
11 | ****************************************************************/
12 | class MILAnyBoostClassifier : public StrongClassifierBase
13 | {
14 | public:
15 | MILAnyBoostClassifier( Classifier::StrongClassifierParametersBasePtr strongClassifierParametersBasePtr )
16 | : StrongClassifierBase( strongClassifierParametersBasePtr )
17 | {
18 | try
19 | {
20 | m_milAnyBoostClassifierParametersPtr = boost::static_pointer_cast( strongClassifierParametersBasePtr );
21 | }
22 | EXCEPTION_CATCH_AND_ABORT( "Failed to Construct MILAnyBoost" );
23 | }
24 |
25 | //update the classifier
26 | virtual void Update( Classifier::SampleSet& positiveSampleSet, Classifier::SampleSet& negativeSampleSet );
27 |
28 | //classify the set of samples
29 | virtual vectorf Classify( Classifier::SampleSet& sampleSet, bool isLogRatioEnabled = true );
30 |
31 | private:
32 | MILAnyBoostClassifierParametersPtr m_milAnyBoostClassifierParametersPtr;
33 | };
34 | }
35 | #endif
36 |
--------------------------------------------------------------------------------
/src/MILBoostClassifier.h:
--------------------------------------------------------------------------------
1 | #ifndef MILBOOST_H
2 | #define MILBOOST_H
3 |
4 | #include "StrongClassifierBase.h"
5 |
6 | namespace Classifier
7 | {
8 | /****************************************************************
9 | MILBoostClassifier
10 | The class that implements MIL boost based classifier.
11 | ****************************************************************/
12 | class MILBoostClassifier : public StrongClassifierBase
13 | {
14 | public:
15 |
16 | MILBoostClassifier( Classifier::StrongClassifierParametersBasePtr strongClassifierParametersBasePtr )
17 | : StrongClassifierBase( strongClassifierParametersBasePtr )
18 | {
19 | m_MILBoostClassifierParametersPtr =
20 | boost::static_pointer_cast( strongClassifierParametersBasePtr );
21 | }
22 |
23 | virtual void Update( Classifier::SampleSet& positiveSampleSet,
24 | Classifier::SampleSet& negativeSampleSet );
25 |
26 | virtual vectorf Classify( Classifier::SampleSet& sampleSet,
27 | bool isLogRatioEnabled = true );
28 |
29 | //multiple positive bags
30 | virtual void Update( Classifier::SampleSet& positiveSampleSet,
31 | Classifier::SampleSet& negativeSampleSet,
32 | int numPositiveBags );
33 |
34 | private:
35 | MILBoostClassifierParametersPtr m_MILBoostClassifierParametersPtr;
36 | };
37 | }
38 | #endif
39 |
--------------------------------------------------------------------------------
/src/MILEnsembleClassifier.h:
--------------------------------------------------------------------------------
1 | #ifndef MILENSEMBLE_H
2 | #define MILENSEMBLE_H
3 |
4 | #include "StrongClassifierBase.h"
5 |
6 | namespace Classifier
7 | {
8 | /****************************************************************
9 | MILEnsembleClassifier
10 | The class that implements MIL Ensemble boosting based classifier.
11 | ****************************************************************/
12 | class MILEnsembleClassifier : public StrongClassifierBase
13 | {
14 | public:
15 |
16 | MILEnsembleClassifier( Classifier::StrongClassifierParametersBasePtr strongClassifierParametersBasePtr )
17 | : StrongClassifierBase( strongClassifierParametersBasePtr )
18 | {
19 | m_MILEnsembleClassifierParametersPtr = boost::static_pointer_cast( strongClassifierParametersBasePtr );
20 | }
21 |
22 | virtual void Update( Classifier::SampleSet& positiveSampleSet, Classifier::SampleSet& negativeSampleSet );
23 | virtual vectorf Classify( Classifier::SampleSet& sampleSet, bool isLogRatioEnabled = true );
24 |
25 | private:
26 |
27 | void RetainBestPerformingWeakClassifiers( Classifier::SampleSet& positiveSampleSet,
28 | Classifier::SampleSet& negativeSampleSet,
29 | vectorf& positiveHypothesis,
30 | vectorf& negativeHypothesis );
31 |
32 | void RetainBestPerformingWeakClassifiersWithAdaptiveWeighting( Classifier::SampleSet& positiveSampleSet,
33 | Classifier::SampleSet& negativeSampleSet,
34 | vectorf& positiveHypothesis,
35 | vectorf& negativeHypothesis );
36 |
37 | void UpdateWithAdaptiveWeighting( Classifier::SampleSet& positiveSampleSet, Classifier::SampleSet& negativeSampleSet );
38 |
39 | MILEnsembleClassifierParametersPtr m_MILEnsembleClassifierParametersPtr;
40 | };
41 | }
42 | #endif
43 |
--------------------------------------------------------------------------------
/src/MultiDimensionalColorHistogram.cpp:
--------------------------------------------------------------------------------
1 | #include "MultiDimensionalColorHistogram.h"
2 |
3 | namespace Features
4 | {
5 | /****************************************************************
6 | MultiDimensionalColorHistogram::Compute
7 | Generate the multi-dimensional color histogram (multi-part)
8 | Exception:
9 | None
10 | ****************************************************************/
11 | void MultiDimensionalColorHistogram::Generate( FeatureParametersPtr featureParametersPtr )
12 | {
13 | try
14 | {
15 | MultiDimensionalColorHistogramParametersPtr temp = boost::dynamic_pointer_cast(featureParametersPtr);
16 |
17 | m_numberOfBins = temp->m_numberOfBins;
18 | m_numberOfParts = temp->m_numberOfParts;
19 | m_partPercentageVertical = temp->m_partPercentageVertical;
20 | m_useHSVColorSpace = temp->m_useHSVColorSpace;
21 | }
22 | EXCEPTION_CATCH_AND_ABORT( "Failed to Generate Multi-dimensional color histrogram" );
23 | }
24 |
25 | /****************************************************************
26 | MultiDimensionalColorHistogram::Compute
27 | Compute the multi-dimensional color histogram and store it in the
28 | given vector.
29 | Exception:
30 | None
31 | ****************************************************************/
32 | void MultiDimensionalColorHistogram::Compute( const Classifier::Sample& sample, vectorf& featureValueList ) const
33 | {
34 | try
35 | {
36 | ASSERT_TRUE( !featureValueList.empty( ) );
37 |
38 | // Calculate the size for each part.
39 | vectori partRowList;
40 | int accum = 0, partEnd;
41 |
42 | float numberOfRows = cvRound( static_cast(sample.m_height) * sample.m_scaleY );
43 |
44 | partRowList.push_back( 0 );
45 | for (int i = 0; i < m_numberOfParts; i++)
46 | {
47 | accum += m_partPercentageVertical[i];
48 | partEnd = cvRound( numberOfRows * accum/100 );
49 | ASSERT_TRUE ( partEnd > partRowList[i] );
50 | partRowList.push_back( partEnd );
51 | }
52 |
53 | Matrixu* pImageMatrix = NULL;
54 |
55 | if ( m_useHSVColorSpace )
56 | {
57 | pImageMatrix = sample.GetHSVImage();
58 | }
59 | else
60 | {
61 | pImageMatrix = sample.GetColorImage();
62 | }
63 |
64 | ASSERT_TRUE ( pImageMatrix != NULL );
65 |
66 | float numberOfColumns =cvRound( static_cast(sample.m_width) * sample.m_scaleX );
67 |
68 | float varianceX = pow( (numberOfColumns / 2), 2);
69 | float sampleCenterX = sample.m_col + numberOfColumns/2;
70 |
71 | ASSERT_TRUE( pImageMatrix->depth( ) == 3 );
72 | ASSERT_TRUE( m_numberOfBins > 0 );
73 |
74 | float binWidth = 256 / m_numberOfBins;
75 |
76 | int partFeatureDimension = m_numberOfBins*m_numberOfBins*m_numberOfBins;
77 |
78 | vectorf partFeatureValueList;
79 |
80 | partFeatureValueList.resize( partFeatureDimension );
81 |
82 |
83 | for( int partIndex = 0; partIndex < m_numberOfParts; partIndex++ )
84 | {
85 | #pragma omp parallel for
86 |
87 | float partNumberOfRows = partRowList[partIndex+1] - partRowList[partIndex];
88 | float varianceY = pow( (partNumberOfRows / 2), 2);
89 | float sampleCenterY = sample.m_row + partRowList[partIndex] + partNumberOfRows/2;
90 |
91 | for ( uint rowIndex = sample.m_row+partRowList[partIndex]; rowIndex < (sample.m_row+partRowList[partIndex+1]); rowIndex++ )
92 | {
93 | for ( uint columnIndex = sample.m_col; columnIndex < (sample.m_col+numberOfColumns); columnIndex++ )
94 | {
95 | uint rPixel = (*pImageMatrix)( rowIndex, columnIndex, 0 /*depth*/ );
96 | uint gPixel = (*pImageMatrix)( rowIndex, columnIndex, 1 /*depth*/ );
97 | uint bPixel = (*pImageMatrix)( rowIndex, columnIndex, 2 /*depth*/ );
98 |
99 | uint rBin = floor( rPixel / binWidth );
100 | uint gBin = floor( gPixel / binWidth );
101 | uint bBin = floor( bPixel / binWidth );
102 |
103 | uint featureIndex = rBin + m_numberOfBins * gBin + m_numberOfBins * m_numberOfBins * bBin;
104 |
105 | float featureWeight = 1.0f;
106 |
107 | if ( m_shouldWeightFromCenter )
108 | {
109 | float weightedDistanceFromCenter = pow( ( sampleCenterX - columnIndex ), 2 ) / (2.0f * varianceX) +
110 | pow( ( sampleCenterY - rowIndex ), 2 ) / ( 2.0f * varianceY );
111 |
112 | featureWeight = exp( -1 * weightedDistanceFromCenter );
113 | }
114 |
115 | partFeatureValueList[ featureIndex ] = partFeatureValueList[ featureIndex ] + featureWeight;
116 | }
117 | }
118 | ::normalizeVec( partFeatureValueList );
119 |
120 | for ( int i = 0; i < partFeatureDimension; i++ )
121 | {
122 | featureValueList[partIndex*partFeatureDimension + i]= partFeatureValueList[i];
123 | }
124 | } //to next part
125 | }
126 | EXCEPTION_CATCH_AND_ABORT( "Failed to Compute Multi-Dimensional Color Histogram" )
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/src/MultiDimensionalColorHistogram.h:
--------------------------------------------------------------------------------
1 | #ifndef MULTI_COLOR_HISTOGRAM
2 | #define MULTI_COLOR_HISTOGRAM
3 |
4 | #include "Feature.h"
5 |
6 | namespace Features
7 | {
8 | /****************************************************************
9 | MultiDimensionalColorHistogram
10 | A multi dimensional color histogram obtained by binning the
11 | pixels in R,G and B spaces separately.
12 | ****************************************************************/
13 | class MultiDimensionalColorHistogram : public Feature
14 | {
15 | public:
16 | MultiDimensionalColorHistogram( )
17 | : m_shouldWeightFromCenter( true )
18 | {
19 | }
20 |
21 | virtual const FeatureType GetFeatureType( ) const { return MULTI_DIMENSIONAL_COLOR_HISTOGRAM; };
22 |
23 | //MultiDimensionalColorHistogram has more than one dim
24 | virtual float Compute( const Classifier::Sample& sample ) const
25 | {
26 | abortError( __LINE__, __FILE__, "Error: MultiDimensionalColorHistogram has only one Dimension" ); return 0.0f;
27 | }
28 |
29 | virtual void Compute( const Classifier::Sample& sample, vectorf& featureValueList ) const;
30 |
31 | //initialize feature instance (unlike the haar feature)
32 | virtual void Generate( FeatureParametersPtr featureParametersPtr ) ;
33 |
34 | private:
35 | vectori m_partPercentageVertical; // a list of percentage (of total height) for each part, must add up to 100
36 | uint m_numberOfBins;
37 | uint m_numberOfParts; // number of parts
38 | bool m_useHSVColorSpace; // use HSV instead of RGB
39 | bool m_shouldWeightFromCenter;
40 | };
41 | }
42 | #endif
--------------------------------------------------------------------------------
/src/MultiDimensionalColorHistogramFeatureVector.cpp:
--------------------------------------------------------------------------------
1 | #include "MultiDimensionalColorHistogramFeatureVector.h"
2 | #include "MultiDimensionalColorHistogram.h"
3 |
4 | namespace Features
5 | {
6 | /****************************************************************
7 | MultiDimensionalColorHistogramFeatureVector::Generate
8 | Generates FeatureVector based on the specified feature type.
9 | Feature stores the multi dimensional color histogram.
10 | Note: parameter "numberOfColorFeatures" is not used as the size of feature vector
11 | is pre-determined.
12 | Exception:
13 | None
14 | ****************************************************************/
15 | void MultiDimensionalColorHistogramFeatureVector::Generate( FeatureParametersPtr featureParametersPtr )
16 | {
17 | try
18 | {
19 | ASSERT_TRUE( featureParametersPtr != NULL );
20 |
21 | m_featureParametersPtr = featureParametersPtr;
22 |
23 | m_featurePtr = boost::shared_ptr( new MultiDimensionalColorHistogram() );
24 |
25 | ASSERT_TRUE( m_featurePtr != NULL );
26 |
27 | m_numberOfColorFeatures = m_featureParametersPtr->GetColorFeatureDimension( );
28 |
29 | m_featurePtr->Generate( m_featureParametersPtr );
30 |
31 | //Update the feature generated flag
32 | m_isFeatureGenerated = true;
33 |
34 | ///feature index starts from this location
35 | m_startingIndexForFeatureMatrix = m_featureParametersPtr->GetHaarFeatureDimension( );
36 |
37 | ASSERT_TRUE( m_startingIndexForFeatureMatrix >= 0 );
38 | }
39 | EXCEPTION_CATCH_AND_ABORT( "Error While Generating MultiDimensionalColorHistogram Feature Vector" );
40 | }
41 |
42 |
43 | /****************************************************************
44 | MultiDimensionalColorHistogramFeatureVector::Compute
45 | Iterate over each sample in the given Classifier::SampleSet
46 | and compute the featurePtr. Store the computed featurePtr value
47 | in the featurePtr vector.
48 | Classifier calls this method with a set of samples for each type.
49 | Exception:
50 | None
51 | ****************************************************************/
52 | void MultiDimensionalColorHistogramFeatureVector::Compute( Classifier::SampleSet& sampleSet, bool shouldResizeFeatureMatrix )
53 | {
54 | try
55 | {
56 | size_t numberOfSamples = sampleSet.Size( );
57 |
58 | ASSERT_TRUE( m_isFeatureGenerated == true );
59 | ASSERT_TRUE( m_numberOfColorFeatures > 0 );
60 |
61 | //return if no sample is available
62 | if ( numberOfSamples == 0 )
63 | {
64 | return;
65 | }
66 |
67 | //resize the feature matrix size to the number of features
68 | if ( shouldResizeFeatureMatrix )
69 | {
70 | sampleSet.ResizeFeatures( m_numberOfColorFeatures );
71 | }
72 |
73 | #pragma omp parallel for
74 | for ( int sampleIndex = 0; sampleIndex < numberOfSamples; sampleIndex++ )
75 | {
76 | vectorf colorHistogramVector( m_numberOfColorFeatures, 0.0f );
77 | m_featurePtr->Compute( sampleSet[sampleIndex], colorHistogramVector );
78 |
79 | ASSERT_TRUE( m_featurePtr != NULL );
80 | ASSERT_TRUE( colorHistogramVector.size( ) == m_numberOfColorFeatures );
81 |
82 | for ( uint featureIndex = m_startingIndexForFeatureMatrix; featureIndex < (m_startingIndexForFeatureMatrix+m_numberOfColorFeatures); featureIndex++ )
83 | {
84 | //store the feature value in the feature matrix
85 | sampleSet.GetFeatureValue( sampleIndex, featureIndex ) = colorHistogramVector[featureIndex-m_startingIndexForFeatureMatrix];
86 | }
87 | }
88 | }
89 | EXCEPTION_CATCH_AND_ABORT( "Failed to Multi-Dimensional Color Histogram Feature Vector" );
90 | }
91 | }
--------------------------------------------------------------------------------
/src/MultiDimensionalColorHistogramFeatureVector.h:
--------------------------------------------------------------------------------
1 | #ifndef COLOR_FEATURE_VECTOR_H
2 | #define COLOR_FEATURE_VECTOR_H
3 |
4 | #include "FeatureVector.h"
5 | namespace Features
6 | {
7 | /****************************************************************
8 | MultiDimensionalColorHistogramFeatureVector
9 | This is a wrapper class for MultiDimensionalColorHistogram.
10 | ****************************************************************/
11 | class MultiDimensionalColorHistogramFeatureVector : virtual public FeatureVector
12 | {
13 | public:
14 | //Generate features
15 | virtual void Generate( FeatureParametersPtr featureParametersPtr );
16 |
17 | //Computes features for the given sample set
18 | virtual void Compute( Classifier::SampleSet& sampleSet, bool shouldResizeFeatureMatrix = true );
19 |
20 | //Save the visualized feature vector - Unused
21 | virtual void SaveVisualizedFeatureVector( const char *dirName ){}
22 |
23 | //Get Number of Features
24 | virtual const uint GetNumberOfFeatures( ) const { return m_numberOfColorFeatures; }
25 |
26 | protected:
27 |
28 | FeaturePtr m_featurePtr;
29 | uint m_numberOfColorFeatures;
30 | uint m_startingIndexForFeatureMatrix; //Used while Color Feature is concatenated to the Other features.
31 | };
32 | }
33 | #endif
--------------------------------------------------------------------------------
/src/Object.h:
--------------------------------------------------------------------------------
1 | #ifndef CAMERA_OBJECT_HEADER
2 | #define CAMERA_OBJECT_HEADER
3 |
4 | #include "Matrix.h"
5 | #include "Feature.h"
6 | #include "Tracker.h"
7 | #include "SimpleTracker.h"
8 | #include "ParticleFilterTracker.h"
9 | #include "Public.h"
10 | #include "CameraNetworkBase.h"
11 | #include "AppearanceBasedInformationFuser.h"
12 | #include "DefaultParameters.h"
13 | #include "Config.h"
14 |
15 | namespace MultipleCameraTracking
16 | {
17 | /****************************************************************
18 | Object
19 | This class holds all the information about an
20 | object(target of interest) inside a particular camera,
21 | i.e. an object instance belong to a camera
22 | instance.
23 | ****************************************************************/
24 | class Object
25 | {
26 | public:
27 | //Constructor
28 | Object( const int objectId,
29 | const int cameraId,
30 | const bool isColorEnabled,
31 | CameraTrackingParametersPtr cameraTrackingParametersPtr,
32 | CvMat* pHomographyMatrix );
33 |
34 | int GetObjectID( ) const { return m_objectID; };
35 |
36 | //Initializes the object parameters with initial state and file name for saving its trajectory
37 | void InitializeObjectParameters( const vectorf& initialState, const string& trajSaveStrBase );
38 |
39 | /***** Basic Object Tracker *****/
40 | // Initialize the tracker for the object
41 | bool InitializeObjectTracker( Matrixu* pFrameImageColor,
42 | Matrixu* pFrameImageGray,
43 | int frameInd,
44 | uint videoLength,
45 | Matrixu* pFrameDisplay = NULL,
46 | Matrixu* pFrameDisplayTraining = NULL,
47 | Matrixu* pFrameImageHSV = NULL,
48 | Matrixf* pGroundTruthMatrix = NULL );
49 |
50 | // Track the object in a given frame
51 | void TrackObjectFrame( int frameind,
52 | Matrixu* pFrameImageColor,
53 | Matrixu* pFrameImageGray,
54 | Matrixu* pFrameDisplay=NULL,
55 | Matrixu* pFrameDisplayTraining=NULL,
56 | Matrixu* pFrameImageHSV=NULL );
57 |
58 | // Notify the tracker to keep the particle filter tracker state as the final state for the frame,
59 | void StoreParticleFilterTrackerState( int frameInd, Matrixu* pFrameDisplay = NULL );
60 |
61 | // Update the particle filter tracker appearance model
62 | void UpdateParticleFilterTrackerAppearanceModel( Matrixu* pFrameImageColor,
63 | Matrixu* pFrameImageGray,
64 | Matrixu* pFrameDisplayTraining = NULL,
65 | Matrixu* pFrameImageHSV = NULL );
66 |
67 | // Save the state on the object's trajectory file
68 | void SaveObjectStatesAllFrames( );
69 |
70 | /***** For Ground Plane Fusion *****/
71 | // Get ground plane position particles (still on the image plane)
72 | CvMat* GetParticlesFootPositionOnImagePlaneForGeometricFusion( );
73 | CvMat* GetAverageParticleFootPositionOnImagePlaneForGeometricFusion( );
74 |
75 | /***** For Color Appearance Fusion *****/
76 | void GenerateTrainingSampleSetsForAppearanceFusion( Classifier::SampleSet& positiveSampleSet,
77 | Classifier::SampleSet& negativeSampleSet,
78 | Matrixu* pFrameImageColor,
79 | Matrixu* pFrameImageGray,
80 | Matrixu* pFrameImageHSV );
81 |
82 | void LearnGlobalAppearanceModel( CameraNetworkBasePtr cameraNetworkBasePtr );
83 |
84 | /***** For Occlusion Handling *****/
85 | void AutoInitialize( Matrixf AppearanceModel ) { };
86 | void SuspendTracking( ) {};
87 | void ResumeTracking( Matrixf AppearanceModel) { };
88 |
89 | void UpdateParticleWeightUsingMultiCameraAppearanceModel( Matrixu* pFrameImageColor,
90 | Matrixu* pFrameImageGray,
91 | Matrixu* pFrameImageHSV );
92 |
93 | void UpdateParticleWeightsWithGroundPDF( CvMat* pMeanMatrix,
94 | CvMat* pCovarianceMatrix,
95 | Matrixu* pColorImageMatrix,
96 | Matrixu* pGrayImageMatrix,
97 | Matrixu* pHsvImageMatrix );
98 |
99 | void DrawObjectFootPoint(Matrixu* pFrameDisplay);
100 | private:
101 | DISALLOW_IMPLICIT_CONSTRUCTORS( Object );
102 |
103 | Features::FeatureParametersPtr GenerateDefaultTrackerFeatureParameters( );
104 | Features::FeatureParametersPtr GenerateDefaultAppearanceFusionFeatureParameters( );
105 | Classifier::StrongClassifierParametersBasePtr GenerateDefaultAppearanceFusionClassifierParameters( );
106 |
107 | CameraTrackingParametersPtr m_cameraTrackingParametersPtr;
108 | CvMat* m_pHomographyMatrix;
109 |
110 | Classifier::StrongClassifierParametersBasePtr m_classifierParamPtr; //Strong Classifier Parameters
111 | TrackerParametersPtr m_trackerParametersPtr; //Simple Tracker Parameters
112 | TrackerPtr m_trackerPtr; //Object for Tracking Module
113 | AppearanceBasedInformationFuserPtr m_appearanceFuserPtr;
114 | const int m_objectID; //Object ID
115 | const int m_cameraID; //which camera does this object belongs to
116 |
117 | const bool m_colorImage; //whether input raw video is color
118 | int m_indPreviousTrackedFrame; //the frame index in the most recent call to TrackObjectFrame
119 |
120 | };
121 |
122 | typedef boost::shared_ptr