Skip to content

Commit d205e4e

Browse files
committed
Working code in co-simulation and synthesis
1 parent 2e3ed49 commit d205e4e

File tree

2 files changed

+92
-92
lines changed

2 files changed

+92
-92
lines changed

HLS/IpsFilterHLS/src/ips_filter.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ void Filter::filter()
1818
result = result * (0.1111);
1919

2020
#ifndef __SYNTHESIS__
21-
cout << "Step: " << 1 << " Window Input = " << input_window_0.read() << endl;
22-
cout << "Step: " << 2 << " Window Input = " << input_window_1.read() << endl;
23-
cout << "Step: " << 3 << " Window Input = " << input_window_2.read() << endl;
24-
cout << "Step: " << 4 << " Window Input = " << input_window_3.read() << endl;
25-
cout << "Step: " << 5 << " Window Input = " << input_window_4.read() << endl;
26-
cout << "Step: " << 6 << " Window Input = " << input_window_5.read() << endl;
27-
cout << "Step: " << 7 << " Window Input = " << input_window_6.read() << endl;
28-
cout << "Step: " << 8 << " Window Input = " << input_window_7.read() << endl;
29-
cout << "Step: " << 9 << " Window Input = " << input_window_8.read() << endl;
30-
cout << "Result: " << (int) result << endl;
21+
// cout << "Step: " << 1 << " Window Input = " << input_window_0.read() << endl;
22+
// cout << "Step: " << 2 << " Window Input = " << input_window_1.read() << endl;
23+
// cout << "Step: " << 3 << " Window Input = " << input_window_2.read() << endl;
24+
// cout << "Step: " << 4 << " Window Input = " << input_window_3.read() << endl;
25+
// cout << "Step: " << 5 << " Window Input = " << input_window_4.read() << endl;
26+
// cout << "Step: " << 6 << " Window Input = " << input_window_5.read() << endl;
27+
// cout << "Step: " << 7 << " Window Input = " << input_window_6.read() << endl;
28+
// cout << "Step: " << 8 << " Window Input = " << input_window_7.read() << endl;
29+
// cout << "Step: " << 9 << " Window Input = " << input_window_8.read() << endl;
30+
// cout << "Result: " << (int) result << endl;
3131
#endif //__SYNTHESIS__
3232

3333
// // Perform the convolution

HLS/IpsFilterHLS/src/tb_module.cpp

Lines changed: 82 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#define IPS_FILTER_KERNEL_SIZE 3
1515
#define DELAY_TIME (IPS_FILTER_KERNEL_SIZE * IPS_FILTER_KERNEL_SIZE * 1) + 4 + 2 + 1
16-
#define IPS_IMG_PATH_TB "../../../inputs/car_noisy_image.png"
16+
#define IPS_IMG_PATH_TB "../../../inputs/car_noisy_image.jpg"
1717

1818
SC_MODULE (testbench) {
1919
sc_out<sc_uint<8> > img_window[IPS_FILTER_KERNEL_SIZE*IPS_FILTER_KERNEL_SIZE];
@@ -125,8 +125,8 @@ SC_MODULE (testbench) {
125125
std::cout << " channels = " << image.channels() << std::endl;
126126
}
127127

128-
image.rows = 100;
129-
image.cols = 100;
128+
// image.rows = 100;
129+
// image.cols = 100;
130130
sc_uint<8> local_window[IPS_FILTER_KERNEL_SIZE * IPS_FILTER_KERNEL_SIZE];
131131
sc_uint<8> result;
132132

@@ -140,7 +140,7 @@ SC_MODULE (testbench) {
140140
#endif // IPS_DEBUG_EN
141141

142142
// Define the Window
143-
extract_window(y, x, &image.data[0], &local_window[0], image.cols, image.rows);
143+
extract_window(y, x, image, &local_window[0], image.cols, image.rows);
144144

145145
for (int i = 0; i < IPS_FILTER_KERNEL_SIZE*IPS_FILTER_KERNEL_SIZE; ++i)
146146
{
@@ -157,10 +157,11 @@ SC_MODULE (testbench) {
157157
result = mean.read();
158158
// cout << "Read Result: " << (int) result << endl;
159159
// result = (sc_uint<8>) local_window[0];
160-
o_img.data[y*image.rows+x] = result;
160+
o_img.data[y*image.cols + x]= result;
161+
//*o_img.ptr(y, x) = result;
161162
#ifdef IPS_DEBUG_EN
162163
// SC_REPORT_INFO("TEST_MODE_IMAGE", "filtering");
163-
std::cout << "Iteration: " << (int) y*image.rows + x << " Original Pixel: " << (int) image.data[y* image.rows + x] << " Result = " << (int) result << std::endl;
164+
std::cout << "Iteration: " << (int) y*image.cols + x << " Original Pixel: " << (int) image.data[y* image.rows + x] << " Result = " << (int) result << std::endl;
164165
#endif // IPS_DEBUG_E
165166
}
166167
}
@@ -174,7 +175,7 @@ SC_MODULE (testbench) {
174175
}
175176
#endif //TEST_MODE_IMAGE
176177

177-
void extract_window(int x, int y, unsigned char *image, sc_uint<8>*window, int img_width , int img_height)
178+
void extract_window(int x, int y, cv::Mat image, sc_uint<8>*window, int img_width , int img_height)
178179
{
179180
int offset;
180181

@@ -186,118 +187,117 @@ SC_MODULE (testbench) {
186187
if ((x == 0) && (y == 0)){
187188
//First Row
188189
//Second Row
189-
offset = 0;
190-
window[4] = image[offset + 0];
191-
window[5] = image[offset + 1];
190+
window[4] =*image.ptr(x + 0, y);
191+
window[5] =*image.ptr(x + 0, y+1);
192192
//Third Row
193-
offset = img_height;
194-
window[7] = image[offset + 0];
195-
window[8] = image[offset + 1];
193+
194+
window[7] =*image.ptr(x + 1, y + 0);
195+
window[8] =*image.ptr(x + 1, y + 1);
196196
}
197-
else if ((x == 0) && (y == img_height - 1)){
197+
else if ((x + 0 == 0) && (y == img_height - 1)){
198198
//First Row
199199
//Second Row
200-
offset = img_height - 2;
201-
window[3] = image[offset + 0];
202-
window[4] = image[offset + 1];
200+
201+
window[3] =*image.ptr(x + 0, y + 0);
202+
window[4] =*image.ptr(x + 0, y + 1);
203203
//Third Row
204-
offset = img_height + (img_height - 2);
205-
window[6] = image[offset + 0];
206-
window[7] = image[offset + 1];
204+
205+
window[6] =*image.ptr(x + 1, y + 0);
206+
window[7] =*image.ptr(x + 1, y + 1);
207207
}
208-
else if ((x == 0) ){
208+
else if ((x + 0 == 0) ){
209209
//First Row
210210
//Second Row
211-
offset = (y-1);
212-
window[3] = image[offset + 0];
213-
window[4] = image[offset + 1];
214-
window[5] = image[offset + 2];
211+
212+
window[3] =*image.ptr(x + 0, y + 0);
213+
window[4] =*image.ptr(x + 0, y + 1);
214+
window[5] =*image.ptr(x + 0, y + 2);
215215
//Third Row
216-
offset = img_height + (y-1);
217-
window[6] = image[offset + 0];
218-
window[7] = image[offset + 1];
219-
window[8] = image[offset + 2];
216+
217+
window[6] =*image.ptr(x + 1, y + 0);
218+
window[7] =*image.ptr(x + 1, y + 1);
219+
window[8] =*image.ptr(x + 1, y + 2);
220220
}
221-
else if ((x == img_width-1) && (y == 0)){
221+
else if ((x + 0 == img_width-1) && (y == 0)){
222222
//First Row
223-
offset = (img_width - 2) * img_height;
224-
window[1] = image[offset + 0];
225-
window[2] = image[offset + 1];
223+
224+
window[1] =*image.ptr(x - 1, y + 0);
225+
window[2] =*image.ptr(x - 1, y + 1);
226226
//Second Row
227-
offset = (img_width - 1) * img_height;
228-
window[4] = image[offset + 0];
229-
window[5] = image[offset + 1];
227+
228+
window[4] =*image.ptr(x + 0, y + 0);
229+
window[5] =*image.ptr(x + 0, y + 1);
230230
//Third Row
231231
}
232-
else if ((x == img_width-1) && (y == img_height-1)){
232+
else if ((x + 0 == img_width-1) && (y == img_height-1)){
233233
//First Row
234-
offset = ((img_width - 2) * img_height) + (img_height - 2);
235-
window[0] = image[offset + 0];
236-
window[1] = image[offset + 1];
234+
235+
window[0] =*image.ptr(x - 1, y + 0);
236+
window[1] =*image.ptr(x - 1, y + 1);
237237
//Second Row
238-
offset = ((img_width - 1) * img_height) + (img_height - 2);
239-
window[3] = image[offset + 0];
240-
window[4] = image[offset + 1];
238+
239+
window[3] =*image.ptr(x + 0, y + 0);
240+
window[4] =*image.ptr(x + 0, y + 1);
241241
//Third Row
242242
}
243-
else if ((x == img_width-1)){
243+
else if ((x + 0 == img_width-1)){
244244
//First Row
245-
offset = ((img_width - 2) * img_height) + (y - 1);
246-
window[0] = image[offset + 0];
247-
window[1] = image[offset + 1];
248-
window[2] = image[offset + 2];
245+
246+
window[0] =*image.ptr(x - 1, y + 0);
247+
window[1] =*image.ptr(x - 1, y + 1);
248+
window[2] =*image.ptr(x - 1, y + 2);
249249
//Second Row
250-
offset = ((img_width - 1) * img_height) + (y - 1);
251-
window[3] = image[offset + 0];
252-
window[4] = image[offset + 1];
253-
window[5] = image[offset + 2];
250+
251+
window[3] =*image.ptr(x + 0, y + 0);
252+
window[4] =*image.ptr(x + 0, y + 1);
253+
window[5] =*image.ptr(x + 0, y + 2);
254254
//Third Row
255255
}
256256
else if ((y == 0)){
257257
//First Row
258-
offset = (x - 1) * img_height;
259-
window[1] = image[offset + 0];
260-
window[2] = image[offset + 1];
258+
259+
window[1] =*image.ptr(x - 1, y + 0);
260+
window[2] =*image.ptr(x - 1, y + 1);
261261
//Second Row
262-
offset = (x * img_height);
263-
window[4] = image[offset + 0];
264-
window[5] = image[offset + 1];
262+
263+
window[4] =*image.ptr(x + 0, y + 0);
264+
window[5] =*image.ptr(x + 0, y + 1);
265265
//Third Row
266-
offset = (x + 1) * img_height;
267-
window[7] = image[offset + 0];
268-
window[8] = image[offset + 1];
266+
267+
window[7] =*image.ptr(x + 1, y + 0);
268+
window[8] =*image.ptr(x + 1, y + 1);
269269
}
270270
else if (y == img_height-1){
271271
//First Row
272-
offset = ((x - 1) * img_height) + (y - 1);
273-
window[0] = image[offset + 0];
274-
window[1] = image[offset + 1];
272+
273+
window[0] =*image.ptr(x - 1, y + 0);
274+
window[1] =*image.ptr(x - 1, y + 1);
275275
//Second Row
276-
offset = (x * img_height) + (y - 1);
277-
window[3] = image[offset + 0];
278-
window[4] = image[offset + 1];
276+
277+
window[3] =*image.ptr(x + 0, y + 0);
278+
window[4] =*image.ptr(x + 0, y + 1);
279279
//Third Row
280-
offset = ((x + 1) * img_height) + (y - 1);
281-
window[6] = image[offset + 0];
282-
window[7] = image[offset + 1];
280+
281+
window[6] =*image.ptr(x + 1, y + 0);
282+
window[7] =*image.ptr(x + 1, y + 1);
283283
}
284284
else
285285
{
286286
//First Row
287-
offset = ((x - 1) * img_height) + (y - 1);
288-
window[0] = image[offset + 0];
289-
window[1] = image[offset + 1];
290-
window[2] = image[offset + 2];
287+
288+
window[0] =*image.ptr(x - 1, y + 0);
289+
window[1] =*image.ptr(x - 1, y + 1);
290+
window[2] =*image.ptr(x - 1, y + 2);
291291
//Second Row
292-
offset = (x * img_height) + (y - 1);
293-
window[3] = image[offset + 0];
294-
window[4] = image[offset + 1];
295-
window[5] = image[offset + 2];
292+
293+
window[3] =*image.ptr(x + 0, y + 0);
294+
window[4] =*image.ptr(x + 0, y + 1);
295+
window[5] =*image.ptr(x + 0, y + 2);
296296
//Third Row
297-
offset = ((x + 1) * img_height) + (y - 1);
298-
window[6] = image[offset + 0];
299-
window[7] = image[offset + 1];
300-
window[8] = image[offset + 2];
297+
298+
window[6] =*image.ptr(x + 1, y + 0);
299+
window[7] =*image.ptr(x + 1, y + 1);
300+
window[8] =*image.ptr(x + 1, y + 2);
301301
}
302302
}
303303
};

0 commit comments

Comments
 (0)