1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
|
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_TRACKER_HPP__
#define __OPENCV_TRACKER_HPP__
#include "opencv2/core.hpp"
#include "opencv2/imgproc/types_c.h"
#include "feature.hpp"
#include "onlineMIL.hpp"
#include "onlineBoosting.hpp"
#include <iostream>
#define BOILERPLATE_CODE(name,classname) \
static Ptr<classname> createTracker(const classname::Params ¶meters=classname::Params());\
virtual ~classname(){};
/*
* Partially based on:
* ====================================================================================================================
* - [AAM] S. Salti, A. Cavallaro, L. Di Stefano, Adaptive Appearance Modeling for Video Tracking: Survey and Evaluation
* - [AMVOT] X. Li, W. Hu, C. Shen, Z. Zhang, A. Dick, A. van den Hengel, A Survey of Appearance Models in Visual Object Tracking
*
* This Tracking API has been designed with PlantUML. If you modify this API please change UML files under modules/tracking/doc/uml
*
*/
namespace cv
{
//! @addtogroup tracking
//! @{
/************************************ TrackerFeature Base Classes ************************************/
/** @brief Abstract base class for TrackerFeature that represents the feature.
*/
class CV_EXPORTS TrackerFeature
{
public:
virtual ~TrackerFeature();
/** @brief Compute the features in the images collection
@param images The images
@param response The output response
*/
void compute( const std::vector<Mat>& images, Mat& response );
/** @brief Create TrackerFeature by tracker feature type
@param trackerFeatureType The TrackerFeature name
The modes available now:
- "HAAR" -- Haar Feature-based
The modes that will be available soon:
- "HOG" -- Histogram of Oriented Gradients features
- "LBP" -- Local Binary Pattern features
- "FEATURE2D" -- All types of Feature2D
*/
static Ptr<TrackerFeature> create( const String& trackerFeatureType );
/** @brief Identify most effective features
@param response Collection of response for the specific TrackerFeature
@param npoints Max number of features
@note This method modifies the response parameter
*/
virtual void selection( Mat& response, int npoints ) = 0;
/** @brief Get the name of the specific TrackerFeature
*/
String getClassName() const;
protected:
virtual bool computeImpl( const std::vector<Mat>& images, Mat& response ) = 0;
String className;
};
/** @brief Class that manages the extraction and selection of features
@cite AAM Feature Extraction and Feature Set Refinement (Feature Processing and Feature Selection).
See table I and section III C @cite AMVOT Appearance modelling -\> Visual representation (Table II,
section 3.1 - 3.2)
TrackerFeatureSet is an aggregation of TrackerFeature
@sa
TrackerFeature
*/
class CV_EXPORTS TrackerFeatureSet
{
public:
TrackerFeatureSet();
~TrackerFeatureSet();
/** @brief Extract features from the images collection
@param images The input images
*/
void extraction( const std::vector<Mat>& images );
/** @brief Identify most effective features for all feature types (optional)
*/
void selection();
/** @brief Remove outliers for all feature types (optional)
*/
void removeOutliers();
/** @brief Add TrackerFeature in the collection. Return true if TrackerFeature is added, false otherwise
@param trackerFeatureType The TrackerFeature name
The modes available now:
- "HAAR" -- Haar Feature-based
The modes that will be available soon:
- "HOG" -- Histogram of Oriented Gradients features
- "LBP" -- Local Binary Pattern features
- "FEATURE2D" -- All types of Feature2D
Example TrackerFeatureSet::addTrackerFeature : :
@code
//sample usage:
Ptr<TrackerFeature> trackerFeature = new TrackerFeatureHAAR( HAARparameters );
featureSet->addTrackerFeature( trackerFeature );
//or add CSC sampler with default parameters
//featureSet->addTrackerFeature( "HAAR" );
@endcode
@note If you use the second method, you must initialize the TrackerFeature
*/
bool addTrackerFeature( String trackerFeatureType );
/** @overload
@param feature The TrackerFeature class
*/
bool addTrackerFeature( Ptr<TrackerFeature>& feature );
/** @brief Get the TrackerFeature collection (TrackerFeature name, TrackerFeature pointer)
*/
const std::vector<std::pair<String, Ptr<TrackerFeature> > >& getTrackerFeature() const;
/** @brief Get the responses
@note Be sure to call extraction before getResponses Example TrackerFeatureSet::getResponses : :
*/
const std::vector<Mat>& getResponses() const;
private:
void clearResponses();
bool blockAddTrackerFeature;
std::vector<std::pair<String, Ptr<TrackerFeature> > > features; //list of features
std::vector<Mat> responses; //list of response after compute
};
/************************************ TrackerSampler Base Classes ************************************/
/** @brief Abstract base class for TrackerSamplerAlgorithm that represents the algorithm for the specific
sampler.
*/
class CV_EXPORTS TrackerSamplerAlgorithm
{
public:
/**
* \brief Destructor
*/
virtual ~TrackerSamplerAlgorithm();
/** @brief Create TrackerSamplerAlgorithm by tracker sampler type.
@param trackerSamplerType The trackerSamplerType name
The modes available now:
- "CSC" -- Current State Center
- "CS" -- Current State
*/
static Ptr<TrackerSamplerAlgorithm> create( const String& trackerSamplerType );
/** @brief Computes the regions starting from a position in an image.
Return true if samples are computed, false otherwise
@param image The current frame
@param boundingBox The bounding box from which regions can be calculated
@param sample The computed samples @cite AAM Fig. 1 variable Sk
*/
bool sampling( const Mat& image, Rect boundingBox, std::vector<Mat>& sample );
/** @brief Get the name of the specific TrackerSamplerAlgorithm
*/
String getClassName() const;
protected:
String className;
virtual bool samplingImpl( const Mat& image, Rect boundingBox, std::vector<Mat>& sample ) = 0;
};
/**
* \brief Class that manages the sampler in order to select regions for the update the model of the tracker
* [AAM] Sampling e Labeling. See table I and section III B
*/
/** @brief Class that manages the sampler in order to select regions for the update the model of the tracker
@cite AAM Sampling e Labeling. See table I and section III B
TrackerSampler is an aggregation of TrackerSamplerAlgorithm
@sa
TrackerSamplerAlgorithm
*/
class CV_EXPORTS TrackerSampler
{
public:
/**
* \brief Constructor
*/
TrackerSampler();
/**
* \brief Destructor
*/
~TrackerSampler();
/** @brief Computes the regions starting from a position in an image
@param image The current frame
@param boundingBox The bounding box from which regions can be calculated
*/
void sampling( const Mat& image, Rect boundingBox );
/** @brief Return the collection of the TrackerSamplerAlgorithm
*/
const std::vector<std::pair<String, Ptr<TrackerSamplerAlgorithm> > >& getSamplers() const;
/** @brief Return the samples from all TrackerSamplerAlgorithm, @cite AAM Fig. 1 variable Sk
*/
const std::vector<Mat>& getSamples() const;
/** @brief Add TrackerSamplerAlgorithm in the collection. Return true if sampler is added, false otherwise
@param trackerSamplerAlgorithmType The TrackerSamplerAlgorithm name
The modes available now:
- "CSC" -- Current State Center
- "CS" -- Current State
- "PF" -- Particle Filtering
Example TrackerSamplerAlgorithm::addTrackerSamplerAlgorithm : :
@code
TrackerSamplerCSC::Params CSCparameters;
Ptr<TrackerSamplerAlgorithm> CSCSampler = new TrackerSamplerCSC( CSCparameters );
if( !sampler->addTrackerSamplerAlgorithm( CSCSampler ) )
return false;
//or add CSC sampler with default parameters
//sampler->addTrackerSamplerAlgorithm( "CSC" );
@endcode
@note If you use the second method, you must initialize the TrackerSamplerAlgorithm
*/
bool addTrackerSamplerAlgorithm( String trackerSamplerAlgorithmType );
/** @overload
@param sampler The TrackerSamplerAlgorithm
*/
bool addTrackerSamplerAlgorithm( Ptr<TrackerSamplerAlgorithm>& sampler );
private:
std::vector<std::pair<String, Ptr<TrackerSamplerAlgorithm> > > samplers;
std::vector<Mat> samples;
bool blockAddTrackerSampler;
void clearSamples();
};
/************************************ TrackerModel Base Classes ************************************/
/** @brief Abstract base class for TrackerTargetState that represents a possible state of the target.
See @cite AAM \f$\hat{x}^{i}_{k}\f$ all the states candidates.
Inherits this class with your Target state, In own implementation you can add scale variation,
width, height, orientation, etc.
*/
class CV_EXPORTS TrackerTargetState
{
public:
virtual ~TrackerTargetState()
{
}
;
/**
* \brief Get the position
* \return The position
*/
Point2f getTargetPosition() const;
/**
* \brief Set the position
* \param position The position
*/
void setTargetPosition( const Point2f& position );
/**
* \brief Get the width of the target
* \return The width of the target
*/
int getTargetWidth() const;
/**
* \brief Set the width of the target
* \param width The width of the target
*/
void setTargetWidth( int width );
/**
* \brief Get the height of the target
* \return The height of the target
*/
int getTargetHeight() const;
/**
* \brief Set the height of the target
* \param height The height of the target
*/
void setTargetHeight( int height );
protected:
Point2f targetPosition;
int targetWidth;
int targetHeight;
};
/** @brief Represents the model of the target at frame \f$k\f$ (all states and scores)
See @cite AAM The set of the pair \f$\langle \hat{x}^{i}_{k}, C^{i}_{k} \rangle\f$
@sa TrackerTargetState
*/
typedef std::vector<std::pair<Ptr<TrackerTargetState>, float> > ConfidenceMap;
/** @brief Represents the estimate states for all frames
@cite AAM \f$x_{k}\f$ is the trajectory of the target up to time \f$k\f$
@sa TrackerTargetState
*/
typedef std::vector<Ptr<TrackerTargetState> > Trajectory;
/** @brief Abstract base class for TrackerStateEstimator that estimates the most likely target state.
See @cite AAM State estimator
See @cite AMVOT Statistical modeling (Fig. 3), Table III (generative) - IV (discriminative) - V (hybrid)
*/
class CV_EXPORTS TrackerStateEstimator
{
public:
virtual ~TrackerStateEstimator();
/** @brief Estimate the most likely target state, return the estimated state
@param confidenceMaps The overall appearance model as a list of :cConfidenceMap
*/
Ptr<TrackerTargetState> estimate( const std::vector<ConfidenceMap>& confidenceMaps );
/** @brief Update the ConfidenceMap with the scores
@param confidenceMaps The overall appearance model as a list of :cConfidenceMap
*/
void update( std::vector<ConfidenceMap>& confidenceMaps );
/** @brief Create TrackerStateEstimator by tracker state estimator type
@param trackeStateEstimatorType The TrackerStateEstimator name
The modes available now:
- "BOOSTING" -- Boosting-based discriminative appearance models. See @cite AMVOT section 4.4
The modes available soon:
- "SVM" -- SVM-based discriminative appearance models. See @cite AMVOT section 4.5
*/
static Ptr<TrackerStateEstimator> create( const String& trackeStateEstimatorType );
/** @brief Get the name of the specific TrackerStateEstimator
*/
String getClassName() const;
protected:
virtual Ptr<TrackerTargetState> estimateImpl( const std::vector<ConfidenceMap>& confidenceMaps ) = 0;
virtual void updateImpl( std::vector<ConfidenceMap>& confidenceMaps ) = 0;
String className;
};
/** @brief Abstract class that represents the model of the target. It must be instantiated by specialized
tracker
See @cite AAM Ak
Inherits this with your TrackerModel
*/
class CV_EXPORTS TrackerModel
{
public:
/**
* \brief Constructor
*/
TrackerModel();
/**
* \brief Destructor
*/
virtual ~TrackerModel();
/** @brief Set TrackerEstimator, return true if the tracker state estimator is added, false otherwise
@param trackerStateEstimator The TrackerStateEstimator
@note You can add only one TrackerStateEstimator
*/
bool setTrackerStateEstimator( Ptr<TrackerStateEstimator> trackerStateEstimator );
/** @brief Estimate the most likely target location
@cite AAM ME, Model Estimation table I
@param responses Features extracted from TrackerFeatureSet
*/
void modelEstimation( const std::vector<Mat>& responses );
/** @brief Update the model
@cite AAM MU, Model Update table I
*/
void modelUpdate();
/** @brief Run the TrackerStateEstimator, return true if is possible to estimate a new state, false otherwise
*/
bool runStateEstimator();
/** @brief Set the current TrackerTargetState in the Trajectory
@param lastTargetState The current TrackerTargetState
*/
void setLastTargetState( const Ptr<TrackerTargetState>& lastTargetState );
/** @brief Get the last TrackerTargetState from Trajectory
*/
Ptr<TrackerTargetState> getLastTargetState() const;
/** @brief Get the list of the ConfidenceMap
*/
const std::vector<ConfidenceMap>& getConfidenceMaps() const;
/** @brief Get the last ConfidenceMap for the current frame
*/
const ConfidenceMap& getLastConfidenceMap() const;
/** @brief Get the TrackerStateEstimator
*/
Ptr<TrackerStateEstimator> getTrackerStateEstimator() const;
private:
void clearCurrentConfidenceMap();
protected:
std::vector<ConfidenceMap> confidenceMaps;
Ptr<TrackerStateEstimator> stateEstimator;
ConfidenceMap currentConfidenceMap;
Trajectory trajectory;
int maxCMLength;
virtual void modelEstimationImpl( const std::vector<Mat>& responses ) = 0;
virtual void modelUpdateImpl() = 0;
};
/************************************ Tracker Base Class ************************************/
/** @brief Base abstract class for the long-term tracker:
*/
class CV_EXPORTS_W Tracker : public virtual Algorithm
{
public:
virtual ~Tracker();
/** @brief Initialize the tracker with a know bounding box that surrounding the target
@param image The initial frame
@param boundingBox The initial boundig box
@return True if initialization went succesfully, false otherwise
*/
CV_WRAP bool init( const Mat& image, const Rect2d& boundingBox );
/** @brief Update the tracker, find the new most likely bounding box for the target
@param image The current frame
@param boundingBox The boundig box that represent the new target location, if true was returned, not
modified otherwise
@return True means that target was located and false means that tracker cannot locate target in
current frame. Note, that latter *does not* imply that tracker has failed, maybe target is indeed
missing from the frame (say, out of sight)
*/
CV_WRAP bool update( const Mat& image, CV_OUT Rect2d& boundingBox );
/** @brief Creates a tracker by its name.
@param trackerType Tracker type
The following detector types are supported:
- "MIL" -- TrackerMIL
- "BOOSTING" -- TrackerBoosting
*/
CV_WRAP static Ptr<Tracker> create( const String& trackerType );
virtual void read( const FileNode& fn )=0;
virtual void write( FileStorage& fs ) const=0;
Ptr<TrackerModel> getModel()
{
return model;
}
protected:
virtual bool initImpl( const Mat& image, const Rect2d& boundingBox ) = 0;
virtual bool updateImpl( const Mat& image, Rect2d& boundingBox ) = 0;
bool isInit;
Ptr<TrackerFeatureSet> featureSet;
Ptr<TrackerSampler> sampler;
Ptr<TrackerModel> model;
};
/************************************ Specific TrackerStateEstimator Classes ************************************/
/** @brief TrackerStateEstimator based on Boosting
*/
class CV_EXPORTS TrackerStateEstimatorMILBoosting : public TrackerStateEstimator
{
public:
/**
* Implementation of the target state for TrackerStateEstimatorMILBoosting
*/
class TrackerMILTargetState : public TrackerTargetState
{
public:
/**
* \brief Constructor
* \param position Top left corner of the bounding box
* \param width Width of the bounding box
* \param height Height of the bounding box
* \param foreground label for target or background
* \param features features extracted
*/
TrackerMILTargetState( const Point2f& position, int width, int height, bool foreground, const Mat& features );
/**
* \brief Destructor
*/
~TrackerMILTargetState()
{
}
;
/** @brief Set label: true for target foreground, false for background
@param foreground Label for background/foreground
*/
void setTargetFg( bool foreground );
/** @brief Set the features extracted from TrackerFeatureSet
@param features The features extracted
*/
void setFeatures( const Mat& features );
/** @brief Get the label. Return true for target foreground, false for background
*/
bool isTargetFg() const;
/** @brief Get the features extracted
*/
Mat getFeatures() const;
private:
bool isTarget;
Mat targetFeatures;
};
/** @brief Constructor
@param nFeatures Number of features for each sample
*/
TrackerStateEstimatorMILBoosting( int nFeatures = 250 );
~TrackerStateEstimatorMILBoosting();
/** @brief Set the current confidenceMap
@param confidenceMap The current :cConfidenceMap
*/
void setCurrentConfidenceMap( ConfidenceMap& confidenceMap );
protected:
Ptr<TrackerTargetState> estimateImpl( const std::vector<ConfidenceMap>& confidenceMaps );
void updateImpl( std::vector<ConfidenceMap>& confidenceMaps );
private:
uint max_idx( const std::vector<float> &v );
void prepareData( const ConfidenceMap& confidenceMap, Mat& positive, Mat& negative );
ClfMilBoost boostMILModel;
bool trained;
int numFeatures;
ConfidenceMap currentConfidenceMap;
};
/** @brief TrackerStateEstimatorAdaBoosting based on ADA-Boosting
*/
class CV_EXPORTS TrackerStateEstimatorAdaBoosting : public TrackerStateEstimator
{
public:
/** @brief Implementation of the target state for TrackerAdaBoostingTargetState
*/
class TrackerAdaBoostingTargetState : public TrackerTargetState
{
public:
/**
* \brief Constructor
* \param position Top left corner of the bounding box
* \param width Width of the bounding box
* \param height Height of the bounding box
* \param foreground label for target or background
* \param responses list of features
*/
TrackerAdaBoostingTargetState( const Point2f& position, int width, int height, bool foreground, const Mat& responses );
/**
* \brief Destructor
*/
~TrackerAdaBoostingTargetState()
{
}
;
/** @brief Set the features extracted from TrackerFeatureSet
@param responses The features extracted
*/
void setTargetResponses( const Mat& responses );
/** @brief Set label: true for target foreground, false for background
@param foreground Label for background/foreground
*/
void setTargetFg( bool foreground );
/** @brief Get the features extracted
*/
Mat getTargetResponses() const;
/** @brief Get the label. Return true for target foreground, false for background
*/
bool isTargetFg() const;
private:
bool isTarget;
Mat targetResponses;
};
/** @brief Constructor
@param numClassifer Number of base classifiers
@param initIterations Number of iterations in the initialization
@param nFeatures Number of features/weak classifiers
@param patchSize tracking rect
@param ROI initial ROI
*/
TrackerStateEstimatorAdaBoosting( int numClassifer, int initIterations, int nFeatures, Size patchSize, const Rect& ROI );
/**
* \brief Destructor
*/
~TrackerStateEstimatorAdaBoosting();
/** @brief Get the sampling ROI
*/
Rect getSampleROI() const;
/** @brief Set the sampling ROI
@param ROI the sampling ROI
*/
void setSampleROI( const Rect& ROI );
/** @brief Set the current confidenceMap
@param confidenceMap The current :cConfidenceMap
*/
void setCurrentConfidenceMap( ConfidenceMap& confidenceMap );
/** @brief Get the list of the selected weak classifiers for the classification step
*/
std::vector<int> computeSelectedWeakClassifier();
/** @brief Get the list of the weak classifiers that should be replaced
*/
std::vector<int> computeReplacedClassifier();
/** @brief Get the list of the weak classifiers that replace those to be replaced
*/
std::vector<int> computeSwappedClassifier();
protected:
Ptr<TrackerTargetState> estimateImpl( const std::vector<ConfidenceMap>& confidenceMaps );
void updateImpl( std::vector<ConfidenceMap>& confidenceMaps );
Ptr<StrongClassifierDirectSelection> boostClassifier;
private:
int numBaseClassifier;
int iterationInit;
int numFeatures;
bool trained;
Size initPatchSize;
Rect sampleROI;
std::vector<int> replacedClassifier;
std::vector<int> swappedClassifier;
ConfidenceMap currentConfidenceMap;
};
/**
* \brief TrackerStateEstimator based on SVM
*/
class CV_EXPORTS TrackerStateEstimatorSVM : public TrackerStateEstimator
{
public:
TrackerStateEstimatorSVM();
~TrackerStateEstimatorSVM();
protected:
Ptr<TrackerTargetState> estimateImpl( const std::vector<ConfidenceMap>& confidenceMaps );
void updateImpl( std::vector<ConfidenceMap>& confidenceMaps );
};
/************************************ Specific TrackerSamplerAlgorithm Classes ************************************/
/** @brief TrackerSampler based on CSC (current state centered), used by MIL algorithm TrackerMIL
*/
class CV_EXPORTS TrackerSamplerCSC : public TrackerSamplerAlgorithm
{
public:
enum
{
MODE_INIT_POS = 1, //!< mode for init positive samples
MODE_INIT_NEG = 2, //!< mode for init negative samples
MODE_TRACK_POS = 3, //!< mode for update positive samples
MODE_TRACK_NEG = 4, //!< mode for update negative samples
MODE_DETECT = 5 //!< mode for detect samples
};
struct CV_EXPORTS Params
{
Params();
float initInRad; //!< radius for gathering positive instances during init
float trackInPosRad; //!< radius for gathering positive instances during tracking
float searchWinSize; //!< size of search window
int initMaxNegNum; //!< # negative samples to use during init
int trackMaxPosNum; //!< # positive samples to use during training
int trackMaxNegNum; //!< # negative samples to use during training
};
/** @brief Constructor
@param parameters TrackerSamplerCSC parameters TrackerSamplerCSC::Params
*/
TrackerSamplerCSC( const TrackerSamplerCSC::Params ¶meters = TrackerSamplerCSC::Params() );
/** @brief Set the sampling mode of TrackerSamplerCSC
@param samplingMode The sampling mode
The modes are:
- "MODE_INIT_POS = 1" -- for the positive sampling in initialization step
- "MODE_INIT_NEG = 2" -- for the negative sampling in initialization step
- "MODE_TRACK_POS = 3" -- for the positive sampling in update step
- "MODE_TRACK_NEG = 4" -- for the negative sampling in update step
- "MODE_DETECT = 5" -- for the sampling in detection step
*/
void setMode( int samplingMode );
~TrackerSamplerCSC();
protected:
bool samplingImpl( const Mat& image, Rect boundingBox, std::vector<Mat>& sample );
private:
Params params;
int mode;
RNG rng;
std::vector<Mat> sampleImage( const Mat& img, int x, int y, int w, int h, float inrad, float outrad = 0, int maxnum = 1000000 );
};
/** @brief TrackerSampler based on CS (current state), used by algorithm TrackerBoosting
*/
class CV_EXPORTS TrackerSamplerCS : public TrackerSamplerAlgorithm
{
public:
enum
{
MODE_POSITIVE = 1, //!< mode for positive samples
MODE_NEGATIVE = 2, //!< mode for negative samples
MODE_CLASSIFY = 3 //!< mode for classify samples
};
struct CV_EXPORTS Params
{
Params();
float overlap; //!<overlapping for the search windows
float searchFactor; //!<search region parameter
};
/** @brief Constructor
@param parameters TrackerSamplerCS parameters TrackerSamplerCS::Params
*/
TrackerSamplerCS( const TrackerSamplerCS::Params ¶meters = TrackerSamplerCS::Params() );
/** @brief Set the sampling mode of TrackerSamplerCS
@param samplingMode The sampling mode
The modes are:
- "MODE_POSITIVE = 1" -- for the positive sampling
- "MODE_NEGATIVE = 2" -- for the negative sampling
- "MODE_CLASSIFY = 3" -- for the sampling in classification step
*/
void setMode( int samplingMode );
~TrackerSamplerCS();
bool samplingImpl( const Mat& image, Rect boundingBox, std::vector<Mat>& sample );
Rect getROI() const;
private:
Rect getTrackingROI( float searchFactor );
Rect RectMultiply( const Rect & rect, float f );
std::vector<Mat> patchesRegularScan( const Mat& image, Rect trackingROI, Size patchSize );
void setCheckedROI( Rect imageROI );
Params params;
int mode;
Rect trackedPatch;
Rect validROI;
Rect ROI;
};
/** @brief This sampler is based on particle filtering.
In principle, it can be thought of as performing some sort of optimization (and indeed, this
tracker uses opencv's optim module), where tracker seeks to find the rectangle in given frame,
which is the most *"similar"* to the initial rectangle (the one, given through the constructor).
The optimization performed is stochastic and somehow resembles genetic algorithms, where on each new
image received (submitted via TrackerSamplerPF::sampling()) we start with the region bounded by
boundingBox, then generate several "perturbed" boxes, take the ones most similar to the original.
This selection round is repeated several times. At the end, we hope that only the most promising box
remaining, and these are combined to produce the subrectangle of image, which is put as a sole
element in array sample.
It should be noted, that the definition of "similarity" between two rectangles is based on comparing
their histograms. As experiments show, tracker is *not* very succesfull if target is assumed to
strongly change its dimensions.
*/
class CV_EXPORTS TrackerSamplerPF : public TrackerSamplerAlgorithm
{
public:
/** @brief This structure contains all the parameters that can be varied during the course of sampling
algorithm. Below is the structure exposed, together with its members briefly explained with
reference to the above discussion on algorithm's working.
*/
struct CV_EXPORTS Params
{
Params();
int iterationNum; //!< number of selection rounds
int particlesNum; //!< number of "perturbed" boxes on each round
double alpha; //!< with each new round we exponentially decrease the amount of "perturbing" we allow (like in simulated annealing)
//!< and this very alpha controls how fast annealing happens, ie. how fast perturbing decreases
Mat_<double> std; //!< initial values for perturbing (1-by-4 array, as each rectangle is given by 4 values -- coordinates of opposite vertices,
//!< hence we have 4 values to perturb)
};
/** @brief Constructor
@param chosenRect Initial rectangle, that is supposed to contain target we'd like to track.
@param parameters
*/
TrackerSamplerPF(const Mat& chosenRect,const TrackerSamplerPF::Params ¶meters = TrackerSamplerPF::Params());
protected:
bool samplingImpl( const Mat& image, Rect boundingBox, std::vector<Mat>& sample );
private:
Params params;
Ptr<MinProblemSolver> _solver;
Ptr<MinProblemSolver::Function> _function;
};
/************************************ Specific TrackerFeature Classes ************************************/
/**
* \brief TrackerFeature based on Feature2D
*/
class CV_EXPORTS TrackerFeatureFeature2d : public TrackerFeature
{
public:
/**
* \brief Constructor
* \param detectorType string of FeatureDetector
* \param descriptorType string of DescriptorExtractor
*/
TrackerFeatureFeature2d( String detectorType, String descriptorType );
~TrackerFeatureFeature2d();
void selection( Mat& response, int npoints );
protected:
bool computeImpl( const std::vector<Mat>& images, Mat& response );
private:
std::vector<KeyPoint> keypoints;
};
/**
* \brief TrackerFeature based on HOG
*/
class CV_EXPORTS TrackerFeatureHOG : public TrackerFeature
{
public:
TrackerFeatureHOG();
~TrackerFeatureHOG();
void selection( Mat& response, int npoints );
protected:
bool computeImpl( const std::vector<Mat>& images, Mat& response );
};
/** @brief TrackerFeature based on HAAR features, used by TrackerMIL and many others algorithms
@note HAAR features implementation is copied from apps/traincascade and modified according to MIL
*/
class CV_EXPORTS TrackerFeatureHAAR : public TrackerFeature
{
public:
struct CV_EXPORTS Params
{
Params();
int numFeatures; //!< # of rects
Size rectSize; //!< rect size
bool isIntegral; //!< true if input images are integral, false otherwise
};
/** @brief Constructor
@param parameters TrackerFeatureHAAR parameters TrackerFeatureHAAR::Params
*/
TrackerFeatureHAAR( const TrackerFeatureHAAR::Params ¶meters = TrackerFeatureHAAR::Params() );
~TrackerFeatureHAAR();
/** @brief Compute the features only for the selected indices in the images collection
@param selFeatures indices of selected features
@param images The images
@param response Collection of response for the specific TrackerFeature
*/
bool extractSelected( const std::vector<int> selFeatures, const std::vector<Mat>& images, Mat& response );
/** @brief Identify most effective features
@param response Collection of response for the specific TrackerFeature
@param npoints Max number of features
@note This method modifies the response parameter
*/
void selection( Mat& response, int npoints );
/** @brief Swap the feature in position source with the feature in position target
@param source The source position
@param target The target position
*/
bool swapFeature( int source, int target );
/** @brief Swap the feature in position id with the feature input
@param id The position
@param feature The feature
*/
bool swapFeature( int id, CvHaarEvaluator::FeatureHaar& feature );
/** @brief Get the feature in position id
@param id The position
*/
CvHaarEvaluator::FeatureHaar& getFeatureAt( int id );
protected:
bool computeImpl( const std::vector<Mat>& images, Mat& response );
private:
Params params;
Ptr<CvHaarEvaluator> featureEvaluator;
};
/**
* \brief TrackerFeature based on LBP
*/
class CV_EXPORTS TrackerFeatureLBP : public TrackerFeature
{
public:
TrackerFeatureLBP();
~TrackerFeatureLBP();
void selection( Mat& response, int npoints );
protected:
bool computeImpl( const std::vector<Mat>& images, Mat& response );
};
/************************************ Specific Tracker Classes ************************************/
/** @brief The MIL algorithm trains a classifier in an online manner to separate the object from the
background.
Multiple Instance Learning avoids the drift problem for a robust tracking. The implementation is
based on @cite MIL .
Original code can be found here <http://vision.ucsd.edu/~bbabenko/project_miltrack.shtml>
*/
class CV_EXPORTS TrackerMIL : public Tracker
{
public:
struct CV_EXPORTS Params
{
Params();
//parameters for sampler
float samplerInitInRadius; //!< radius for gathering positive instances during init
int samplerInitMaxNegNum; //!< # negative samples to use during init
float samplerSearchWinSize; //!< size of search window
float samplerTrackInRadius; //!< radius for gathering positive instances during tracking
int samplerTrackMaxPosNum; //!< # positive samples to use during tracking
int samplerTrackMaxNegNum; //!< # negative samples to use during tracking
int featureSetNumFeatures; //!< # features
void read( const FileNode& fn );
void write( FileStorage& fs ) const;
};
/** @brief Constructor
@param parameters MIL parameters TrackerMIL::Params
*/
BOILERPLATE_CODE("MIL",TrackerMIL);
};
/** @brief This is a real-time object tracking based on a novel on-line version of the AdaBoost algorithm.
The classifier uses the surrounding background as negative examples in update step to avoid the
drifting problem. The implementation is based on @cite OLB .
*/
class CV_EXPORTS TrackerBoosting : public Tracker
{
public:
struct CV_EXPORTS Params
{
Params();
int numClassifiers; //!<the number of classifiers to use in a OnlineBoosting algorithm
float samplerOverlap; //!<search region parameters to use in a OnlineBoosting algorithm
float samplerSearchFactor; //!< search region parameters to use in a OnlineBoosting algorithm
int iterationInit; //!<the initial iterations
int featureSetNumFeatures; //!< # features
/**
* \brief Read parameters from file
*/
void read( const FileNode& fn );
/**
* \brief Write parameters in a file
*/
void write( FileStorage& fs ) const;
};
/** @brief Constructor
@param parameters BOOSTING parameters TrackerBoosting::Params
*/
BOILERPLATE_CODE("BOOSTING",TrackerBoosting);
};
/** @brief Median Flow tracker implementation.
Implementation of a paper @cite MedianFlow .
The tracker is suitable for very smooth and predictable movements when object is visible throughout
the whole sequence. It's quite and accurate for this type of problems (in particular, it was shown
by authors to outperform MIL). During the implementation period the code at
<http://www.aonsquared.co.uk/node/5>, the courtesy of the author Arthur Amarra, was used for the
reference purpose.
*/
class CV_EXPORTS TrackerMedianFlow : public Tracker
{
public:
struct CV_EXPORTS Params
{
Params();
int pointsInGrid; //!<square root of number of keypoints used; increase it to trade
//!<accurateness for speed; default value is sensible and recommended
void read( const FileNode& /*fn*/ );
void write( FileStorage& /*fs*/ ) const;
};
/** @brief Constructor
@param parameters Median Flow parameters TrackerMedianFlow::Params
*/
BOILERPLATE_CODE("MEDIANFLOW",TrackerMedianFlow);
};
/** @brief TLD is a novel tracking framework that explicitly decomposes the long-term tracking task into
tracking, learning and detection.
The tracker follows the object from frame to frame. The detector localizes all appearances that
have been observed so far and corrects the tracker if necessary. The learning estimates detector’s
errors and updates it to avoid these errors in the future. The implementation is based on @cite TLD .
The Median Flow algorithm (see cv::TrackerMedianFlow) was chosen as a tracking component in this
implementation, following authors. Tracker is supposed to be able to handle rapid motions, partial
occlusions, object absence etc.
*/
class CV_EXPORTS TrackerTLD : public Tracker
{
public:
struct CV_EXPORTS Params
{
Params();
void read( const FileNode& /*fn*/ );
void write( FileStorage& /*fs*/ ) const;
};
/** @brief Constructor
@param parameters TLD parameters TrackerTLD::Params
*/
BOILERPLATE_CODE("TLD",TrackerTLD);
};
/** @brief KCF is a novel tracking framework that utilizes properties of circulant matrix to enhance the processing speed.
* This tracking method is an implementation of @cite KCF_ECCV which is extended to KFC with color-names features (@cite KCF_CN).
* The original paper of KCF is available at <http://home.isr.uc.pt/~henriques/circulant/index.html>
* as well as the matlab implementation. For more information about KCF with color-names features, please refer to
* <http://www.cvl.isy.liu.se/research/objrec/visualtracking/colvistrack/index.html>.
*/
class CV_EXPORTS TrackerKCF : public Tracker
{
public:
/**
* \brief Feature type to be used in the tracking grayscale, colornames, compressed color-names
* The modes available now:
- "GRAY" -- Use grayscale values as the feature
- "CN" -- Color-names feature
*/
enum MODE {
GRAY = (1u << 0),
CN = (1u << 1),
CUSTOM = (1u << 2)
};
struct CV_EXPORTS Params
{
/**
* \brief Constructor
*/
Params();
/**
* \brief Read parameters from file, currently unused
*/
void read(const FileNode& /*fn*/);
/**
* \brief Read parameters from file, currently unused
*/
void write(FileStorage& /*fs*/) const;
double sigma; //!< gaussian kernel bandwidth
double lambda; //!< regularization
double interp_factor; //!< linear interpolation factor for adaptation
double output_sigma_factor; //!< spatial bandwidth (proportional to target)
double pca_learning_rate; //!< compression learning rate
bool resize; //!< activate the resize feature to improve the processing speed
bool split_coeff; //!< split the training coefficients into two matrices
bool wrap_kernel; //!< wrap around the kernel values
bool compress_feature; //!< activate the pca method to compress the features
int max_patch_size; //!< threshold for the ROI size
int compressed_size; //!< feature size after compression
unsigned int desc_pca; //!< compressed descriptors of TrackerKCF::MODE
unsigned int desc_npca; //!< non-compressed descriptors of TrackerKCF::MODE
};
virtual void setFeatureExtractor(void(*)(const Mat, const Rect, Mat&), bool pca_func = false);
/** @brief Constructor
@param parameters KCF parameters TrackerKCF::Params
*/
BOILERPLATE_CODE("KCF", TrackerKCF);
};
/** @brief GOTURN (@cite GOTURN) is kind of trackers based on Convolutional Neural Networks (CNN). While taking all advantages of CNN trackers,
* GOTURN is much faster due to offline training without online fine-tuning nature.
* GOTURN tracker addresses the problem of single target tracking: given a bounding box label of an object in the first frame of the video,
* we track that object through the rest of the video. NOTE: Current method of GOTURN does not handle occlusions; however, it is fairly
* robust to viewpoint changes, lighting changes, and deformations.
* Inputs of GOTURN are two RGB patches representing Target and Search patches resized to 227x227.
* Outputs of GOTURN are predicted bounding box coordinates, relative to Search patch coordinate system, in format X1,Y1,X2,Y2.
* Original paper is here: <http://davheld.github.io/GOTURN/GOTURN.pdf>
* As long as original authors implementation: <https://github.com/davheld/GOTURN#train-the-tracker>
* Implementation of training algorithm is placed in separately here due to 3d-party dependencies:
* <https://github.com/Auron-X/GOTURN_Training_Toolkit>
* GOTURN architecture goturn.prototxt and trained model goturn.caffemodel are accessible on opencv_extra GitHub repository.
*/
class CV_EXPORTS TrackerGOTURN : public Tracker
{
public:
struct CV_EXPORTS Params
{
Params();
void read(const FileNode& /*fn*/);
void write(FileStorage& /*fs*/) const;
};
/** @brief Constructor
@param parameters GOTURN parameters TrackerGOTURN::Params
*/
BOILERPLATE_CODE("GOTURN", TrackerGOTURN);
};
/************************************ MultiTracker Class ---By Laksono Kurnianggoro---) ************************************/
/** @brief This class is used to track multiple objects using the specified tracker algorithm.
* The MultiTracker is naive implementation of multiple object tracking.
* It process the tracked objects independently without any optimization accross the tracked objects.
*/
class CV_EXPORTS_W MultiTracker
{
public:
/**
* \brief Constructor.
* In the case of trackerType is given, it will be set as the default algorithm for all trackers.
* @param trackerType the name of the tracker algorithm to be used
*/
CV_WRAP MultiTracker(const String& trackerType = "");
/**
* \brief Destructor
*/
~MultiTracker();
/**
* \brief Add a new object to be tracked.
* The defaultAlgorithm will be used the newly added tracker.
* @param image input image
* @param boundingBox a rectangle represents ROI of the tracked object
*/
CV_WRAP bool add(const Mat& image, const Rect2d& boundingBox);
/**
* \brief Add a new object to be tracked.
* @param trackerType the name of the tracker algorithm to be used
* @param image input image
* @param boundingBox a rectangle represents ROI of the tracked object
*/
CV_WRAP bool add(const String& trackerType, const Mat& image, const Rect2d& boundingBox);
/**
* \brief Add a set of objects to be tracked.
* @param trackerType the name of the tracker algorithm to be used
* @param image input image
* @param boundingBox list of the tracked objects
*/
CV_WRAP bool add(const String& trackerType, const Mat& image, std::vector<Rect2d> boundingBox);
/**
* \brief Add a set of objects to be tracked using the defaultAlgorithm tracker.
* @param image input image
* @param boundingBox list of the tracked objects
*/
CV_WRAP bool add(const Mat& image, std::vector<Rect2d> boundingBox);
/**
* \brief Update the current tracking status.
* The result will be saved in the internal storage.
* @param image input image
*/
bool update(const Mat& image);
//!< storage for the tracked objects, each object corresponds to one tracker algorithm.
std::vector<Rect2d> objects;
/**
* \brief Update the current tracking status.
* @param image input image
* @param boundingBox the tracking result, represent a list of ROIs of the tracked objects.
*/
CV_WRAP bool update(const Mat& image, CV_OUT std::vector<Rect2d> & boundingBox);
protected:
//!< storage for the tracker algorithms.
std::vector< Ptr<Tracker> > trackerList;
//!< default algorithm for the tracking method.
String defaultAlgorithm;
};
class ROISelector {
public:
Rect2d select(Mat img, bool fromCenter = true);
Rect2d select(const cv::String& windowName, Mat img, bool showCrossair = true, bool fromCenter = true);
void select(const cv::String& windowName, Mat img, std::vector<Rect2d> & boundingBox, bool fromCenter = true);
struct handlerT{
// basic parameters
bool isDrawing;
Rect2d box;
Mat image;
// parameters for drawing from the center
bool drawFromCenter;
Point2f center;
// initializer list
handlerT() : isDrawing(false), drawFromCenter(true) {};
}selectorParams;
// to store the tracked objects
std::vector<handlerT> objects;
private:
static void mouseHandler(int event, int x, int y, int flags, void *param);
void opencv_mouse_callback(int event, int x, int y, int, void *param);
// save the keypressed characted
int key;
};
Rect2d CV_EXPORTS_W selectROI(Mat img, bool fromCenter = true);
Rect2d CV_EXPORTS_W selectROI(const cv::String& windowName, Mat img, bool showCrossair = true, bool fromCenter = true);
void CV_EXPORTS_W selectROI(const cv::String& windowName, Mat img, std::vector<Rect2d> & boundingBox, bool fromCenter = true);
/************************************ Multi-Tracker Classes ---By Tyan Vladimir---************************************/
/** @brief Base abstract class for the long-term Multi Object Trackers:
@sa Tracker, MultiTrackerTLD
*/
class CV_EXPORTS MultiTracker_Alt
{
public:
/** @brief Constructor for Multitracker
*/
MultiTracker_Alt()
{
targetNum = 0;
}
/** @brief Add a new target to a tracking-list and initialize the tracker with a know bounding box that surrounding the target
@param image The initial frame
@param boundingBox The initial boundig box of target
@param tracker_algorithm_name Multi-tracker algorithm name
@return True if new target initialization went succesfully, false otherwise
*/
bool addTarget(const Mat& image, const Rect2d& boundingBox, String tracker_algorithm_name);
/** @brief Update all trackers from the tracking-list, find a new most likely bounding boxes for the targets
@param image The current frame
@return True means that all targets were located and false means that tracker couldn't locate one of the targets in
current frame. Note, that latter *does not* imply that tracker has failed, maybe target is indeed
missing from the frame (say, out of sight)
*/
bool update(const Mat& image);
/** @brief Current number of targets in tracking-list
*/
int targetNum;
/** @brief Trackers list for Multi-Object-Tracker
*/
std::vector <Ptr<Tracker> > trackers;
/** @brief Bounding Boxes list for Multi-Object-Tracker
*/
std::vector <Rect2d> boundingBoxes;
/** @brief List of randomly generated colors for bounding boxes display
*/
std::vector<Scalar> colors;
};
/** @brief Multi Object Tracker for TLD. TLD is a novel tracking framework that explicitly decomposes
the long-term tracking task into tracking, learning and detection.
The tracker follows the object from frame to frame. The detector localizes all appearances that
have been observed so far and corrects the tracker if necessary. The learning estimates detector’s
errors and updates it to avoid these errors in the future. The implementation is based on @cite TLD .
The Median Flow algorithm (see cv::TrackerMedianFlow) was chosen as a tracking component in this
implementation, following authors. Tracker is supposed to be able to handle rapid motions, partial
occlusions, object absence etc.
@sa Tracker, MultiTracker, TrackerTLD
*/
class CV_EXPORTS MultiTrackerTLD : public MultiTracker_Alt
{
public:
/** @brief Update all trackers from the tracking-list, find a new most likely bounding boxes for the targets by
optimized update method using some techniques to speedup calculations specifically for MO TLD. The only limitation
is that all target bounding boxes should have approximately same aspect ratios. Speed boost is around 20%
@param image The current frame.
@return True means that all targets were located and false means that tracker couldn't locate one of the targets in
current frame. Note, that latter *does not* imply that tracker has failed, maybe target is indeed
missing from the frame (say, out of sight)
*/
bool update_opt(const Mat& image);
};
//! @}
} /* namespace cv */
#endif
|