From fa7528490cb23e286791c4c29bf9034ea8d559bf Mon Sep 17 00:00:00 2001 From: mai Date: Wed, 20 Feb 2019 17:54:11 +0900 Subject: [PATCH] add testbench --- src/PE_func.cpp | 12 +- src/hough.cpp | 6 +- src/rle.cpp | 2 +- src/top.cpp | 8 +- test/sub.h | 6 +- test/sys_tb.cpp | 478 +++++++++++++++++++++++++++++++++++++++++++ test/sys_tb.h | 48 +++++ test/whole_tb_ln.cpp | 120 +++++++---- 8 files changed, 620 insertions(+), 60 deletions(-) create mode 100644 test/sys_tb.cpp create mode 100644 test/sys_tb.h diff --git a/src/PE_func.cpp b/src/PE_func.cpp index cfd9adb..f80dd11 100644 --- a/src/PE_func.cpp +++ b/src/PE_func.cpp @@ -11,12 +11,12 @@ void reset(int *v, int *vo, int *svote){ vo[7] = 0; } type_t inter(int rb, int z, int theta, int rst, type_t my_cos, type_t my_sin){ - static type_t step[180]; -#pragma HLS ARRAY_PARTITION variable=step complete dim=0 - static type_t row[180]; -#pragma HLS ARRAY_PARTITION variable=row complete dim=0 - static type_t col[180]; -#pragma HLS ARRAY_PARTITION variable=col complete dim=0 + static type_t step[180]={0}; +//#pragma HLS ARRAY_PARTITION variable=step complete dim=0 + static type_t row[180]={0}; +//#pragma HLS ARRAY_PARTITION variable=row complete dim=0 + static type_t col[180]={0}; +//#pragma HLS ARRAY_PARTITION variable=col complete dim=0 #pragma HLS PIPELINE diff --git a/src/hough.cpp b/src/hough.cpp index f8fb9b2..03f1c71 100644 --- a/src/hough.cpp +++ b/src/hough.cpp @@ -9,9 +9,9 @@ #endif int hough(int symbol, volatile int *vote, type_t *my_cos, type_t *my_sin, int rst){ -#pragma HLS INTERFACE m_axi depth=144000 port=vote offset=slave bundle=vote -#pragma HLS INTERFACE m_axi depth=91 port=my_cos offset=slave bundle=my_cos -#pragma HLS INTERFACE m_axi depth=91 port=my_sin offset=slave bundle=my_sin +//#pragma HLS INTERFACE m_axi depth=144000 port=vote offset=slave bundle=vote +//#pragma HLS INTERFACE m_axi depth=91 port=my_cos offset=slave bundle=my_cos +//#pragma HLS INTERFACE m_axi depth=91 port=my_sin offset=slave bundle=my_sin int rb, c, zl; int i; diff --git a/src/rle.cpp b/src/rle.cpp index a8067b1..de00b33 100644 --- a/src/rle.cpp +++ b/src/rle.cpp @@ -1,6 +1,6 @@ #include "../test/sub.h" -int rle(int pix, hls::stream &que) +int rle(int pix, hls::stream &que) { //#pragma HLS INTERFACE axis port=&que //int code=0, B=0, zl=0, rb=1, symbol; diff --git a/src/top.cpp b/src/top.cpp index e236eb2..a2e1738 100644 --- a/src/top.cpp +++ b/src/top.cpp @@ -2,7 +2,7 @@ #include "PE.h" int im_top(int, int); -int rle(int , hls::stream&); +int rle(int , hls::stream&); int hough(int, volatile int *, type_t *, type_t *, int); #ifdef __SDSCC__ @@ -14,14 +14,16 @@ int hough(int, volatile int *, type_t *, type_t *, int); #pragma SDS data access_pattern(my_sin:SEQUENTIAL) #endif int top(int *ins, volatile int *vote, type_t *my_cos, type_t *my_sin){ -#pragma HLS INTERFACE axis depth=307200 port=ins +#pragma HLS INTERFACE axis depth=307200 port=&ins #pragma HLS INTERFACE m_axi depth=144000 port=vote offset=slave bundle=vote #pragma HLS INTERFACE m_axi depth=91 port=my_cos offset=slave bundle=my_cos #pragma HLS INTERFACE m_axi depth=91 port=my_sin offset=slave bundle=my_sin +#pragma HLS INTERFACE s_axilite port=return + int pix, out; int symbol, rst=0; - hls::stream que("que"); + hls::stream que("que"); #pragma HLS STREAM variable=que depth=2560 //#pragma HLS dataflow diff --git a/test/sub.h b/test/sub.h index be50b53..7acbc4c 100644 --- a/test/sub.h +++ b/test/sub.h @@ -22,9 +22,9 @@ #define N 4 //typedef uint32_t data_t; -typedef int data_t; -//typedef ap_ufixed<32,12> type_t; -typedef double type_t; +//typedef int data_t; +typedef ap_fixed<32,12> type_t; +//typedef double type_t; // External function prototypes diff --git a/test/sys_tb.cpp b/test/sys_tb.cpp new file mode 100644 index 0000000..f421889 --- /dev/null +++ b/test/sys_tb.cpp @@ -0,0 +1,478 @@ +#include "sub.h" +#include "sys_tb.h" +#include + +testbench::testbench(){}; +testbench::~testbench(){}; + +int testbench::sobel5( + int x0y0, int x1y0, int x2y0, int x3y0, int x4y0, + int x0y2, int x1y2, int x2y2, int x3y2, int x4y2, + int x0y4, int x1y4, int x2y4, int x3y4, int x4y4, + int th){ + int y; + + y = (x0y0 + 4*x1y0 + 6*x2y0 + 4*x3y0 + x4y0 + -2*x0y2 -8*x1y2 -12*x2y2 -8*x3y2 -2*x4y2 + + x0y4 + 4*x1y4 + 6*x2y4 + 4*x3y4 + x4y4); + + if(y<0) y = -1*y; + if (y>th) + y = 1; + else + y = 0; + + return y; +} + +int testbench::dilate( + int x0y0, int x1y0, int x2y0, int x3y0, int x4y0, + int x0y1, int x1y1, int x2y1, int x3y1, int x4y1, + int x0y2, int x1y2, int x2y2, int x3y2, int x4y2, + int x0y3, int x1y3, int x2y3, int x3y3, int x4y3, + int x0y4, int x1y4, int x2y4, int x3y4, int x4y4){ + int max; + max = x2y0; + if(x0y1 > max) max = x0y1; + if(x1y1 > max) max = x1y1; + if(x2y1 > max) max = x2y1; + if(x3y1 > max) max = x3y1; + if(x4y1 > max) max = x4y1; + if(x0y2 > max) max = x0y2; + if(x1y2 > max) max = x1y2; + if(x2y2 > max) max = x2y2; + if(x3y2 > max) max = x3y2; + if(x4y2 > max) max = x4y2; + if(x0y3 > max) max = x0y3; + if(x1y3 > max) max = x1y3; + if(x2y3 > max) max = x2y3; + if(x3y3 > max) max = x3y3; + if(x4y3 > max) max = x4y3; + if(x2y4 > max) max = x2y4; + //printf("%d\n",max); + return (max); +} + +int testbench::erode( + int x0y0, int x1y0, int x2y0, int x3y0, int x4y0, + int x0y1, int x1y1, int x2y1, int x3y1, int x4y1, + int x0y2, int x1y2, int x2y2, int x3y2, int x4y2, + int x0y3, int x1y3, int x2y3, int x3y3, int x4y3, + int x0y4, int x1y4, int x2y4, int x3y4, int x4y4){ + int min; + min = x2y0; + + if(x0y1 < min) min = x0y1; + if(x1y1 < min) min = x1y1; + if(x2y1 < min) min = x2y1; + if(x3y1 < min) min = x3y1; + if(x4y1 < min) min = x4y1; + if(x0y2 < min) min = x0y2; + if(x1y2 < min) min = x1y2; + if(x2y2 < min) min = x2y2; + if(x3y2 < min) min = x3y2; + if(x4y2 < min) min = x4y2; + if(x0y3 < min) min = x0y3; + if(x1y3 < min) min = x1y3; + if(x2y3 < min) min = x2y3; + if(x3y3 < min) min = x3y3; + if(x4y3 < min) min = x4y3; + if(x2y4 < min) min = x2y4; + //printf("%d\n",min); + return (min); +} + +int testbench::im_top(int x, int pix){ + int i, j=0, k=0; + int pix2, pix3, pix4, pix5, pix6, out=0; + static unsigned int line_buf[4][HORIZONTAL_PIXEL_WIDTH]; + static unsigned int line_buf2[4][HORIZONTAL_PIXEL_WIDTH]; + static unsigned int line_buf3[4][HORIZONTAL_PIXEL_WIDTH]; + static unsigned int line_buf4[4][HORIZONTAL_PIXEL_WIDTH]; + static unsigned int line_buf5[4][HORIZONTAL_PIXEL_WIDTH]; + static unsigned int line_buf6[4][HORIZONTAL_PIXEL_WIDTH]; + static unsigned int line_buf7[4][HORIZONTAL_PIXEL_WIDTH]; + static int pix_mat[5][5]={{0}}; + static int pix_mat2[5][5]={{0}}; + static int pix_mat3[5][5]={{0}}; + static int pix_mat4[5][5]={{0}}; + static int pix_mat5[5][5]={{0}}; + static int pix_mat6[5][5]={{0}}; + + int val, a, tmp; + ROOP1:for (int k=0; k<5; k++){ + for (int m=0; m<4; m++){ + pix_mat[k][m] = pix_mat[k][m+1]; + } + } + + pix_mat[0][4] = line_buf[0][x]; + pix_mat[1][4] = line_buf[1][x]; + pix_mat[2][4] = line_buf[2][x]; + pix_mat[3][4] = line_buf[3][x]; + pix_mat[4][4] = pix; + + line_buf[0][x] = line_buf[1][x]; + line_buf[1][x] = line_buf[2][x]; // �s�̓���ւ� + line_buf[2][x] = line_buf[3][x]; + line_buf[3][x] = pix; + + + val = 0; + for(a=16; a>=0; a-=8){ + tmp = erode( + (pix_mat[0][0]>>a)&0xff, (pix_mat[0][1]>>a)&0xff, (pix_mat[0][2]>>a)&0xff, (pix_mat[0][3]>>a)&0xff, (pix_mat[0][4]>>a)&0xff, + (pix_mat[1][0]>>a)&0xff, (pix_mat[1][1]>>a)&0xff, (pix_mat[1][2]>>a)&0xff, (pix_mat[1][3]>>a)&0xff, (pix_mat[1][4]>>a)&0xff, + (pix_mat[2][0]>>a)&0xff, (pix_mat[2][1]>>a)&0xff, (pix_mat[2][2]>>a)&0xff, (pix_mat[2][3]>>a)&0xff, (pix_mat[2][4]>>a)&0xff, + (pix_mat[3][0]>>a)&0xff, (pix_mat[3][1]>>a)&0xff, (pix_mat[3][2]>>a)&0xff, (pix_mat[3][3]>>a)&0xff, (pix_mat[3][4]>>a)&0xff, + (pix_mat[4][0]>>a)&0xff, (pix_mat[4][1]>>a)&0xff, (pix_mat[4][2]>>a)&0xff, (pix_mat[4][3]>>a)&0xff, (pix_mat[4][4]>>a)&0xff); + val += tmp << a; + } + + pix2 = val; // RGB�����l������ + if (x<4 ) // �ŏ���2�s�Ƃ��̑��̍s�̍ŏ���2��͖����f�[�^�Ȃ̂�0�Ƃ��� + pix2 = 0; + + ROOP2:for (int k=0; k<5; k++){ + for (int m=0; m<4; m++){ + pix_mat2[k][m] = pix_mat2[k][m+1]; + } + } + + pix_mat2[0][4] = line_buf2[0][x]; + pix_mat2[1][4] = line_buf2[1][x]; + pix_mat2[2][4] = line_buf2[2][x]; + pix_mat2[3][4] = line_buf2[3][x]; + pix_mat2[4][4] = pix2; + + line_buf2[0][x] = line_buf2[1][x]; + line_buf2[1][x] = line_buf2[2][x]; // �s�̓���ւ� + line_buf2[2][x] = line_buf2[3][x]; + line_buf2[3][x] = pix2; + + val = 0; + for(a=16; a>=0; a-=8){ + tmp = dilate( + (pix_mat2[0][0]>>a)&0xff, (pix_mat2[0][1]>>a)&0xff, (pix_mat2[0][2]>>a)&0xff, (pix_mat2[0][3]>>a)&0xff, (pix_mat2[0][4]>>a)&0xff, + (pix_mat2[1][0]>>a)&0xff, (pix_mat2[1][1]>>a)&0xff, (pix_mat2[1][2]>>a)&0xff, (pix_mat2[1][3]>>a)&0xff, (pix_mat2[1][4]>>a)&0xff, + (pix_mat2[2][0]>>a)&0xff, (pix_mat2[2][1]>>a)&0xff, (pix_mat2[2][2]>>a)&0xff, (pix_mat2[2][3]>>a)&0xff, (pix_mat2[2][4]>>a)&0xff, + (pix_mat2[3][0]>>a)&0xff, (pix_mat2[3][1]>>a)&0xff, (pix_mat2[3][2]>>a)&0xff, (pix_mat2[3][3]>>a)&0xff, (pix_mat2[3][4]>>a)&0xff, + (pix_mat2[4][0]>>a)&0xff, (pix_mat2[4][1]>>a)&0xff, (pix_mat2[4][2]>>a)&0xff, (pix_mat2[4][3]>>a)&0xff, (pix_mat2[4][4]>>a)&0xff); + val += tmp << a; + } + + pix3 = val; + if(x<4) + pix3 = 0; + + ROOP3:for (int k=0; k<5; k++){ + for (int m=0; m<4; m++){ + pix_mat3[k][m] = pix_mat3[k][m+1]; + } + } + + pix_mat3[0][4] = line_buf3[0][x]; + pix_mat3[1][4] = line_buf3[1][x]; + pix_mat3[2][4] = line_buf3[2][x]; + pix_mat3[3][4] = line_buf3[3][x]; + pix_mat3[4][4] = pix3; + + line_buf3[0][x] = line_buf3[1][x]; + line_buf3[1][x] = line_buf3[2][x]; // �s�̓���ւ� + line_buf3[2][x] = line_buf3[3][x]; + line_buf3[3][x] = pix3; + + val = 0; + for(a=16; a>=0; a-=8){ + tmp = dilate( + (pix_mat3[0][0]>>a)&0xff, (pix_mat3[0][1]>>a)&0xff, (pix_mat3[0][2]>>a)&0xff, (pix_mat3[0][3]>>a)&0xff, (pix_mat3[0][4]>>a)&0xff, + (pix_mat3[1][0]>>a)&0xff, (pix_mat3[1][1]>>a)&0xff, (pix_mat3[1][2]>>a)&0xff, (pix_mat3[1][3]>>a)&0xff, (pix_mat3[1][4]>>a)&0xff, + (pix_mat3[2][0]>>a)&0xff, (pix_mat3[2][1]>>a)&0xff, (pix_mat3[2][2]>>a)&0xff, (pix_mat3[2][3]>>a)&0xff, (pix_mat3[2][4]>>a)&0xff, + (pix_mat3[3][0]>>a)&0xff, (pix_mat3[3][1]>>a)&0xff, (pix_mat3[3][2]>>a)&0xff, (pix_mat3[3][3]>>a)&0xff, (pix_mat3[3][4]>>a)&0xff, + (pix_mat3[4][0]>>a)&0xff, (pix_mat3[4][1]>>a)&0xff, (pix_mat3[4][2]>>a)&0xff, (pix_mat3[4][3]>>a)&0xff, (pix_mat3[4][4]>>a)&0xff); + val += tmp << a; + } + + pix4 = val; + if(x<4) + pix4 = 0; + + ROOP4:for (int k=0; k<5; k++){ + for (int m=0; m<4; m++){ + pix_mat4[k][m] = pix_mat4[k][m+1]; + } + } + + pix_mat4[0][4] = line_buf4[0][x]; + pix_mat4[1][4] = line_buf4[1][x]; + pix_mat4[2][4] = line_buf4[2][x]; + pix_mat4[3][4] = line_buf4[3][x]; + pix_mat4[4][4] = pix4; + + line_buf4[0][x] = line_buf4[1][x]; + line_buf4[1][x] = line_buf4[2][x]; // �s�̓���ւ� + line_buf4[2][x] = line_buf4[3][x]; + line_buf4[3][x] = pix4; + + val = 0; + for(a=16; a>=0; a-=8){ + tmp = erode( + (pix_mat4[0][0]>>a)&0xff, (pix_mat4[0][1]>>a)&0xff, (pix_mat4[0][2]>>a)&0xff, (pix_mat4[0][3]>>a)&0xff, (pix_mat4[0][4]>>a)&0xff, + (pix_mat4[1][0]>>a)&0xff, (pix_mat4[1][1]>>a)&0xff, (pix_mat4[1][2]>>a)&0xff, (pix_mat4[1][3]>>a)&0xff, (pix_mat4[1][4]>>a)&0xff, + (pix_mat4[2][0]>>a)&0xff, (pix_mat4[2][1]>>a)&0xff, (pix_mat4[2][2]>>a)&0xff, (pix_mat4[2][3]>>a)&0xff, (pix_mat4[2][4]>>a)&0xff, + (pix_mat4[3][0]>>a)&0xff, (pix_mat4[3][1]>>a)&0xff, (pix_mat4[3][2]>>a)&0xff, (pix_mat4[3][3]>>a)&0xff, (pix_mat4[3][4]>>a)&0xff, + (pix_mat4[4][0]>>a)&0xff, (pix_mat4[4][1]>>a)&0xff, (pix_mat4[4][2]>>a)&0xff, (pix_mat4[4][3]>>a)&0xff, (pix_mat4[4][4]>>a)&0xff); + val += tmp << a; + } + + pix5 = val; + if(x<4) + pix5 = 0; + +ROOP5:for (int k=0; k<5; k++){ + for (int m=0; m<4; m++){ + pix_mat5[k][m] = pix_mat5[k][m+1]; + } + } + + pix_mat5[0][4] = line_buf5[0][x]; + pix_mat5[1][4] = line_buf5[1][x]; + pix_mat5[2][4] = line_buf5[2][x]; + pix_mat5[3][4] = line_buf5[3][x]; + pix_mat5[4][4] = pix5; + + line_buf5[0][x] = line_buf5[1][x]; + line_buf5[1][x] = line_buf5[2][x]; // �s�̓���ւ� + line_buf5[2][x] = line_buf5[3][x]; + line_buf5[3][x] = pix5; + + val = 0; + for(a=16; a>=0; a-=8){ + tmp = sobel5( + (pix_mat5[0][0]>>a)&0xff, (pix_mat5[0][1]>>a)&0xff, (pix_mat5[0][2]>>a)&0xff, (pix_mat5[0][3]>>a)&0xff, (pix_mat5[0][4]>>a)&0xff, + (pix_mat5[2][0]>>a)&0xff, (pix_mat5[2][1]>>a)&0xff, (pix_mat5[2][2]>>a)&0xff, (pix_mat5[2][3]>>a)&0xff, (pix_mat5[2][4]>>a)&0xff, + (pix_mat5[4][0]>>a)&0xff, (pix_mat5[4][1]>>a)&0xff, (pix_mat5[4][2]>>a)&0xff, (pix_mat5[4][3]>>a)&0xff, (pix_mat5[4][4]>>a)&0xff, + 200); + val += tmp << a; + } + + if(x<4) + pix6 = 0; + + pix6 = val; + + ROOP6:for (int k=0; k<5; k++){ + for (int m=0; m<4; m++){ + pix_mat6[k][m] = pix_mat6[k][m+1]; + } + } + + pix_mat6[0][4] = line_buf6[0][x]; + pix_mat6[1][4] = line_buf6[1][x]; + pix_mat6[2][4] = line_buf6[2][x]; + pix_mat6[3][4] = line_buf6[3][x]; + pix_mat6[4][4] = pix6; + + line_buf6[0][x] = line_buf6[1][x]; + line_buf6[1][x] = line_buf6[2][x]; // �s�̓���ւ� + line_buf6[2][x] = line_buf6[3][x]; + line_buf6[3][x] = pix6; + + val = 0; + for(a=16; a>=0; a-=8){ + tmp = ((pix_mat6[0][0]>>a)&0xff) | ((pix_mat6[0][1]>>a)&0xff) | ((pix_mat6[0][2]>>a)&0xff) | ((pix_mat6[0][3]>>a)&0xff) | ((pix_mat6[0][4]>>a)&0xff) | + ((pix_mat6[1][0]>>a)&0xff) | ((pix_mat6[1][1]>>a)&0xff) | ((pix_mat6[1][2]>>a)&0xff) | ((pix_mat6[1][3]>>a)&0xff) | ((pix_mat6[1][4]>>a)&0xff) | + ((pix_mat6[2][0]>>a)&0xff) | ((pix_mat6[2][1]>>a)&0xff) | ((pix_mat6[2][2]>>a)&0xff) | ((pix_mat6[2][3]>>a)&0xff) | ((pix_mat6[2][4]>>a)&0xff) | + ((pix_mat6[3][0]>>a)&0xff) | ((pix_mat6[3][1]>>a)&0xff) | ((pix_mat6[3][2]>>a)&0xff) | ((pix_mat6[3][3]>>a)&0xff) | ((pix_mat6[3][4]>>a)&0xff) | + ((pix_mat6[4][0]>>a)&0xff) | ((pix_mat6[4][1]>>a)&0xff) | ((pix_mat6[4][2]>>a)&0xff) | ((pix_mat6[4][3]>>a)&0xff) | ((pix_mat6[4][4]>>a)&0xff); + val += tmp << a; + } + out = (val & 0xff) & (val >> 8 & 0xff ) & (val >> 16 & 0xff); +// out = val & 0xff; + + if(x<4) + out = 0; + + return out; +} + +int testbench::rle(int pix, std::queue *que) +{ + unsigned int symbol=0, rb=1; + unsigned int code=0, B=0; + unsigned int zl=0; + + static unsigned int line_buf[4][HORIZONTAL_PIXEL_WIDTH]; + static unsigned int m=0; + static unsigned int n=0; + + if(n > HORIZONTAL_PIXEL_WIDTH-1){ + m++; + n = 0; + } + + line_buf[m][n++] = pix; + + if(m==3 && n==HORIZONTAL_PIXEL_WIDTH){ + code = (line_buf[0][0]<<7) + (line_buf[0][1]<<6) + + (line_buf[1][0]<<5) + (line_buf[1][1]<<4) + + (line_buf[2][0]<<3) + (line_buf[2][1]<<2) + + (line_buf[3][0]<<1) + (line_buf[3][1]); + + RLE:for(int j=2; j 14){ + symbol = ((rb << 12) + (code << 4) + zl); + que->push(symbol); + rb = 0; + zl = 0; + code = B; + } + else + zl += 1; + } + symbol = ((rb << 12) + (code << 4) + zl); + que->push(symbol); + + m=0; + n=0; +} + + return 0; +} + +void testbench::reset(int *v, int *vo, int *svote){ + for(int i=0; i<5; i++){ + v[i] = 0; + vo[i] = 0; + svote[i] = 0; + } + vo[5] = 0; + vo[6] = 0; + vo[7] = 0; +} +type_tb testbench::inter(int rb, int z, int theta, int rst, type_tb my_cos, type_tb my_sin){ + static type_tb step[180]={0}; + static type_tb row[180]={0}; + static type_tb col[180]={0}; + + if(!rst){ + col[theta] = 0; + if(theta < 90){ + row[theta] = 0; + } + else { + row[theta] = my_cos; + } + } + + if(!rb){ + col[theta] += step[theta]; + } + else{ + + col[theta] = row[theta]; + row[theta] += N*my_sin; + + } + + step[theta] = (z+1)*M*my_cos; + + return col[theta]; + +} + +int testbench::intra(int *vo, type_tb f, type_tb my_cos, type_tb my_sin){ + vo[0] = 0; + vo[1] = f+my_cos; + vo[2] = f+my_sin; + vo[3] = f+my_sin+my_cos; + vo[4] = f+2*my_sin; + vo[5] = f+2*my_sin+my_cos; + vo[6] = f+3*my_sin; + vo[7] = f+3*my_sin+my_cos; + return 0; +} + +int testbench::vote_c(int *code, int *vo, int *v){ + for(int i=0; i<8; i++){ + v[vo[i]] += code[i]; + } + return 0; +} + +int testbench::hough(int symbol, int *vote, type_tb *my_cos, type_tb *my_sin, int rst){ + int rb, c, zl; + int i; + type_tb f; + int code[8]={0}, vo[8]={0}, v[5]={0}, svote[5]={0}, t; + + type_tb tmp_cos, tmp_sin, i_f; + + rb = (symbol>>12)&0x01; + c = (symbol>>4)&0xff; + zl = symbol&0xf; + HOUGH:for(int theta=0; theta<180; theta++){ + if(theta < 90){ + t = theta; + tmp_sin = my_sin[t]; + tmp_cos = my_cos[t]; + + CODE:for(int k=0; k<8; k++) + code[7-k] = (c>>k)&0x01; + } + else{ + t = 180-theta; + tmp_sin = my_sin[t]; + tmp_cos = -1*my_cos[t]; + + for(int k=0; k<8; k+=2){ + code[k] = (c>>(6-k))&0x01; + code[k+1] = (c>>(7-k))&0x01; + } + } + + reset(v, vo, svote); + i_f = inter(rb, zl, theta, rst, tmp_cos, tmp_sin); + i = (int)i_f; + f = i_f - i; + intra(vo, f, tmp_cos, tmp_sin); + vote_c(code, vo, v); + + memcpy(svote, (const int*)&vote[theta*MAX_RHO+i], 5*sizeof(int)); + for(int k=0; k<5; k++){ + svote[k] += v[k]; + } + memcpy((int*)&vote[theta*MAX_RHO+i], (const int*)svote, 5*sizeof(int)); + } + + return 0; +} + +int testbench::top_tb(int *ins, int *vote, type_tb *my_cos, type_tb *my_sin){ + int pix, out; + int symbol, rst=0; + std::queue que; + rst = 0; + + for(int y=0; y + +typedef double type_tb; + +class testbench{ +public: + testbench(); + ~testbench(); + +int sobel5( + int,int,int,int,int, + int,int,int,int,int, + int,int,int,int,int, + int); +int dilate( + int,int,int,int,int, + int,int,int,int,int, + int,int,int,int,int, + int,int,int,int,int, + int,int,int,int,int); +int erode( + int,int,int,int,int, + int,int,int,int,int, + int,int,int,int,int, + int,int,int,int,int, + int,int,int,int,int); + + +int im_top(int, int ); + +int rle(int, std::queue *); + +void reset(int *, int *, int*); +type_tb inter(int rb, int z, int theta, int rst, type_tb my_cos, type_tb my_sin); +int intra(int *vo, type_tb f, type_tb my_cos, type_tb my_sin); +int vote_c(int *code, int *vo, int *v); + + +int hough(int, int *, type_tb *, type_tb *, int); + +int top_tb(int *, int *, type_tb *, type_tb *); + + +}; +#endif diff --git a/test/whole_tb_ln.cpp b/test/whole_tb_ln.cpp index fd97193..5be0864 100644 --- a/test/whole_tb_ln.cpp +++ b/test/whole_tb_ln.cpp @@ -1,95 +1,127 @@ #include "sub.h" #include +#include "sys_tb.h" int top(int *, volatile int *, type_t *, type_t *); + int main() { FILE *fbmpr; unsigned char info[54]; - int *rd_bmp; + int rd_bmp[307200]; int width, height; int blue, green, red; int i, j; - int vote[180*MAX_RHO]; - type_t co[180], si[180]; - float rad = 0.0, theta=180.0; + int vote[144000], vote_tb[144000]; + type_t co[91], si[91]; + type_tb co_tb[91], si_tb[91]; + float rad = 0.0, theta_m=180.0; -if ((fbmpr = fopen("opencountry_land298.bmp", "rb")) == NULL){ +if ((fbmpr = fopen("city06.bmp", "rb")) == NULL){ fprintf(stderr, "Can't open image by binary read mode\n"); exit(1); } - fread(info, sizeof(unsigned char), 54, fbmpr); - - width = *(int*)&info[18]; - height = *(int*)&info[22]; - - -#ifdef __SDSCC__ - if ((rd_bmp =(int *)sds_alloc(sizeof(int) * (width*height))) == NULL){ - fprintf(stderr, "Can't allocate rd_bmp memory by sds_alloc\n"); - exit(1); - } -#else - if ((rd_bmp =(int *)malloc(sizeof(int) * (width*height))) == NULL){ - fprintf(stderr, "Can't allocate rd_bmp memory by malloc\n"); - exit(1); - } -#endif +// fread(info, sizeof(unsigned char), 54, fbmpr); +// +// width = *(int*)&info[18]; +// height = *(int*)&info[22]; + width = 640; + height = 480; + +//#ifdef __SDSCC__ +// if ((rd_bmp =(int *)sds_alloc(sizeof(int) * (width*height))) == NULL){ +// fprintf(stderr, "Can't allocate rd_bmp memory by sds_alloc\n"); +// exit(1); +// } +//#else +// if ((rd_bmp =(int *)malloc(sizeof(int) * (width*height))) == NULL){ +// fprintf(stderr, "Can't allocate rd_bmp memory by malloc\n"); +// exit(1); +// } +//#endif for (int y=0; y max){ - max = vote[theta*MAX_RHO+r]; - t = theta; + if(vote[t*MAX_RHO+r] > max){ + max = vote[t*MAX_RHO+r]; + theta = t; rho = r; -// std::cout << "max " << std::dec << max << " theta "< max_tb){ + + max_tb = vote_tb[t*MAX_RHO+r]; + theta_tb = t; + rho_tb = r; + std::cout << max_tb << " " << theta_tb << " " << rho_tb << std::endl; } } } - std::cout << "theta is " << std::dec << t << " rho is " << rho << std::endl; + if(theta == theta_tb){ + if(rho == rho_tb){ + std::cout << "theta is " << std::dec << theta << " rho is " << rho << std::endl; + } + } + else{ + std::cout << theta << " " << rho << std::endl; + std::cout << theta_tb << " " << rho_tb << std::endl; + } -#ifdef __SDSCC__ - sds_free(rd_bmp); -#else - free(rd_bmp); -#endif +//#ifdef __SDSCC__ +// sds_free(rd_bmp); +//#else +// free(rd_bmp); +//#endif return 0; } -- GitLab