@@ -149,16 +149,23 @@ SC_MODULE(Tb_top)
149149 }
150150 }
151151
152- Mat grayImage (IMAG_ROWS, IMAG_COLS, CV_8UC1);
153- Mat filteredImage (IMAG_ROWS, IMAG_COLS, CV_8UC1);
154- Mat detectedImageX (IMAG_ROWS, IMAG_COLS, CV_8UC1);
155- Mat detectedImageY (IMAG_ROWS, IMAG_COLS, CV_8UC1);
156- Mat detectedImage (IMAG_ROWS, IMAG_COLS, CV_8UC1);
152+ Mat grayImagePrevMem (IMAG_ROWS, IMAG_COLS, CV_8UC1);
153+ Mat filteredImagePrevMem (IMAG_ROWS, IMAG_COLS, CV_8UC1);
154+ Mat detectedImagePrevMemX (IMAG_ROWS, IMAG_COLS, CV_8UC1);
155+ Mat detectedImagePrevMemY (IMAG_ROWS, IMAG_COLS, CV_8UC1);
156+ Mat detectedImagePrevMem (IMAG_ROWS, IMAG_COLS, CV_8UC1);
157+
158+ Mat grayImageAfterMem (IMAG_ROWS, IMAG_COLS, CV_8UC1);
159+ Mat filteredImageAfterMem (IMAG_ROWS, IMAG_COLS, CV_8UC1);
160+ Mat detectedImageAfterMemX (IMAG_ROWS, IMAG_COLS, CV_8UC1);
161+ Mat detectedImageAfterMemY (IMAG_ROWS, IMAG_COLS, CV_8UC1);
162+ Mat detectedImageAfterMem (IMAG_ROWS, IMAG_COLS, CV_8UC1);
157163
158164 total_number_of_pixels = IMAG_ROWS * IMAG_COLS;
159165
160166 for (int i = 0 ; i < IMAG_ROWS; i++)
161167 {
168+ int local_group_count = 0 ;
162169 for (int j = 0 ; j < IMAG_COLS; j++)
163170 {
164171 unsigned char * read_ptr;
@@ -173,7 +180,7 @@ SC_MODULE(Tb_top)
173180
174181 dbgprint (" Data_returned: %0d" , localResult);
175182
176- grayImage .at <uchar>(i, j) = (unsigned char )localResult;
183+ grayImagePrevMem .at <uchar>(i, j) = (unsigned char )localResult;
177184
178185 if (local_count == 0 )
179186 {
@@ -187,9 +194,10 @@ SC_MODULE(Tb_top)
187194 if (local_count == 8 )
188195 {
189196 dbgprint (" Before doing a write in TB" );
190- memory_initiator->write (local_results, IMG_INPROCESS_A + ((i * IMAG_COLS) + j ), 8 * sizeof (char ));
197+ memory_initiator->write (local_results, IMG_INPROCESS_A + ((i * IMAG_COLS) + (local_group_count * 8 * sizeof ( char )) ), 8 * sizeof (char ));
191198 dbgprint (" After doing a write in TB" );
192199 local_count = 0 ;
200+ local_group_count++;
193201 }
194202
195203 current_number_of_pixels++;
@@ -202,6 +210,17 @@ SC_MODULE(Tb_top)
202210
203211 dbgprint (" Finished gray scale conversion" );
204212
213+ // Sanity check that the image was written in memory as expected
214+ for (int i = 0 ; i < IMAG_ROWS; i++)
215+ {
216+ for (int j = 0 ; j < IMAG_COLS; j++)
217+ {
218+ unsigned char * read_ptr;
219+ memory_DUT->backdoor_read (read_ptr, 1 * sizeof (char ), IMG_INPROCESS_A + ((i * IMAG_COLS) + j));
220+ grayImageAfterMem.at <uchar>(i, j) = *read_ptr;
221+ }
222+ }
223+
205224 local_count = 0 ;
206225 current_number_of_pixels = 0 ;
207226 next_target_of_completion = 10.0 ;
@@ -232,10 +251,10 @@ SC_MODULE(Tb_top)
232251 data_returned = *data_returned_ptr;
233252
234253 if (data_returned > 255.0 ) {
235- filteredImage .at <uchar>(i, j) = 255 ;
254+ filteredImagePrevMem .at <uchar>(i, j) = 255 ;
236255 }
237256 else {
238- filteredImage .at <uchar>(i, j) = (unsigned char )data_returned;
257+ filteredImagePrevMem .at <uchar>(i, j) = (unsigned char )data_returned;
239258 }
240259
241260 if (local_count == 0 )
@@ -244,7 +263,6 @@ SC_MODULE(Tb_top)
244263 }
245264
246265 if (data_returned > 255.0 ) {
247- filteredImage.at <uchar>(i, j) = 255 ;
248266 *(local_results + local_count) = 255 ;
249267 }
250268 else {
@@ -256,9 +274,10 @@ SC_MODULE(Tb_top)
256274 if (local_count == 8 )
257275 {
258276 dbgprint (" Before doing a write in TB" );
259- memory_initiator->write (local_results, IMG_COMPRESSED + ((i * IMAG_COLS) + j ), 8 * sizeof (char ));
277+ memory_initiator->write (local_results, IMG_COMPRESSED + ((i * IMAG_COLS) + (local_group_count * 8 * sizeof ( char )) ), 8 * sizeof (char ));
260278 dbgprint (" After doing a write in TB" );
261279 local_count = 0 ;
280+ local_group_count++;
262281 }
263282
264283 current_number_of_pixels++;
@@ -271,6 +290,17 @@ SC_MODULE(Tb_top)
271290
272291 dbgprint (" Finished filtering the image" );
273292
293+ // Sanity check that the image was written in memory as expected
294+ for (int i = 0 ; i < IMAG_ROWS; i++)
295+ {
296+ for (int j = 0 ; j < IMAG_COLS; j++)
297+ {
298+ unsigned char * read_ptr;
299+ memory_DUT->backdoor_read (read_ptr, 1 * sizeof (char ), IMG_COMPRESSED + ((i * IMAG_COLS) + j));
300+ filteredImageAfterMem.at <uchar>(i, j) = *read_ptr;
301+ }
302+ }
303+
274304 local_count = 0 ;
275305 current_number_of_pixels = 0 ;
276306 next_target_of_completion = 10.0 ;
@@ -310,32 +340,32 @@ SC_MODULE(Tb_top)
310340 localGradientY = *(data_returned_ptr+1 );
311341
312342 if ((localGradientX > 255 ) || (localGradientX < -255 )) {
313- detectedImageX .at <uchar>(i, j) = 255 ;
343+ detectedImagePrevMemX .at <uchar>(i, j) = 255 ;
314344 }
315345 else if (localGradientX < 0 ) {
316- detectedImageX .at <uchar>(i, j) = (unsigned char )(-localGradientX);
346+ detectedImagePrevMemX .at <uchar>(i, j) = (unsigned char )(-localGradientX);
317347 }
318348 else {
319- detectedImageX .at <uchar>(i, j) = (unsigned char )localGradientX;
349+ detectedImagePrevMemX .at <uchar>(i, j) = (unsigned char )localGradientX;
320350 }
321351 if ((localGradientY > 255 ) || (localGradientY < -255 )) {
322- detectedImageY .at <uchar>(i, j) = 255 ;
352+ detectedImagePrevMemY .at <uchar>(i, j) = 255 ;
323353 }
324354 else if (localGradientY < 0 ) {
325- detectedImageY .at <uchar>(i, j) = (unsigned char )(-localGradientY);
355+ detectedImagePrevMemY .at <uchar>(i, j) = (unsigned char )(-localGradientY);
326356 }
327357 else {
328- detectedImageY .at <uchar>(i, j) = (unsigned char )localGradientY;
358+ detectedImagePrevMemY .at <uchar>(i, j) = (unsigned char )localGradientY;
329359 }
330360
331361 localResult = (unsigned short int )sqrt ((float )(pow (localGradientX, 2 )) + (float )(pow (localGradientY, 2 )));
332362 if (localResult > 255 )
333363 {
334- detectedImage .at <uchar>(i, j) = 255 ;
364+ detectedImagePrevMem .at <uchar>(i, j) = 255 ;
335365 }
336366 else
337367 {
338- detectedImage .at <uchar>(i, j) = (unsigned char )localResult;
368+ detectedImagePrevMem .at <uchar>(i, j) = (unsigned char )localResult;
339369 }
340370
341371 if (local_count == 0 )
@@ -351,11 +381,11 @@ SC_MODULE(Tb_top)
351381 {
352382 write_ptr = local_results;
353383 dbgprint (" Before doing a write in TB" );
354- memory_initiator->write (write_ptr, IMG_INPROCESS_B + ((i * IMAG_COLS) + (local_group_count * 4 * sizeof (short int ))), 4 * sizeof (short int ));
384+ memory_initiator->write (write_ptr, IMG_INPROCESS_B + ((i * IMAG_COLS * sizeof ( short int ) ) + (local_group_count * 4 * sizeof (short int ))), 4 * sizeof (short int ));
355385 dbgprint (" After doing a write in TB" );
356386 write_ptr = (local_results + 8 );
357387 dbgprint (" Before doing a write in TB" );
358- memory_initiator->write (write_ptr, IMG_INPROCESS_C + ((i * IMAG_COLS) + (local_group_count * 4 * sizeof (short int ))), 4 * sizeof (short int ));
388+ memory_initiator->write (write_ptr, IMG_INPROCESS_C + ((i * IMAG_COLS * sizeof ( short int ) ) + (local_group_count * 4 * sizeof (short int ))), 4 * sizeof (short int ));
359389 dbgprint (" After doing a write in TB" );
360390 local_count = 0 ;
361391 local_group_count++;
@@ -369,11 +399,52 @@ SC_MODULE(Tb_top)
369399 }
370400 }
371401
372- imwrite (" grayImage.jpg" , grayImage);
373- imwrite (" filteredImage.jpg" , filteredImage);
374- imwrite (" detectedImageX.jpg" , detectedImageX);
375- imwrite (" detectedImageY.jpg" , detectedImageY);
376- imwrite (" detectedImage.jpg" , detectedImage);
402+ // Sanity check that the image was written in memory as expected
403+ for (int i = 0 ; i < IMAG_ROWS; i++)
404+ {
405+ for (int j = 0 ; j < IMAG_COLS; j++)
406+ {
407+ unsigned char * read_ptr;
408+ short int * data_returned_ptr;
409+
410+ memory_DUT->backdoor_read (read_ptr, sizeof (short int ), IMG_INPROCESS_B + ((i * IMAG_COLS * sizeof (short int )) + (j * sizeof (short int ))));
411+ data_returned_ptr = reinterpret_cast <short int *>(read_ptr);
412+ localGradientX = *data_returned_ptr;
413+ if ((localGradientX > 255 ) || (localGradientX < -255 )) {
414+ detectedImageAfterMemX.at <uchar>(i, j) = 255 ;
415+ }
416+ else if (localGradientX < 0 ) {
417+ detectedImageAfterMemX.at <uchar>(i, j) = (unsigned char )(-localGradientX);
418+ }
419+ else {
420+ detectedImageAfterMemX.at <uchar>(i, j) = (unsigned char )localGradientX;
421+ }
422+
423+ memory_DUT->backdoor_read (read_ptr, sizeof (short int ), IMG_INPROCESS_C + ((i * IMAG_COLS * sizeof (short int )) + (j * sizeof (short int ))));
424+ data_returned_ptr = reinterpret_cast <short int *>(read_ptr);
425+ localGradientY = *data_returned_ptr;
426+ if ((localGradientY > 255 ) || (localGradientY < -255 )) {
427+ detectedImageAfterMemY.at <uchar>(i, j) = 255 ;
428+ }
429+ else if (localGradientY < 0 ) {
430+ detectedImageAfterMemY.at <uchar>(i, j) = (unsigned char )(-localGradientY);
431+ }
432+ else {
433+ detectedImageAfterMemY.at <uchar>(i, j) = (unsigned char )localGradientY;
434+ }
435+ }
436+ }
437+
438+ imwrite (" grayImagePrevMem.jpg" , grayImagePrevMem);
439+ imwrite (" grayImageAfterMem.jpg" , grayImageAfterMem);
440+ imwrite (" filteredImagePrevMem.jpg" , filteredImagePrevMem);
441+ imwrite (" filteredImageAfterMem.jpg" , filteredImageAfterMem);
442+ imwrite (" detectedImagePrevMemX.jpg" , detectedImagePrevMemX);
443+ imwrite (" detectedImageAfterMemX.jpg" , detectedImageAfterMemX);
444+ imwrite (" detectedImagePrevMemY.jpg" , detectedImagePrevMemY);
445+ imwrite (" detectedImageAfterMemY.jpg" , detectedImageAfterMemY);
446+ imwrite (" detectedImagePrevMem.jpg" , detectedImagePrevMem);
447+ imwrite (" detectedImageAfterMem.jpg" , detectedImageAfterMem);
377448 }
378449
379450 void extract_window (int i, int j, unsigned int initial_address, unsigned char *& local_window_ptr)
0 commit comments