-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.cpp
59 lines (48 loc) · 1.5 KB
/
util.cpp
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
#include "stdafx.h"
#include "util.h"
#include "common.h"
namespace fs = std::filesystem;
using namespace cv;
/* Histogram display function - display a histogram using bars (simlilar to L3 / PI)
Input:
name - destination (output) window name
hist - pointer to the vector containing the histogram values
hist_cols - no. of bins (elements) in the histogram = histogram image width
hist_height - height of the histogram image
Call example:
showHistogram ("MyHist", hist_dir, 255, 200);
*/
void showHistogram(const std::string& name, const int* hist, const int hist_cols, const int hist_height)
{
Mat imgHist(hist_height, hist_cols, CV_8UC3, CV_RGB(255, 255, 255)); // constructs a white image
//computes histogram maximum
int max_hist = 0;
for (int i = 0; i < hist_cols; i++)
if (hist[i] > max_hist)
max_hist = hist[i];
double scale = 1.0;
scale = (double)hist_height / max_hist;
int baseline = hist_height - 1;
for (int x = 0; x < hist_cols; x++) {
Point p1 = Point(x, baseline);
Point p2 = Point(x, baseline - cvRound(hist[x] * scale));
line(imgHist, p1, p2, CV_RGB(255, 0, 255)); // histogram bins colored in magenta
}
imshow(name, imgHist);
}
std::vector<std::string> getFilesInDir(const std::string& dirName)
{
std::vector<std::string> files;
for (const auto& entry : fs::directory_iterator(dirName)) {
files.push_back(entry.path().string());
}
return files;
}
double degToRad(double degree)
{
return (degree * (PI / 180.0));
}
double radToDeg(double radian)
{
return (radian / (PI / 180.0));
}