forked from pjarosik/pwi_cpp_example
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgui.h
82 lines (71 loc) · 2.2 KB
/
gui.h
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
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef CPP_EXAMPLE_DISPLAY2D_H
#define CPP_EXAMPLE_DISPLAY2D_H
#include "imaging/DataType.h"
class Display2D {
public:
Display2D() = default;
void update(void *inputPtr) {
if(isClosed) {
windowClosed.notify_all();
return;
}
cv::Mat mat(nrows, ncols, inputDataTypeCv, inputPtr);
if(inputDataTypeCv == CV_32FC2) {
cv::Mat real(nrows, ncols, CV_32F);
cv::Mat imag(nrows, ncols, CV_32F);
cv::Mat abs(nrows, ncols, CV_32F);
cv::Mat logAbs(nrows, ncols, CV_32F);
cv::Mat logAbsColor;
Mat out[] = {real, imag};
int from_to[] = {0,0 , 1,1};
cv::mixChannels(&mat, 1, out, 2, from_to, 2);
cv::Mat mag = real.mul(real) + imag.mul(imag);
::cv::imshow("Display2D", real);
}
else {
::cv::transpose(mat, mat);
::cv::imshow("Display2D", mat);
}
// Refresh the window and check if user pressed 'q'.
int key = waitKey(1);
}
void exit() {
windowClosed.notify_all();
}
void close() {
isClosed = true;
}
void waitUntilClosed(std::unique_lock<std::mutex> &lock) {
windowClosed.wait(lock);
}
void setNrows(unsigned int nrows) {
Display2D::nrows = nrows;
}
void setNcols(unsigned int ncols) {
Display2D::ncols = ncols;
}
void setInputDataType(imaging::DataType inputDataType) {
switch(inputDataType) {
case imaging::DataType::INT16:
inputDataTypeCv = CV_16S;
break;
case imaging::DataType::UINT8:
inputDataTypeCv = CV_8U;
break;
case imaging::DataType::FLOAT32:
inputDataTypeCv = CV_32F;
break;
case imaging::DataType::COMPLEX64:
inputDataTypeCv = CV_32FC2;
break;
default:
throw std::runtime_error("Invalid input data type.");
}
}
private:
unsigned int nrows, ncols;
bool isClosed{false};
size_t inputDataTypeCv;
std::condition_variable windowClosed;
};
#endif //CPP_EXAMPLE_DISPLAY2D_H