-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview_class.cpp
More file actions
273 lines (257 loc) · 9.96 KB
/
view_class.cpp
File metadata and controls
273 lines (257 loc) · 9.96 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#include "view_class.h"
#define DEBUG_WRITE_BUFFER_TO_FILE false
View_class::View_class(std::string theName,std::string theDescription)
{
Name = theName;
Description = theDescription;
Flag_Advanced = false;
istheLeftOne = false;
istheRightOne = false;
isDoubled = false;
interpolation = CV_INTER_LINEAR;
threshold = 0;
gain = 0;
type_of_process = BASE_7BIT;
mat_processing = new cv::Mat;
mat_processing->create(104,104,CV_8U);
mat_temp = new cv::Mat;
mat_temp->create(104,104,CV_8U);
mat_processing_double = new cv::Mat;
mat_processing_double->create(208,208,CV_8U);
}
/*
View_class::~View_class(){
//cvReleaseMat(&mat_processing);
}
*/
//return a pointer to mat_processing
cv::Mat * View_class::pointer_to_mat_processing(){
return mat_processing;
}
cv::Mat* View_class::process_selection(){
switch (type_of_process){
//pair and odd frames
case BASE_7BIT:
process_frame_enervis_8bit_BASE_7BIT();
break;
case NOTZERO_8BIT:
process_frame_enervis_8bit_NOTZERO_8BIT();
break;
case OVERTHRESHOLD_8BIT:
process_frame_enervis_8bit_OVERTHRESHOLD_8BIT();
break;
//pair frames:
case BASE_7BIT_PF:
process_frame_enervis_8bit_BASE_7BIT_PF();
break;
case NOTZERO_8BIT_PF:
process_frame_enervis_8bit_NOTZERO_8BIT_PF();
break;
case OVERTHRESHOLD_8BIT_PF:
process_frame_enervis_8bit_OVERTHRESHOLD_8BIT_PF();
break;
case THRESHOLD_TO_ZERO_PF:
process_frame_enervis_8bit_THRESHOLD_TO_ZERO_PF();
break;
case THRESHOLD_TO_ZERO_EQ_PF:
process_frame_enervis_8bit_THRESHOLD_TO_ZERO_EQ_PF();
break;
//odd frames:
case BASE_7BIT_OF:
process_frame_enervis_8bit_BASE_7BIT_OF();
break;
case NOTZERO_8BIT_OF:
process_frame_enervis_8bit_NOTZERO_8BIT_OF();
break;
case OVERTHRESHOLD_8BIT_OF:
process_frame_enervis_8bit_OVERTHRESHOLD_8BIT_OF();
break;
case THRESHOLD_TO_ZERO_OF:
process_frame_enervis_8bit_THRESHOLD_TO_ZERO_OF();
break;
case THRESHOLD_TO_ZERO_EQ_OF:
process_frame_enervis_8bit_THRESHOLD_TO_ZERO_EQ_OF();
break;
default:
process_frame_enervis_8bit_BASE_7BIT();
break;
}
if (isDoubled == false){
return mat_processing;
} else {
cv::resize(*mat_processing,*mat_processing_double,cv::Size(208,208),interpolation);
return mat_processing_double;
}
}
//////////////////////////////////////////////////////////////////////////
//pair and odd frames:
void View_class::process_frame_enervis_8bit_NOTZERO_8BIT(){
cv::threshold(*gCV_MAT_FRAME_VIEW,*mat_processing,0,255,CV_THRESH_BINARY);
}
void View_class::process_frame_enervis_8bit_BASE_7BIT(){
mat_processing = gCV_MAT_FRAME_VIEW;
}
void View_class::process_frame_enervis_8bit_OVERTHRESHOLD_8BIT(){
cv::threshold(*gCV_MAT_FRAME_VIEW,*mat_processing,threshold,255,CV_THRESH_BINARY);
}
///////////////////////////////////////////////////////////////////////////////////
//pair frames:
void View_class::process_frame_enervis_8bit_BASE_7BIT_PF(){
if (gCV_ACQ_OF_ENERVIS->last_frame_type == PAIR_FRAME) {
mat_processing = gCV_MAT_FRAME_VIEW;
//make a copy of gCV_FRAME_VIEW for the next call
*mat_temp = gCV_MAT_FRAME_VIEW->clone();
} else {
mat_processing = mat_temp;
}
}
void View_class::process_frame_enervis_8bit_NOTZERO_8BIT_PF(){
if (gCV_ACQ_OF_ENERVIS->last_frame_type == PAIR_FRAME) {
cv::threshold(*gCV_MAT_FRAME_VIEW,*mat_processing,0,255,CV_THRESH_BINARY);
//make a copy of mat_processing for the next call
*mat_temp = mat_processing->clone();
} else {
mat_processing = mat_temp;
}
}
void View_class::process_frame_enervis_8bit_OVERTHRESHOLD_8BIT_PF(){
if (gCV_ACQ_OF_ENERVIS->last_frame_type == PAIR_FRAME) {
cv::threshold(*gCV_MAT_FRAME_VIEW,*mat_processing,threshold,255,CV_THRESH_BINARY);
//make a copy of mat_processing for the next call
*mat_temp = mat_processing->clone();
}else {
mat_processing = mat_temp;
}
}
void View_class::process_frame_enervis_8bit_THRESHOLD_TO_ZERO_PF(){
if (gCV_ACQ_OF_ENERVIS->last_frame_type == PAIR_FRAME) {
cv::threshold(*gCV_MAT_FRAME_VIEW,*mat_processing,threshold,255,CV_THRESH_TOZERO);
//make a copy of mat_processing for the next call
*mat_temp = mat_processing->clone();
}else {
mat_processing = mat_temp;
}
}
void View_class::process_frame_enervis_8bit_THRESHOLD_TO_ZERO_EQ_PF(){
if (gCV_ACQ_OF_ENERVIS->last_frame_type == PAIR_FRAME) {
cv::threshold(*gCV_MAT_FRAME_VIEW,*mat_temp,threshold,255,CV_THRESH_TOZERO);
cv::equalizeHist(*mat_temp,*mat_processing);
//make a copy of mat_processing for the next call
*mat_temp = mat_processing->clone();
}else {
mat_processing = mat_temp;
}
}
///////////////////////////////////////////////////////////////////////////////////
//odd frames:
void View_class::process_frame_enervis_8bit_BASE_7BIT_OF(){
if (gCV_ACQ_OF_ENERVIS->last_frame_type == ODD_FRAME) {
mat_processing = gCV_MAT_FRAME_VIEW;
//make a copy of gCV_FRAME_VIEW for the next call
*mat_temp = gCV_MAT_FRAME_VIEW->clone();
} else {
mat_processing = mat_temp;
}
}
void View_class::process_frame_enervis_8bit_NOTZERO_8BIT_OF(){
if (gCV_ACQ_OF_ENERVIS->last_frame_type == ODD_FRAME) {
cv::threshold(*gCV_MAT_FRAME_VIEW,*mat_processing,0,255,CV_THRESH_BINARY);
//make a copy of mat_processing for the next call
*mat_temp = mat_processing->clone();
} else {
mat_processing = mat_temp;
}
}
void View_class::process_frame_enervis_8bit_OVERTHRESHOLD_8BIT_OF(){
if (gCV_ACQ_OF_ENERVIS->last_frame_type == ODD_FRAME) {
cv::threshold(*gCV_MAT_FRAME_VIEW,*mat_processing,threshold,255,CV_THRESH_BINARY);
//make a copy of mat_processing for the next call
*mat_temp = mat_processing->clone();
}else {
mat_processing = mat_temp;
}
}
void View_class::process_frame_enervis_8bit_THRESHOLD_TO_ZERO_OF(){
if (gCV_ACQ_OF_ENERVIS->last_frame_type == ODD_FRAME) {
cv::threshold(*gCV_MAT_FRAME_VIEW,*mat_processing,threshold,255,CV_THRESH_TOZERO);
//make a copy of mat_processing for the next call
*mat_temp = mat_processing->clone();
}else {
mat_processing = mat_temp;
}
}
void View_class::process_frame_enervis_8bit_THRESHOLD_TO_ZERO_EQ_OF(){
if (gCV_ACQ_OF_ENERVIS->last_frame_type == ODD_FRAME) {
cv::threshold(*gCV_MAT_FRAME_VIEW,*mat_temp,threshold,255,CV_THRESH_TOZERO);
cv::equalizeHist(*mat_temp,*mat_processing);
//make a copy of mat_processing for the next call
*mat_temp = mat_processing->clone();
}else {
mat_processing = mat_temp;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
//// class View Initialization /////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
View_initialization::View_initialization(){
last_time_query = QTime::currentTime();
isAcquisitionActive = false;
last_frame_type = ODD_FRAME;
}
/** \brief process the data from enervis and save it in matrix CvMat that is globally defined
*
* To access the data in the opencv Mat structure gCV_
* It use the macro CV_MAT_ELEM_PTR macro discussed at page 36/40 of
* OpenCv Manual
*
*
*/
void View_initialization::process_frame_enervis(){
last_time_query = QTime::currentTime();
last_frame_type = gEnervis->GetFrameOn_XEMFPGA_NB();
int i,row,col;
for (i=0;i<1024;i++){
//data from first ram block
gEnervis->frame_processed_8bit[i*2]= (gEnervis->bufout_1[i*2] >> 1) & 0x7F;
gEnervis->frame_processed_8bit[i*2 + 1]= (gEnervis->bufout_1[i*2 + 1] >> 1) & 0x7F;
//data from second ram block
gEnervis->frame_processed_8bit[i*2 + 2048]= (gEnervis->bufout_2[i*2] >> 1) & 0x7F;
gEnervis->frame_processed_8bit[i*2 + 2049]= (gEnervis->bufout_2[i*2 + 1] >> 1) & 0x7F;
//data from third ram block
gEnervis->frame_processed_8bit[i*2 + 4096]= (gEnervis->bufout_3[i*2] >> 1) & 0x7F;
gEnervis->frame_processed_8bit[i*2 + 4097]= (gEnervis->bufout_3[i*2 + 1] >> 1) & 0x7F;
//data from fourth ram block
gEnervis->frame_processed_8bit[i*2 + 6144]= (gEnervis->bufout_4[i*2] >> 1) & 0x7F;
gEnervis->frame_processed_8bit[i*2 + 6145]= (gEnervis->bufout_4[i*2 + 1] >> 1) & 0x7F;
//data from fifth ram block
gEnervis->frame_processed_8bit[i*2 + 8192]= (gEnervis->bufout_5[i*2] >> 1) & 0x7F;
gEnervis->frame_processed_8bit[i*2 + 8193]= (gEnervis->bufout_5[i*2 + 1] >> 1) & 0x7F;
//data from sixth ram block
if (i<288){
gEnervis->frame_processed_8bit[i*2 + 10240]= (gEnervis->bufout_6[i*2] >> 1) & 0x7F;
gEnervis->frame_processed_8bit[i*2 + 10241]= (gEnervis->bufout_6[i*2 + 1] >> 1) & 0x7F;
}
}
for (row=0;row< gCV_MAT_FRAME_VIEW->rows;row++){
for (col=0; col<gCV_MAT_FRAME_VIEW->cols; col++){
//*((unsigned char*)CV_MAT_ELEM_PTR( *gCV_MAT_FRAME_VIEW,row,col))= gEnervis->frame_processed_8bit[row*104+col];
gCV_MAT_FRAME_VIEW->at<unsigned char>(row,col)= gEnervis->frame_processed_8bit[row*104+col];
//unsigned char c = frame[row*104+col];
}
}
if (DEBUG_WRITE_BUFFER_TO_FILE) {
//save buffer in a binary file
const char *buffer_file_name;
buffer_file_name = "frame.dat";
std::ofstream bin_buffer(buffer_file_name,std::ios::out|std::ios::binary);
bin_buffer.write(reinterpret_cast<const char*>(gEnervis->frame_processed_8bit),10816);
bin_buffer.close();
}
/*
unsigned char a;
for (row=0;row< gCV_MAT_FRAME_VIEW->rows;row++){
for (col=0; col<gCV_MAT_FRAME_VIEW->cols; col++){
a = *((unsigned char*)CV_MAT_ELEM_PTR( *gCV_MAT_FRAME_VIEW,row,col));
}
}*/
}