47
47
#include " feature.hpp"
48
48
#include " onlineMIL.hpp"
49
49
#include " onlineBoosting.hpp"
50
- #include < iostream>
51
-
52
-
53
- #define BOILERPLATE_CODE (name,classname ) \
54
- static Ptr<classname> createTracker (const classname::Params ¶meters=classname::Params());\
55
- virtual ~classname (){};
56
50
57
51
/*
58
52
* Partially based on:
@@ -539,7 +533,7 @@ class CV_EXPORTS_W Tracker : public virtual Algorithm
539
533
540
534
@return True if initialization went succesfully, false otherwise
541
535
*/
542
- CV_WRAP bool init ( const Mat& image, const Rect2d& boundingBox );
536
+ CV_WRAP bool init ( InputArray image, const Rect2d& boundingBox );
543
537
544
538
/* * @brief Update the tracker, find the new most likely bounding box for the target
545
539
@param image The current frame
@@ -550,17 +544,7 @@ class CV_EXPORTS_W Tracker : public virtual Algorithm
550
544
current frame. Note, that latter *does not* imply that tracker has failed, maybe target is indeed
551
545
missing from the frame (say, out of sight)
552
546
*/
553
- CV_WRAP bool update ( const Mat& image, CV_OUT Rect2d& boundingBox );
554
-
555
- /* * @brief Creates a tracker by its name.
556
- @param trackerType Tracker type
557
-
558
- The following detector types are supported:
559
-
560
- - "MIL" -- TrackerMIL
561
- - "BOOSTING" -- TrackerBoosting
562
- */
563
- CV_WRAP static Ptr<Tracker> create ( const String& trackerType );
547
+ CV_WRAP bool update ( InputArray image, CV_OUT Rect2d& boundingBox );
564
548
565
549
virtual void read ( const FileNode& fn )=0;
566
550
virtual void write ( FileStorage& fs ) const =0;
@@ -1078,7 +1062,7 @@ based on @cite MIL .
1078
1062
1079
1063
Original code can be found here <http://vision.ucsd.edu/~bbabenko/project_miltrack.shtml>
1080
1064
*/
1081
- class CV_EXPORTS TrackerMIL : public Tracker
1065
+ class CV_EXPORTS_W TrackerMIL : public Tracker
1082
1066
{
1083
1067
public:
1084
1068
struct CV_EXPORTS Params
@@ -1100,15 +1084,19 @@ class CV_EXPORTS TrackerMIL : public Tracker
1100
1084
/* * @brief Constructor
1101
1085
@param parameters MIL parameters TrackerMIL::Params
1102
1086
*/
1103
- BOILERPLATE_CODE (" MIL" ,TrackerMIL);
1087
+ static Ptr<TrackerMIL> create (const TrackerMIL::Params ¶meters);
1088
+
1089
+ CV_WRAP static Ptr<TrackerMIL> create ();
1090
+
1091
+ virtual ~TrackerMIL () {}
1104
1092
};
1105
1093
1106
1094
/* * @brief This is a real-time object tracking based on a novel on-line version of the AdaBoost algorithm.
1107
1095
1108
1096
The classifier uses the surrounding background as negative examples in update step to avoid the
1109
1097
drifting problem. The implementation is based on @cite OLB .
1110
1098
*/
1111
- class CV_EXPORTS TrackerBoosting : public Tracker
1099
+ class CV_EXPORTS_W TrackerBoosting : public Tracker
1112
1100
{
1113
1101
public:
1114
1102
struct CV_EXPORTS Params
@@ -1133,7 +1121,11 @@ class CV_EXPORTS TrackerBoosting : public Tracker
1133
1121
/* * @brief Constructor
1134
1122
@param parameters BOOSTING parameters TrackerBoosting::Params
1135
1123
*/
1136
- BOILERPLATE_CODE (" BOOSTING" ,TrackerBoosting);
1124
+ static Ptr<TrackerBoosting> create (const TrackerBoosting::Params ¶meters);
1125
+
1126
+ CV_WRAP static Ptr<TrackerBoosting> create ();
1127
+
1128
+ virtual ~TrackerBoosting () {}
1137
1129
};
1138
1130
1139
1131
/* * @brief Median Flow tracker implementation.
@@ -1146,7 +1138,7 @@ by authors to outperform MIL). During the implementation period the code at
1146
1138
<http://www.aonsquared.co.uk/node/5>, the courtesy of the author Arthur Amarra, was used for the
1147
1139
reference purpose.
1148
1140
*/
1149
- class CV_EXPORTS TrackerMedianFlow : public Tracker
1141
+ class CV_EXPORTS_W TrackerMedianFlow : public Tracker
1150
1142
{
1151
1143
public:
1152
1144
struct CV_EXPORTS Params
@@ -1168,7 +1160,11 @@ class CV_EXPORTS TrackerMedianFlow : public Tracker
1168
1160
/* * @brief Constructor
1169
1161
@param parameters Median Flow parameters TrackerMedianFlow::Params
1170
1162
*/
1171
- BOILERPLATE_CODE (" MEDIANFLOW" ,TrackerMedianFlow);
1163
+ static Ptr<TrackerMedianFlow> create (const TrackerMedianFlow::Params ¶meters);
1164
+
1165
+ CV_WRAP static Ptr<TrackerMedianFlow> create ();
1166
+
1167
+ virtual ~TrackerMedianFlow () {}
1172
1168
};
1173
1169
1174
1170
/* * @brief TLD is a novel tracking framework that explicitly decomposes the long-term tracking task into
@@ -1182,7 +1178,7 @@ The Median Flow algorithm (see cv::TrackerMedianFlow) was chosen as a tracking c
1182
1178
implementation, following authors. Tracker is supposed to be able to handle rapid motions, partial
1183
1179
occlusions, object absence etc.
1184
1180
*/
1185
- class CV_EXPORTS TrackerTLD : public Tracker
1181
+ class CV_EXPORTS_W TrackerTLD : public Tracker
1186
1182
{
1187
1183
public:
1188
1184
struct CV_EXPORTS Params
@@ -1195,7 +1191,11 @@ class CV_EXPORTS TrackerTLD : public Tracker
1195
1191
/* * @brief Constructor
1196
1192
@param parameters TLD parameters TrackerTLD::Params
1197
1193
*/
1198
- BOILERPLATE_CODE (" TLD" ,TrackerTLD);
1194
+ static Ptr<TrackerTLD> create (const TrackerTLD::Params ¶meters);
1195
+
1196
+ CV_WRAP static Ptr<TrackerTLD> create ();
1197
+
1198
+ virtual ~TrackerTLD () {}
1199
1199
};
1200
1200
1201
1201
/* * @brief KCF is a novel tracking framework that utilizes properties of circulant matrix to enhance the processing speed.
@@ -1204,7 +1204,7 @@ class CV_EXPORTS TrackerTLD : public Tracker
1204
1204
* as well as the matlab implementation. For more information about KCF with color-names features, please refer to
1205
1205
* <http://www.cvl.isy.liu.se/research/objrec/visualtracking/colvistrack/index.html>.
1206
1206
*/
1207
- class CV_EXPORTS TrackerKCF : public Tracker
1207
+ class CV_EXPORTS_W TrackerKCF : public Tracker
1208
1208
{
1209
1209
public:
1210
1210
/* *
@@ -1251,12 +1251,16 @@ class CV_EXPORTS TrackerKCF : public Tracker
1251
1251
int desc_npca; // !< non-compressed descriptors of TrackerKCF::MODE
1252
1252
};
1253
1253
1254
- virtual void setFeatureExtractor (void (*)(const Mat, const Rect, Mat&), bool pca_func = false);
1254
+ virtual void setFeatureExtractor (void (*)(const Mat, const Rect, Mat&), bool pca_func = false) = 0 ;
1255
1255
1256
1256
/* * @brief Constructor
1257
1257
@param parameters KCF parameters TrackerKCF::Params
1258
1258
*/
1259
- BOILERPLATE_CODE (" KCF" , TrackerKCF);
1259
+ static Ptr<TrackerKCF> create (const TrackerKCF::Params ¶meters);
1260
+
1261
+ CV_WRAP static Ptr<TrackerKCF> create ();
1262
+
1263
+ virtual ~TrackerKCF () {}
1260
1264
};
1261
1265
1262
1266
/* * @brief GOTURN (@cite GOTURN) is kind of trackers based on Convolutional Neural Networks (CNN). While taking all advantages of CNN trackers,
@@ -1272,7 +1276,7 @@ class CV_EXPORTS TrackerKCF : public Tracker
1272
1276
* <https://github.com/Auron-X/GOTURN_Training_Toolkit>
1273
1277
* GOTURN architecture goturn.prototxt and trained model goturn.caffemodel are accessible on opencv_extra GitHub repository.
1274
1278
*/
1275
- class CV_EXPORTS TrackerGOTURN : public Tracker
1279
+ class CV_EXPORTS_W TrackerGOTURN : public Tracker
1276
1280
{
1277
1281
public:
1278
1282
struct CV_EXPORTS Params
@@ -1285,24 +1289,26 @@ class CV_EXPORTS TrackerGOTURN : public Tracker
1285
1289
/* * @brief Constructor
1286
1290
@param parameters GOTURN parameters TrackerGOTURN::Params
1287
1291
*/
1288
- BOILERPLATE_CODE (" GOTURN" , TrackerGOTURN);
1292
+ static Ptr<TrackerGOTURN> create (const TrackerGOTURN::Params ¶meters);
1293
+
1294
+ CV_WRAP static Ptr<TrackerGOTURN> create ();
1295
+
1296
+ virtual ~TrackerGOTURN () {}
1289
1297
};
1290
1298
1291
1299
/* *********************************** MultiTracker Class ---By Laksono Kurnianggoro---) ************************************/
1292
1300
/* * @brief This class is used to track multiple objects using the specified tracker algorithm.
1293
1301
* The MultiTracker is naive implementation of multiple object tracking.
1294
1302
* It process the tracked objects independently without any optimization accross the tracked objects.
1295
1303
*/
1296
- class CV_EXPORTS_W MultiTracker
1304
+ class CV_EXPORTS_W MultiTracker : public Algorithm
1297
1305
{
1298
1306
public:
1299
1307
1300
1308
/* *
1301
1309
* \brief Constructor.
1302
- * In the case of trackerType is given, it will be set as the default algorithm for all trackers.
1303
- * @param trackerType the name of the tracker algorithm to be used
1304
1310
*/
1305
- CV_WRAP MultiTracker (const String& trackerType = " " );
1311
+ CV_WRAP MultiTracker ();
1306
1312
1307
1313
/* *
1308
1314
* \brief Destructor
@@ -1311,58 +1317,51 @@ class CV_EXPORTS_W MultiTracker
1311
1317
1312
1318
/* *
1313
1319
* \brief Add a new object to be tracked.
1314
- * The defaultAlgorithm will be used the newly added tracker.
1315
- * @param image input image
1316
- * @param boundingBox a rectangle represents ROI of the tracked object
1317
- */
1318
- CV_WRAP bool add (const Mat& image, const Rect2d& boundingBox);
1319
-
1320
- /* *
1321
- * \brief Add a new object to be tracked.
1322
- * @param trackerType the name of the tracker algorithm to be used
1320
+ *
1321
+ * @param newTracker tracking algorithm to be used
1323
1322
* @param image input image
1324
1323
* @param boundingBox a rectangle represents ROI of the tracked object
1325
1324
*/
1326
- CV_WRAP bool add (const String& trackerType, const Mat& image, const Rect2d& boundingBox);
1325
+ CV_WRAP bool add (Ptr<Tracker> newTracker, InputArray image, const Rect2d& boundingBox);
1327
1326
1328
1327
/* *
1329
1328
* \brief Add a set of objects to be tracked.
1330
- * @param trackerType the name of the tracker algorithm to be used
1329
+ * @param newTrackers list of tracking algorithms to be used
1331
1330
* @param image input image
1332
1331
* @param boundingBox list of the tracked objects
1333
1332
*/
1334
- CV_WRAP bool add (const String& trackerType, const Mat& image, std::vector<Rect2d> boundingBox);
1333
+ bool add (std::vector<Ptr<Tracker> > newTrackers, InputArray image, std::vector<Rect2d> boundingBox);
1335
1334
1336
1335
/* *
1337
- * \brief Add a set of objects to be tracked using the defaultAlgorithm tracker.
1336
+ * \brief Update the current tracking status.
1337
+ * The result will be saved in the internal storage.
1338
1338
* @param image input image
1339
- * @param boundingBox list of the tracked objects
1340
1339
*/
1341
- CV_WRAP bool add ( const Mat& image, std::vector<Rect2d> boundingBox );
1340
+ bool update (InputArray image);
1342
1341
1343
1342
/* *
1344
1343
* \brief Update the current tracking status.
1345
- * The result will be saved in the internal storage.
1346
1344
* @param image input image
1345
+ * @param boundingBox the tracking result, represent a list of ROIs of the tracked objects.
1347
1346
*/
1348
- bool update (const Mat& image );
1347
+ CV_WRAP bool update (InputArray image, CV_OUT std::vector<Rect2d> & boundingBox );
1349
1348
1350
- // !< storage for the tracked objects, each object corresponds to one tracker algorithm.
1351
- std::vector<Rect2d> objects;
1349
+ /* *
1350
+ * \brief Returns a reference to a storage for the tracked objects, each object corresponds to one tracker algorithm
1351
+ */
1352
+ CV_WRAP const std::vector<Rect2d>& getObjects () const ;
1352
1353
1353
1354
/* *
1354
- * \brief Update the current tracking status.
1355
- * @param image input image
1356
- * @param boundingBox the tracking result, represent a list of ROIs of the tracked objects.
1355
+ * \brief Returns a pointer to a new instance of MultiTracker
1357
1356
*/
1358
- CV_WRAP bool update ( const Mat& image, CV_OUT std::vector<Rect2d> & boundingBox );
1357
+ CV_WRAP static Ptr<MultiTracker> create ( );
1359
1358
1360
1359
protected:
1361
1360
// !< storage for the tracker algorithms.
1362
1361
std::vector< Ptr<Tracker> > trackerList;
1363
1362
1364
- // !< default algorithm for the tracking method .
1365
- String defaultAlgorithm ;
1363
+ // !< storage for the tracked objects, each object corresponds to one tracker algorithm .
1364
+ std::vector<Rect2d> objects ;
1366
1365
};
1367
1366
1368
1367
/* *********************************** Multi-Tracker Classes ---By Tyan Vladimir---************************************/
@@ -1384,11 +1383,11 @@ class CV_EXPORTS MultiTracker_Alt
1384
1383
/* * @brief Add a new target to a tracking-list and initialize the tracker with a know bounding box that surrounding the target
1385
1384
@param image The initial frame
1386
1385
@param boundingBox The initial boundig box of target
1387
- @param tracker_algorithm_name Multi-tracker algorithm name
1386
+ @param tracker_algorithm Multi-tracker algorithm
1388
1387
1389
1388
@return True if new target initialization went succesfully, false otherwise
1390
1389
*/
1391
- bool addTarget (const Mat& image, const Rect2d& boundingBox, String tracker_algorithm_name );
1390
+ bool addTarget (InputArray image, const Rect2d& boundingBox, Ptr<Tracker> tracker_algorithm );
1392
1391
1393
1392
/* * @brief Update all trackers from the tracking-list, find a new most likely bounding boxes for the targets
1394
1393
@param image The current frame
@@ -1397,7 +1396,7 @@ class CV_EXPORTS MultiTracker_Alt
1397
1396
current frame. Note, that latter *does not* imply that tracker has failed, maybe target is indeed
1398
1397
missing from the frame (say, out of sight)
1399
1398
*/
1400
- bool update (const Mat& image);
1399
+ bool update (InputArray image);
1401
1400
1402
1401
/* * @brief Current number of targets in tracking-list
1403
1402
*/
@@ -1441,7 +1440,7 @@ class CV_EXPORTS MultiTrackerTLD : public MultiTracker_Alt
1441
1440
current frame. Note, that latter *does not* imply that tracker has failed, maybe target is indeed
1442
1441
missing from the frame (say, out of sight)
1443
1442
*/
1444
- bool update_opt (const Mat& image);
1443
+ bool update_opt (InputArray image);
1445
1444
};
1446
1445
1447
1446
// ! @}
0 commit comments