-
Notifications
You must be signed in to change notification settings - Fork 4
/
cvx_util.hpp
70 lines (51 loc) · 1.77 KB
/
cvx_util.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// cvx_util.hpp
// RGB_RF
//
// Created by jimmy on 2016-05-27.
// Copyright © 2016 jimmy. All rights reserved.
//
#ifndef cvx_util_cpp
#define cvx_util_cpp
#include <stdio.h>
#include <vector>
#include <string>
using std::vector;
using std::string;
class CvxUtil
{
public:
// generate random number in the range of [min_val, max_val]
static vector<double>
generateRandomNumbers(double min_val, double max_val, int rnd_num);
static inline bool isInside(const int width, const int height, const int x, const int y)
{
return x >= 0 && y >= 0 && x < width && y < height;
}
static void splitFilename (const string& str, string &path, string &file);
// folder: /Users/chenjLOCAL/Desktop/*.txt
static void readFilenames(const char *folder, vector<string> & files);
// quantilization method
// interval: resolution, the width of bin
// nBin: tobal number of bins
static unsigned value_to_bin_number(double v_min, double interval, double value, const unsigned nBin);
// bin: bin index
static double bin_number_to_value(double v_min, double interval, int bin);
template <typename T>
static vector<size_t> sortIndices(const vector<T> &v) {
// initialize original index locations
vector<size_t> idx(v.size());
for (size_t i = 0; i != idx.size(); ++i){
idx[i] = i;
}
// sort indexes based on comparing values in v
sort(idx.begin(), idx.end(), [&v](size_t i1, size_t i2) {return v[i1] < v[i2];});
return idx;
}
// video input/ output
static double millisecondsFromIndex(const int index, const double fps)
{
return index * 1000.0/fps;
}
};
#endif /* cvxUtil_cpp */