Visual Vibration Tracking 0.2
Загрузка...
Поиск...
Не найдено
helper.cpp
1#include "VVT-V2/helper.h"
2
3std::string HelperFunctions::GenerateCsvFilename(std::string additional_text)
4{
5 // Имя файла, в который будет производиться запись
6 std::string csv_file_name;
7 // Начало названия выходного файла
8 csv_file_name = "C:/Users/seeyo/source/repos/Visual-Vibration-Tracking-V2/output/metadata/output_";
9 // Добавляем дополнительный текст при желании
10 csv_file_name += additional_text;
11 // Время
12 auto time = std::time(nullptr);
13 // Записываем текущее время
14 std::stringstream date_n_time;
15 date_n_time << std::put_time(std::localtime(&time), "%F_%T");
16 // Переводим дату и время в строковый тип
17 std::string date_n_time_str = date_n_time.str();
18 // Меняем ":" на "-" для корректного имени файла
19 std::replace(date_n_time_str.begin(), date_n_time_str.end(), ':', '-');
20 // Добавляем дату и время к имени файла + расширение файла
21 csv_file_name += date_n_time_str + ".csv";
22
23 std::cout << csv_file_name << std::endl;
24
25 return csv_file_name;
26}
27
28cv::Scalar HelperFunctions::RatioToRgb(double ratio)
29{
30 //
31 int normalized = static_cast<int>(ratio * 256 * 4);
32
33 // find the region for this position
34 int region = normalized / 256;
35
36 // find the distance to the start of the closest region
37 int x = normalized % 256;
38
39 int r = 0, g = 0, b = 0;
40
41 switch (region)
42 {
43 case 0: r = 0; g = 0; b = 255; g += x; break; // синий:сине-зеленый
44 case 1: r = 0; g = 255; b = 255; b -= x; break; // сине-зеленый:зеленый
45 case 2: r = 0; g = 255; b = 0; r += x; break; // зеленый:желтый
46 case 3: r = 255; g = 255; b = 0; g -= x; break; // желтый:красный
47 }
48
49 return cv::Scalar(b, g, r);
50}
51
52void HelperFunctions::FindLocalMaxima(cv::Mat& input_array, cv::Mat& local_maxima, double threshold_value)
53{
54 cv::Mat dilated_input_image, thresholded_input_image, thresholded_input_8bit;
55 dilate(input_array, dilated_input_image, cv::Mat());
56 compare(input_array, dilated_input_image, local_maxima, cv::CMP_EQ);
57 threshold(input_array, thresholded_input_image, threshold_value, 255, cv::THRESH_BINARY);
58 thresholded_input_image.convertTo(thresholded_input_8bit, CV_8U);
59 bitwise_and(local_maxima, thresholded_input_8bit, local_maxima);
60}
61
std::string GenerateCsvFilename(std::string additional_text="")
Генерирует имя CSV файла для сохранения метаданных
Definition: helper.cpp:3
cv::Scalar RatioToRgb(double ratio)
Генерирует имя TXT файла для сохранени
Definition: helper.cpp:28
void FindLocalMaxima(cv::Mat &input_array, cv::Mat &local_maxima, double threshold_value)
Эта функция пригодится. Разберусь с ней чуть позже
Definition: helper.cpp:52