Visual Vibration Tracking 0.2
Загрузка...
Поиск...
Не найдено
eulerian_enlargement.cpp
1#include "MovEn/eulerian_enlargement.h"
2
3EulerEnlarger::EulerEnlarger() :
4 cutoff_low_{ 0.1 },
5 cutoff_high_{ 1.0 },
6 exaggeraiton_coefficient_{ 2.0 },
7 lambda_{ 0.0 }, // будем изменено в цикле
8 lambda_cutoff_{ 16.0 },
9 color_attenuation_coefficient_{ 0.0 },
10 delta_{ 0.0 },
11 alpha_{ 10.0 },
12 levels_amount_{ 3 }
13{
14 std::cout << "Euler Enlarger constructor" << std::endl;
15}
16
17EulerEnlarger::~EulerEnlarger()
18{
19 std::cout << "Euler Enlarger destructor" << std::endl;
20}
21
22void EulerEnlarger::LaplaceEnlarge(Mat& motion_pyramid_level, int current_level)
23{
24 double current_alpha = (lambda_ / delta_ / 8.0 - 1.0) * exaggeraiton_coefficient_;
25
26 if (current_level == levels_amount_ || current_level == 0)
27 {
28 // Для первого и последнего уровней пирамиды устанавливаем усиление на 0
29 motion_pyramid_level = motion_pyramid_level * 0;
30 }
31 else
32 {
33 // Выполняем для остальных уровней
34 motion_pyramid_level = motion_pyramid_level * std::min(current_alpha, alpha_);
35 }
36}
37
38void EulerEnlarger::Attenuate(Mat& motion_frame)
39{
40 // "Приглушение" будет происходить только для цветных кадров
41 if (motion_frame.channels() > 2)
42 {
43 //std::vector<Mat> planes;
44 Mat planes[3];
45 split(motion_frame, planes);
46 // Применяем только к 2-му и 3-му каналу, тк первый отвечает за ч-б составляющую картинки в нашем формате
47 planes[1] = planes[1] * color_attenuation_coefficient_;
48 planes[2] = planes[2] * color_attenuation_coefficient_;
49 merge(planes, 3, motion_frame);
50 }
51}
52
53void EulerEnlarger::BuildLaplacePyramid(const Mat& input_frame, std::vector<Mat>& input_pyramid, const int levels)
54{
55 input_pyramid.clear();
56 std::vector<Mat> pyramid;
57 Mat current_level = input_frame.clone();
58
59 for (int level = 0; level < levels; level++)
60 {
61 Mat down, up;
62 // Блюрим кадр и уменьшаем его размер по ширине и высоте в два раза
63 pyrDown(current_level, down);
64 // Увеличиваем изображение по ширине и высоте в два раза, затем блюрим его
65 pyrUp(down, up, current_level.size());
66 Mat laplace = current_level - up;
67 pyramid.push_back(laplace);
68 current_level = down;
69 }
70 pyramid.push_back(current_level);
71 input_pyramid = pyramid;
72}
73
74void EulerEnlarger::IirFilter(Mat& input_pyramid_level, Mat& motion_pyramid_level, Mat& low_pass_high_level, Mat& low_pass_low_level, double cutoff_low, double cutoff_high)
75{
76 low_pass_high_level = (1 - cutoff_high) * low_pass_high_level + cutoff_high * input_pyramid_level;
77 low_pass_low_level = (1 - cutoff_low) * low_pass_low_level + cutoff_low * input_pyramid_level;
78
79 motion_pyramid_level = low_pass_high_level - low_pass_low_level;
80}
81
82void EulerEnlarger::BuildFromLaplacePyramid(std::vector<Mat>& motion_pyramid, Mat& motion_frame, const int levels)
83{
84 // Сначала рассматриваем последний элемент вектора - он же первый уровень пирамиды
85 Mat current_level = motion_pyramid[levels];
86
87 for (int level = levels - 1; level >= 0; --level)
88 {
89 Mat up;
90 pyrUp(current_level, up, motion_pyramid[level].size());
91 // Добавляем только что заапсемпленный уровень к "текущему" (по сути предыдущему) уровню пирамиды
92 current_level = up + motion_pyramid[level];
93 }
94 motion_frame = current_level.clone();
95}
double lambda_
Показательная длина волны
void IirFilter(Mat &input_pyramid_level, Mat &motion_pyramid_level, Mat &low_pass_high_level, Mat &low_pass_low_level, double cutoff_low, double cutoff_high)
Фильтр для отсекания низких и высоких "пространственных" частот ("фильтр с бесконечной импульсной хар...
void BuildFromLaplacePyramid(std::vector< Mat > &motion_pyramid, Mat &motion_frame, int levels)
Извлекаем выходное изображение из пирамиды Лапласа
double exaggeraiton_coefficient_
Коэффициент увеличения. Чем выше - тем больше шума, тем сильнее увеличиваются небольшие движения.
int levels_amount_
Количество уровней (слоев) пирамиды
void LaplaceEnlarge(Mat &motion_pyramid_level, int current_level)
Осуществляет увеличение движения на конкретном уровне пирамиды
double delta_
Коэффициент, использующийся при увеличении
void Attenuate(Mat &motion_frame)
"Приглушает" усиленные цвета на кадре
void BuildLaplacePyramid(const Mat &input_frame, std::vector< Mat > &input_pyramid, const int levels)
Создает пирамиду изображений
double color_attenuation_coefficient_
Коэффициент приглушеняи цвета