274 int const w = this->sat->width();
275 int const row1 = (x - fs - 1) + w * (y - fs - 1);
276 int const row2 = row1 + w * fs;
277 int const row3 = row2 + w;
278 int const row4 = row3 + w * fs;
285 ret += v3 + v0 - v2 - v1;
287 v0 = this->sat->at(row1 + fs + 1);
288 v1 = this->sat->at(row1 + fs + fs + 1);
289 v2 = this->sat->at(row2 + fs + 1);
290 v3 = this->sat->at(row2 + fs + fs + 1);
291 ret -= v3 + v0 - v2 - v1;
293 v0 = this->sat->at(row3);
294 v1 = this->sat->at(row3 + fs);
295 v2 = this->sat->at(row4);
296 v3 = this->sat->at(row4 + fs);
297 ret -= v3 + v0 - v2 - v1;
299 v0 = this->sat->at(row3 + fs + 1);
300 v1 = this->sat->at(row3 + fs + fs + 1);
301 v2 = this->sat->at(row4 + fs + 1);
302 v3 = this->sat->at(row4 + fs + fs + 1);
303 ret += v3 + v0 - v2 - v1;
399 int const sample =
static_cast<int>(kp->
sample);
400 int const w = this->octaves[kp->
octave].imgs[sample]->width();
402 int off =
static_cast<int>(kp->
x) +
static_cast<int>(kp->
y) * w;
404 s0 = this->octaves[kp->
octave].imgs[sample - 1]->get_data_pointer() + off;
405 s1 = this->octaves[kp->
octave].imgs[sample]->get_data_pointer() + off;
406 s2 = this->octaves[kp->
octave].imgs[sample + 1]->get_data_pointer() + off;
410 { s0[-1-w], s0[-w], s0[1-w], s0[-1], s0[0], s0[1], s0[w-1], s0[w], s0[1+w] },
411 { s1[-1-w], s1[-w], s1[1-w], s1[-1], s1[0], s1[1], s1[w-1], s1[w], s1[1+w] },
412 { s2[-1-w], s2[-w], s2[1-w], s2[-1], s2[0], s2[1], s2[w-1], s2[w], s2[1+w] }
418 vec_b[0] = -(N9[1][5] - N9[1][3]) * 0.5;
419 vec_b[1] = -(N9[1][7] - N9[1][1]) * 0.5;
420 vec_b[2] = -(N9[2][4] - N9[0][4]) * 0.5;
422 mat_a[0] = N9[1][3] - 2.0 * N9[1][4] + N9[1][5];
423 mat_a[1] = (N9[1][8] - N9[1][6] - N9[1][2] + N9[1][0]) * 0.25;
424 mat_a[2] = (N9[2][5] - N9[2][3] - N9[0][5] + N9[0][3]) * 0.25;
426 mat_a[4] = N9[1][1] - 2.0 * N9[1][4] + N9[1][7];
427 mat_a[5] = (N9[2][7] - N9[2][1] - N9[0][7] + N9[0][1]) * 0.25;
430 mat_a[8] = N9[0][4] - 2.0 * N9[1][4] + N9[2][4];
450 float dog_value = N9[1][4] - 0.5 * vec_b.
dot(vec_x);
459 kp->
x = (kp->
x + vec_x[0]) * sampling;
460 kp->
y = (kp->
y + vec_x[1]) * sampling;
464 if (kp->
x < 0.0f || kp->
x + 1.0f > this->sat->width()
465 || kp->
y < 0.0f || kp->
y + 1.0f > this->sat->height())
518 int const descr_x =
static_cast<int>(descr->
x + 0.5f);
519 int const descr_y =
static_cast<int>(descr->
y + 0.5f);
520 int const descr_scale =
static_cast<int>(descr->
scale);
521 int const width = this->sat->width();
522 int const height = this->sat->height();
528 float const gaussian[109] = { 0.0658748, 0.0982736, 0.12493, 0.135335,
529 0.12493, 0.0982736, 0.0658748, 0.0773047, 0.135335, 0.201897, 0.256661,
530 0.278037, 0.256661, 0.201897, 0.135335, 0.0773047, 0.0658748, 0.135335,
531 0.236928, 0.353455, 0.449329, 0.486752, 0.449329, 0.353455, 0.236928,
532 0.135335, 0.0658748, 0.0982736, 0.201897, 0.353455, 0.527292, 0.67032,
533 0.726149, 0.67032, 0.527292, 0.353455, 0.201897, 0.0982736, 0.12493,
534 0.256661, 0.449329, 0.67032, 0.852144, 0.923116, 0.852144, 0.67032,
535 0.449329, 0.256661, 0.12493, 0.135335, 0.278037, 0.486752, 0.726149,
536 0.923116, 1, 0.923116, 0.726149, 0.486752, 0.278037, 0.135335, 0.12493,
537 0.256661, 0.449329, 0.67032, 0.852144, 0.923116, 0.852144, 0.67032,
538 0.449329, 0.256661, 0.12493, 0.0982736, 0.201897, 0.353455, 0.527292,
539 0.67032, 0.726149, 0.67032, 0.527292, 0.353455, 0.201897, 0.0982736,
540 0.0658748, 0.135335, 0.236928, 0.353455, 0.449329, 0.486752, 0.449329,
541 0.353455, 0.236928, 0.135335, 0.0658748, 0.0773047, 0.135335, 0.201897,
542 0.256661, 0.278037, 0.256661, 0.201897, 0.135335, 0.0773047, 0.0658748,
543 0.0982736, 0.12493, 0.135335, 0.12493, 0.0982736, 0.0658748 };
552 int const spacing = 8 * descr_scale + 1;
553 if (descr_x < spacing || descr_y < spacing
554 || descr_x + spacing >= width || descr_y + spacing >= height)
558#define NUM_SAMPLES 109
565 for (
int ry = -5, index = 0; ry <= 5; ++ry)
566 for (
int rx = -5; rx <= 5; ++rx)
568 if (rx * rx + ry * ry >= 36)
571 descr_y + ry * descr_scale, 2 * descr_scale,
572 dx + index, dy + index);
573 dx[index] *= gaussian[index];
574 dy[index] *= gaussian[index];
582 double const window_increment =
MATH_PI / 8.0;
583 double const window_halfsize =
MATH_PI / 6.0;
584 double best_dx = 0.0, best_dy = 0.0;
585 double best_length = 0.0f;
586 for (
double deg = -
MATH_PI; deg <
MATH_PI; deg += window_increment)
589 double const win_start = deg - window_halfsize;
590 double const win_end = deg + window_halfsize;
591 double sum_dx = 0.0f, sum_dy = 0.0f;
594 double const sample_deg = std::atan2(dy[i], dx[i]);
595 double const sample_deg_p = sample_deg + 2.0 *
MATH_PI;
596 double const sample_deg_m = sample_deg - 2.0 *
MATH_PI;
597 if ((sample_deg > win_start && sample_deg < win_end)
598 || (sample_deg_p > win_start && sample_deg_p < win_end)
599 || (sample_deg_m > win_start && sample_deg_m < win_end))
607 double const length = sum_dx * sum_dx + sum_dy * sum_dy;
608 if (length > best_length)
612 best_length = length;
667 int const descr_scale =
static_cast<int>(descr->
scale);
668 int const width = this->sat->width();
669 int const height = this->sat->height();
677 float const spacing =
static_cast<float>(15 * descr_scale + 1);
678 if (descr->
x < spacing || descr->
y < spacing
679 || descr->
x + spacing >= width || descr->
y + spacing > height)
682 float sin_ori = 0.0f, cos_ori = 1.0f;
691 float* descr_iter = &descr->
data[0];
692 for (
int y = -10; y < 10; ++y)
694 for (
int x = -10; x < 10; ++x)
698 + (cos_ori * (x + 0.5f) - sin_ori * (y + 0.5f))
701 + (sin_ori * (x + 0.5f) + cos_ori * (y + 0.5f))
706 this->
filter_dx_dy(rot_x, rot_y, descr_scale, &dx, &dy);
707 float ori_dx = cos_ori * dx + sin_ori * dy;
708 float ori_dy = -sin_ori * dx + cos_ori * dy;
711 float weight = std::exp(-
static_cast<float>(x * x + y * y)
713 *(descr_iter++) += weight * ori_dx;
714 *(descr_iter++) += weight * ori_dy;
715 *(descr_iter++) += weight * std::abs(ori_dx);
716 *(descr_iter++) += weight * std::abs(ori_dy);
718 if ((x + 10) % 5 != 4)
721 if ((y + 10) % 5 != 4)
729 descr->
data /= std::sqrt(norm);