@@ -1204,53 +1204,173 @@ class CV_EXPORTS_W TrackerTLD : public Tracker
12041204 */
12051205class CV_EXPORTS_W TrackerKCF : public Tracker
12061206{
1207- public:
1208- /* *
1209- * \brief Feature type to be used in the tracking grayscale, colornames, compressed color-names
1210- * The modes available now:
1211- - "GRAY" -- Use grayscale values as the feature
1212- - "CN" -- Color-names feature
1213- */
1214- enum MODE {GRAY, CN, CN2};
1207+ public:
1208+ /* *
1209+ * \brief Feature type to be used in the tracking grayscale, colornames, compressed color-names
1210+ * The modes available now:
1211+ - "GRAY" -- Use grayscale values as the feature
1212+ - "CN" -- Color-names feature
1213+ */
1214+ enum MODE {
1215+ GRAY = (1u << 0 ),
1216+ CN = (1u << 1 ),
1217+ CUSTOM = (1u << 2 )
1218+ };
12151219
1216- struct CV_EXPORTS Params
1217- {
1218- /* *
1219- * \brief Constructor
1220- */
1221- Params ();
1220+ struct CV_EXPORTS Params
1221+ {
1222+ /* *
1223+ * \brief Constructor
1224+ */
1225+ Params ();
1226+
1227+ /* *
1228+ * \brief Read parameters from file, currently unused
1229+ */
1230+ void read (const FileNode& /* fn*/ );
1231+
1232+ /* *
1233+ * \brief Read parameters from file, currently unused
1234+ */
1235+ void write (FileStorage& /* fs*/ ) const ;
1236+
1237+ double sigma; // !< gaussian kernel bandwidth
1238+ double lambda; // !< regularization
1239+ double interp_factor; // !< linear interpolation factor for adaptation
1240+ double output_sigma_factor; // !< spatial bandwidth (proportional to target)
1241+ double pca_learning_rate; // !< compression learning rate
1242+ bool resize; // !< activate the resize feature to improve the processing speed
1243+ bool split_coeff; // !< split the training coefficients into two matrices
1244+ bool wrap_kernel; // !< wrap around the kernel values
1245+ bool compress_feature; // !< activate the pca method to compress the features
1246+ int max_patch_size; // !< threshold for the ROI size
1247+ int compressed_size; // !< feature size after compression
1248+ unsigned int desc_pca; // !< compressed descriptors of TrackerKCF::MODE
1249+ unsigned int desc_npca; // !< non-compressed descriptors of TrackerKCF::MODE
1250+ };
1251+
1252+ virtual void setFeatureExtractor (void (*)(const Mat, const Rect, Mat&), bool pca_func = false);
1253+
1254+ /* * @brief Constructor
1255+ @param parameters KCF parameters TrackerKCF::Params
1256+ */
1257+ BOILERPLATE_CODE (" KCF" , TrackerKCF);
1258+ };
12221259
1223- /* *
1224- * \brief Read parameters from file, currently unused
1225- */
1226- void read ( const FileNode& /* fn*/ );
1260+ /* *********************************** MultiTracker Class ---By Laksono Kurnianggoro---) ************************************/
1261+ /* * @brief This class is used to track multiple objects using the specified tracker algorithm.
1262+ * The MultiTracker is naive implementation of multiple object tracking.
1263+ * It process the tracked objects independently without any optimization accross the tracked objects.
1264+ */
1265+ class CV_EXPORTS_W MultiTracker
1266+ {
1267+ public:
12271268
1228- /* *
1229- * \brief Read parameters from file, currently unused
1230- */
1231- void write ( FileStorage& /* fs*/ ) const ;
1269+ /* *
1270+ * \brief Constructor.
1271+ * In the case of trackerType is given, it will be set as the default algorithm for all trackers.
1272+ * @param trackerType the name of the tracker algorithm to be used
1273+ */
1274+ MultiTracker (const String& trackerType = " " );
12321275
1233- double sigma; // !< gaussian kernel bandwidth
1234- double lambda; // !< regularization
1235- double interp_factor; // !< linear interpolation factor for adaptation
1236- double output_sigma_factor; // !< spatial bandwidth (proportional to target)
1237- double pca_learning_rate; // !< compression learning rate
1238- bool resize; // !< activate the resize feature to improve the processing speed
1239- bool split_coeff; // !< split the training coefficients into two matrices
1240- bool wrap_kernel; // !< wrap around the kernel values
1241- bool compress_feature; // !< activate the pca method to compress the features
1242- int max_patch_size; // !< threshold for the ROI size
1243- int compressed_size; // !< feature size after compression
1244- MODE descriptor; // !< descriptor type
1245- };
1276+ /* *
1277+ * \brief Destructor
1278+ */
1279+ ~MultiTracker ();
12461280
1247- /* * @brief Constructor
1248- @param parameters KCF parameters TrackerKCF::Params
1249- */
1250- BOILERPLATE_CODE (" KCF" ,TrackerKCF);
1281+ /* *
1282+ * \brief Add a new object to be tracked.
1283+ * The defaultAlgorithm will be used the newly added tracker.
1284+ * @param image input image
1285+ * @param boundingBox a rectangle represents ROI of the tracked object
1286+ */
1287+ bool add (const Mat& image, const Rect2d& boundingBox);
1288+
1289+ /* *
1290+ * \brief Add a new object to be tracked.
1291+ * @param trackerType the name of the tracker algorithm to be used
1292+ * @param image input image
1293+ * @param boundingBox a rectangle represents ROI of the tracked object
1294+ */
1295+ bool add (const String& trackerType, const Mat& image, const Rect2d& boundingBox);
1296+
1297+ /* *
1298+ * \brief Add a set of objects to be tracked.
1299+ * @param trackerType the name of the tracker algorithm to be used
1300+ * @param image input image
1301+ * @param boundingBox list of the tracked objects
1302+ */
1303+ bool add (const String& trackerType, const Mat& image, std::vector<Rect2d> boundingBox);
1304+
1305+ /* *
1306+ * \brief Add a set of objects to be tracked using the defaultAlgorithm tracker.
1307+ * @param image input image
1308+ * @param boundingBox list of the tracked objects
1309+ */
1310+ bool add (const Mat& image, std::vector<Rect2d> boundingBox);
1311+
1312+ /* *
1313+ * \brief Update the current tracking status.
1314+ * The result will be saved in the internal storage.
1315+ * @param image input image
1316+ */
1317+ bool update (const Mat& image);
1318+
1319+ // !< storage for the tracked objects, each object corresponds to one tracker algorithm.
1320+ std::vector<Rect2d> objects;
1321+
1322+ /* *
1323+ * \brief Update the current tracking status.
1324+ * @param image input image
1325+ * @param boundingBox the tracking result, represent a list of ROIs of the tracked objects.
1326+ */
1327+ bool update (const Mat& image, std::vector<Rect2d> & boundingBox);
1328+
1329+ protected:
1330+ // !< storage for the tracker algorithms.
1331+ std::vector< Ptr<Tracker> > trackerList;
1332+
1333+ // !< default algorithm for the tracking method.
1334+ String defaultAlgorithm;
1335+ };
1336+
1337+ class ROISelector {
1338+ public:
1339+ Rect2d select (Mat img, bool fromCenter = true );
1340+ Rect2d select (const std::string& windowName, Mat img, bool showCrossair = true , bool fromCenter = true );
1341+ void select (const std::string& windowName, Mat img, std::vector<Rect2d> & boundingBox, bool fromCenter = true );
1342+
1343+ struct handlerT {
1344+ // basic parameters
1345+ bool isDrawing;
1346+ Rect2d box;
1347+ Mat image;
1348+
1349+ // parameters for drawing from the center
1350+ bool drawFromCenter;
1351+ Point2f center;
1352+
1353+ // initializer list
1354+ handlerT () : isDrawing(false ), drawFromCenter(true ) {};
1355+ }selectorParams;
1356+
1357+ // to store the tracked objects
1358+ std::vector<handlerT> objects;
1359+
1360+ private:
1361+ static void mouseHandler (int event, int x, int y, int flags, void *param);
1362+ void opencv_mouse_callback (int event, int x, int y, int , void *param);
1363+
1364+ // save the keypressed characted
1365+ int key;
12511366};
12521367
1253- /* *********************************** Multi-Tracker Classes ************************************/
1368+ Rect2d CV_EXPORTS_W selectROI (Mat img, bool fromCenter = true );
1369+ Rect2d CV_EXPORTS_W selectROI (const std::string& windowName, Mat img, bool showCrossair = true , bool fromCenter = true );
1370+ void CV_EXPORTS_W selectROI (const std::string& windowName, Mat img, std::vector<Rect2d> & boundingBox, bool fromCenter = true );
1371+
1372+
1373+ /* *********************************** Multi-Tracker Classes ---By Tyan Vladimir---************************************/
12541374
12551375/* * @brief Base abstract class for the long-term Multi Object Trackers:
12561376
@@ -1261,7 +1381,7 @@ class CV_EXPORTS_W MultiTracker_Alt
12611381public:
12621382 /* * @brief Constructor for Multitracker
12631383 */
1264- MultiTracker ()
1384+ MultiTracker_Alt ()
12651385 {
12661386 targetNum = 0 ;
12671387 }
@@ -1277,6 +1397,7 @@ class CV_EXPORTS_W MultiTracker_Alt
12771397
12781398 /* * @brief Update all trackers from the tracking-list, find a new most likely bounding boxes for the targets
12791399 @param image The current frame
1400+
12801401 @return True means that all targets were located and false means that tracker couldn't locate one of the targets in
12811402 current frame. Note, that latter *does not* imply that tracker has failed, maybe target is indeed
12821403 missing from the frame (say, out of sight)
0 commit comments