-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscamp5_main.cpp
260 lines (215 loc) · 6.8 KB
/
scamp5_main.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
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
#include "scamp5.hpp"
#include <math.h>
#include "IMG_TF.hpp"
#include "EDGE_IMAGE_GENERATION.hpp"
using namespace SCAMP5_PE;
volatile bool host_on;
int test_angle_scalar;
int img_gain_level = 1;
int shiftx = 0;
int shifty = 0;
int scale = 0;
int scalex = 0;
int scaley = 0;
int half_scale = 0;
int rot_angle;
uint32_t dreg_tf_time,dreg_translation_time,dreg_scaling_time,dreg_3skewrot_time,dreg_2skewrot_time;
uint32_t areg_tf_time,areg_translation_time,areg_scaling_time,areg_3skewrot_time,areg_2skewrot_time;
void scamp5_main(){
auto display_1 = vs_gui_add_display("3 skew rot",0,0,2);
auto display_2 = vs_gui_add_display("2 skew stepwise rot",0,2,2);
vs_gui_add_slider("scale: ",-64,64,0,&scale);
vs_gui_add_slider("scalex: ",-100,100,0,&scalex);
vs_gui_add_slider("scaley: ",-100,100,0,&scaley);
vs_gui_add_switch("half_scale", false,&half_scale);
vs_gui_add_slider("shiftx: ",-100,100,0,&shiftx);
vs_gui_add_slider("shifty: ",-100,100,0,&shifty);
vs_gui_add_slider("rot_angle: ",-90,90,0,&rot_angle);
vs_gui_add_slider("test_angle_scalar: ",0,1000,180,&test_angle_scalar);
auto areg_dreg_display_switch = vs_gui_add_switch("display areg/dreg", true);
auto slider_vxc = vs_gui_add_slider("vxc: ",0,4095,2900);
vs_on_gui_update(slider_vxc,[&](int32_t new_value){
vs_scamp5_configure_voltage(3,new_value);
});
vs_on_gui_update(VS_GUI_FRAME_RATE,[&](int32_t new_value){
uint32_t framerate = new_value;
if(framerate > 0){
vs_frame_trigger_set(1,framerate);
vs_enable_frame_trigger();
vs_post_text("frame trigger: 1/%d\n",(int)framerate);
}else{
vs_disable_frame_trigger();
vs_post_text("frame trigger disabled\n");
}
});
vs_on_gui_update(VS_GUI_FRAME_GAIN,[&](int32_t new_value){
img_gain_level = new_value;
});
vs_on_host_connect([&](){
vs_post_text("\nScamp5d Vision Algorithm Demo\nloop_counter: %d\n",vs_loop_counter_get());
scamp5_kernel::print_debug_info();
vs_led_on(VS_LED_2);
host_on = true;
});
vs_on_host_disconnect([&](){
vs_enable_frame_trigger();
vs_led_off(VS_LED_2);
host_on = false;
});
vs_frame_trigger_set(1,60);
vs_stopwatch timer;
while(1){
vs_wait_frame_trigger();
vs_process_message();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//GET IMAGE AND EDGE IMAGE
acquire_edge_image(img_gain_level, 50, 0, 30, 250);
scamp5_get_image(A,E,img_gain_level);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TRANSFORM A AND B
//SCALING
timer.reset();
IMGTF::SCALING::ANALOG::SCALE(A,abs(scale),scale > 0 ? 0 : 1);
IMGTF::SCALING::ANALOG::SCALE_X(A,abs(scalex),scalex > 0 ? 0 : 1);
IMGTF::SCALING::ANALOG::SCALE_Y(A,abs(scaley),scaley > 0 ? 0 : 1);
if(half_scale)
{
IMGTF::SCALING::ANALOG::HALF_SCALE(A);
}
areg_scaling_time = timer.get_usec();
//SHIFTING
timer.reset();
scamp5_shift(A,shiftx,shifty);
areg_translation_time = timer.get_usec();
//ROTATION 2 SKEWS
scamp5_kernel_begin();
mov(B,A);
scamp5_kernel_end();
int k = (int)(-rot_angle*test_angle_scalar*0.01);
timer.reset();
IMGTF::ROTATION::ANALOG::ROT_2SKEWS(B,k);
areg_2skewrot_time = timer.get_usec();
//ROTATION 3 SKEWS
timer.reset();
IMGTF::ROTATION::ANALOG::ROT_3SKEWS(A,M_PI*rot_angle/180.0);
areg_3skewrot_time = timer.get_usec();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TRANSFORM R5 AND R6
//SCALING
timer.reset();
if(abs(scale) != 0)
{
IMGTF::SCALING::DIGITAL::SCALE(R5,abs(scale),scale > 0 ? 0 : 1);
}
if(abs(scalex) != 0)
{
IMGTF::SCALING::DIGITAL::SCALE_X(R5,abs(scalex),scalex > 0 ? 0 : 1);
}
if(abs(scaley) != 0)
{
IMGTF::SCALING::DIGITAL::SCALE_Y(R5,abs(scaley),scaley > 0 ? 0 : 1);
}
if(half_scale)
{
IMGTF::SCALING::DIGITAL::HALF_SCALE(R5);
}
dreg_scaling_time = timer.get_usec();
//SHIFTING
timer.reset();
if(abs(shiftx) > 0)
{
scamp5_dynamic_kernel_begin();
CLR(R1,R2,R3,R4);
if(shiftx > 0)
{
SET(R2);
}
else
{
SET(R4);
}
scamp5_dynamic_kernel_end();
for(int x = 0 ; x < abs(shiftx) ; x++)
{
scamp5_kernel_begin();
DNEWS0(R11,R5);
MOV(R5,R11);
scamp5_kernel_end();
}
}
if(abs(shifty) > 0)
{
scamp5_dynamic_kernel_begin();
CLR(R1,R2,R3,R4);
if(shifty > 0)
{
SET(R3);
}
else
{
SET(R1);
}
scamp5_dynamic_kernel_end();
for(int y = 0 ; y < abs(shifty) ; y++)
{
scamp5_kernel_begin();
DNEWS0(R11,R5);
MOV(R5,R11);
scamp5_kernel_end();
}
}
dreg_translation_time = timer.get_usec();
//ROTATION 3 SKEWS
scamp5_kernel_begin();
MOV(R6,R5);
scamp5_kernel_end();
k = (int)(-rot_angle*test_angle_scalar*0.01);
timer.reset();
IMGTF::ROTATION::DIGITAL::ROT_2SKEWS(R6,k);
dreg_2skewrot_time = timer.get_usec();
scamp5_kernel_begin();
MOV(R11,R5);
scamp5_kernel_end();
//ROTATION 3 SKEWS
timer.reset();
IMGTF::ROTATION::DIGITAL::ROT_3SKEWS(R11,M_PI*rot_angle/180.0);
dreg_3skewrot_time = timer.get_usec();
scamp5_kernel_begin();
MOV(R5,R11);
scamp5_kernel_end();
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//OUTPUT
//PRINT TIMINGS
uint32_t temp_areg_tf_time = areg_scaling_time+areg_translation_time+areg_2skewrot_time+areg_3skewrot_time;
uint32_t temp_dreg_tf_time = dreg_scaling_time+dreg_translation_time+dreg_2skewrot_time+dreg_3skewrot_time;
if(temp_areg_tf_time != areg_tf_time || temp_dreg_tf_time != dreg_tf_time)
{
areg_tf_time = temp_areg_tf_time;
dreg_tf_time = temp_dreg_tf_time;
vs_post_text("AREG time(us):%d scale:%d 2skewrot:%d 3skewrot:%d trans:%d \n",areg_tf_time,areg_scaling_time,areg_2skewrot_time,areg_3skewrot_time,areg_translation_time);
vs_post_text("DREG time(us):%d scale:%d 2skewrot:%d 3skewrot:%d trans:%d \n",dreg_tf_time,dreg_scaling_time,dreg_2skewrot_time,dreg_3skewrot_time,dreg_translation_time);
}
//OUTPUT DISPLAYS
if(vs_gui_read_slider(areg_dreg_display_switch) == 1)
{
scamp5_output_image(R5,display_1);
scamp5_output_image(R6,display_2);
}
else
{
scamp5_output_image(A,display_1);
scamp5_output_image(B,display_2);
}
if(vs_loop_counter_get()%25==0){
vs_led_toggle(VS_LED_1);
}
vs_loop_counter_inc();
}
}
int main(){
vs_init();
vs_post_bind_io_agent(vs_usb);
scamp5_bind_io_agent(vs_usb);
scamp5_main();
return 0;
}