1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
4 
5 #ifndef OPENCV_VIDEO_DETAIL_TRACKING_MIL_STATE_HPP
6 #define OPENCV_VIDEO_DETAIL_TRACKING_MIL_STATE_HPP
7 
8 #include "opencv2/video/detail/tracking.detail.hpp"
9 #include "tracking_online_mil.hpp"
10 
11 namespace cv {
12 namespace detail {
13 inline namespace tracking {
14 
15 /** @brief TrackerStateEstimator based on Boosting
16 */
17 class CV_EXPORTS TrackerStateEstimatorMILBoosting : public TrackerStateEstimator
18 {
19 public:
20     /**
21     * Implementation of the target state for TrackerStateEstimatorMILBoosting
22     */
23     class TrackerMILTargetState : public TrackerTargetState
24     {
25 
26     public:
27         /**
28         * \brief Constructor
29         * \param position Top left corner of the bounding box
30         * \param width Width of the bounding box
31         * \param height Height of the bounding box
32         * \param foreground label for target or background
33         * \param features features extracted
34         */
35         TrackerMILTargetState(const Point2f& position, int width, int height, bool foreground, const Mat& features);
36 
~TrackerMILTargetState()37         ~TrackerMILTargetState() {};
38 
39         /** @brief Set label: true for target foreground, false for background
40         @param foreground Label for background/foreground
41         */
42         void setTargetFg(bool foreground);
43         /** @brief Set the features extracted from TrackerFeatureSet
44         @param features The features extracted
45         */
46         void setFeatures(const Mat& features);
47         /** @brief Get the label. Return true for target foreground, false for background
48         */
49         bool isTargetFg() const;
50         /** @brief Get the features extracted
51         */
52         Mat getFeatures() const;
53 
54     private:
55         bool isTarget;
56         Mat targetFeatures;
57     };
58 
59     /** @brief Constructor
60     @param nFeatures Number of features for each sample
61     */
62     TrackerStateEstimatorMILBoosting(int nFeatures = 250);
63     ~TrackerStateEstimatorMILBoosting();
64 
65     /** @brief Set the current confidenceMap
66     @param confidenceMap The current :cConfidenceMap
67     */
68     void setCurrentConfidenceMap(ConfidenceMap& confidenceMap);
69 
70 protected:
71     Ptr<TrackerTargetState> estimateImpl(const std::vector<ConfidenceMap>& confidenceMaps) CV_OVERRIDE;
72     void updateImpl(std::vector<ConfidenceMap>& confidenceMaps) CV_OVERRIDE;
73 
74 private:
75     uint max_idx(const std::vector<float>& v);
76     void prepareData(const ConfidenceMap& confidenceMap, Mat& positive, Mat& negative);
77 
78     ClfMilBoost boostMILModel;
79     bool trained;
80     int numFeatures;
81 
82     ConfidenceMap currentConfidenceMap;
83 };
84 
85 }}}  // namespace cv::detail::tracking
86 
87 #endif
88