Initialize the tracker
| 125 | |
| 126 | // Initialize the tracker |
| 127 | bool CVTracker::initTracker(cv::Mat &frame, size_t frameId) |
| 128 | { |
| 129 | // Create new tracker object |
| 130 | tracker = selectTracker(trackerType); |
| 131 | |
| 132 | // Correct negative width/height |
| 133 | if (bbox.width < 0) { |
| 134 | bbox.x -= bbox.width; |
| 135 | bbox.width = -bbox.width; |
| 136 | } |
| 137 | if (bbox.height < 0) { |
| 138 | bbox.y -= bbox.height; |
| 139 | bbox.height = -bbox.height; |
| 140 | } |
| 141 | |
| 142 | // Clamp to frame bounds |
| 143 | clampRect(bbox, frame.cols, frame.rows); |
| 144 | |
| 145 | // Initialize tracker |
| 146 | tracker->init(frame, bbox); |
| 147 | |
| 148 | float fw = float(frame.cols), fh = float(frame.rows); |
| 149 | |
| 150 | // record original pixel size |
| 151 | origWidth = bbox.width; |
| 152 | origHeight = bbox.height; |
| 153 | |
| 154 | // initialize sub-pixel smoother at true center |
| 155 | smoothC_x = bbox.x + bbox.width * 0.5; |
| 156 | smoothC_y = bbox.y + bbox.height * 0.5; |
| 157 | |
| 158 | // Add new frame data |
| 159 | trackedDataById[frameId] = FrameData( |
| 160 | frameId, 0, |
| 161 | bbox.x / fw, |
| 162 | bbox.y / fh, |
| 163 | (bbox.x + bbox.width) / fw, |
| 164 | (bbox.y + bbox.height) / fh |
| 165 | ); |
| 166 | |
| 167 | return true; |
| 168 | } |
| 169 | |
| 170 | // Update the object tracker according to frame |
| 171 | // returns true if KLT succeeded, false otherwise |
no test coverage detected