Obtain sub-window from image, with replication-padding and extract features
| 340 | |
| 341 | // Obtain sub-window from image, with replication-padding and extract features |
| 342 | cv::Mat KCFTracker::getFeatures(const cv::Mat & image, bool inithann, float scale_adjust) |
| 343 | { |
| 344 | cv::Rect extracted_roi; |
| 345 | |
| 346 | float cx = _roi.x + _roi.width / 2; |
| 347 | float cy = _roi.y + _roi.height / 2; |
| 348 | |
| 349 | if (inithann) { |
| 350 | int padded_w = _roi.width * padding; |
| 351 | int padded_h = _roi.height * padding; |
| 352 | |
| 353 | if (template_size > 1) { // Fit largest dimension to the given template size |
| 354 | if (padded_w >= padded_h) //fit to width |
| 355 | _scale = padded_w / (float) template_size; |
| 356 | else |
| 357 | _scale = padded_h / (float) template_size; |
| 358 | |
| 359 | _tmpl_sz.width = padded_w / _scale; |
| 360 | _tmpl_sz.height = padded_h / _scale; |
| 361 | } |
| 362 | else { //No template size given, use ROI size |
| 363 | _tmpl_sz.width = padded_w; |
| 364 | _tmpl_sz.height = padded_h; |
| 365 | _scale = 1; |
| 366 | // original code from paper: |
| 367 | /*if (sqrt(padded_w * padded_h) >= 100) { //Normal size |
| 368 | _tmpl_sz.width = padded_w; |
| 369 | _tmpl_sz.height = padded_h; |
| 370 | _scale = 1; |
| 371 | } |
| 372 | else { //ROI is too big, track at half size |
| 373 | _tmpl_sz.width = padded_w / 2; |
| 374 | _tmpl_sz.height = padded_h / 2; |
| 375 | _scale = 2; |
| 376 | }*/ |
| 377 | } |
| 378 | |
| 379 | if (_hogfeatures) { |
| 380 | // Round to cell size and also make it even |
| 381 | _tmpl_sz.width = ( ( (int)(_tmpl_sz.width / (2 * cell_size)) ) * 2 * cell_size ) + cell_size*2; |
| 382 | _tmpl_sz.height = ( ( (int)(_tmpl_sz.height / (2 * cell_size)) ) * 2 * cell_size ) + cell_size*2; |
| 383 | } |
| 384 | else { //Make number of pixels even (helps with some logic involving half-dimensions) |
| 385 | _tmpl_sz.width = (_tmpl_sz.width / 2) * 2; |
| 386 | _tmpl_sz.height = (_tmpl_sz.height / 2) * 2; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | extracted_roi.width = scale_adjust * _scale * _tmpl_sz.width; |
| 391 | extracted_roi.height = scale_adjust * _scale * _tmpl_sz.height; |
| 392 | |
| 393 | // center roi with new size |
| 394 | extracted_roi.x = cx - extracted_roi.width / 2; |
| 395 | extracted_roi.y = cy - extracted_roi.height / 2; |
| 396 | |
| 397 | cv::Mat FeaturesMap; |
| 398 | cv::Mat z = RectTools::subwindow(image, extracted_roi, cv::BORDER_REPLICATE); |
| 399 |
nothing calls this directly
no test coverage detected