URL
https://opencores.org/ocsvn/linkruncca/linkruncca/trunk
Subversion Repositories linkruncca
Compare Revisions
- This comparison shows the changes necessary to convert path
/linkruncca/trunk
- from Rev 5 to Rev 6
- ↔ Reverse comparison
Rev 5 → Rev 6
/src/cca.vh
1,43 → 1,2
/************************************** |
Author: J.W Tang |
Email: jaytang1987@hotmail.com |
Module: cca.vh |
Date: 2016-04-24 |
|
Copyright (C) 2016 J.W. Tang |
---------------------------- |
This file is part of LinkRunCCA. |
|
LinkRunCCA is free software: you can redistribute it and/or modify |
it under the terms of the GNU Lesser General Public License as |
published by the Free Software Foundation, either version 3 of |
the License, or (at your option) any later version. |
|
LinkRunCCA is distributed in the hope that it will be useful, |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
GNU Lesser General Public License for more details. |
|
You should have received a copy of the GNU Lesser General Public License |
along with LinkRunCCA. If not, see <http://www.gnu.org/licenses/>. |
|
By using LinkRunCCA in any or associated publication, |
you agree to cite it as: |
Tang, J. W., et al. "A linked list run-length-based single-pass |
connected component analysis for real-time embedded hardware." |
Journal of Real-Time Image Processing: 1-19. 2016. |
doi:10.1007/s11554-016-0590-2. |
|
***************************************/ |
|
`ifndef cca_vh |
`define cca_vh |
parameter imwidth=512; |
parameter imheight=512; |
|
parameter x_bit=$clog2(imwidth); |
parameter y_bit=$clog2(imheight); |
parameter address_bit=x_bit-1; |
parameter data_bit=2*(x_bit+y_bit); |
parameter latency=4; |
`endif |
parameter imwidth=512; |
parameter imheight=512; |
/sim/CCA.sh
0,0 → 1,41
#!/bin/sh |
|
img="testimage/mandrill.pgm" |
|
|
# image exist? |
if [ ! -f $img ]; |
then |
echo $img not found! |
exit |
fi |
|
# get image size and update header/parameters for simulation and verilog files |
w=`identify -format '%w' $img` |
h=`identify -format '%h' $img` |
echo "char fname[]=\"$img\";" > sim.h |
echo "unsigned int imwidth=$w;" >> sim.h |
echo "unsigned int imheight=$h;" >> sim.h |
echo "parameter imwidth=$w;" > ../src/cca.vh |
echo "parameter imheight=$h;" >> ../src/cca.vh |
#----------------------------------------------- |
|
# verilator compilation |
if [ -d "obj_dir" ]; |
then |
rm -rf obj_dir |
fi |
verilator -Wall --cc "../src/LinkRunCCA.v" --exe sim_main.cpp -I"../src" |
cd obj_dir |
make -j -f VLinkRunCCA.mk "VLinkRunCCA" |
cd .. |
#----------------------------------------------- |
|
# Simulation |
echo |
echo "****************************Simulation Start****************************" |
obj_dir/VLinkRunCCA |
echo |
echo "****************************Simulation Ended****************************" |
#----------------------------------------------- |
|
/sim/box_out.pgm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
sim/box_out.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/testimage/18768.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sim/testimage/18768.pgm
===================================================================
--- sim/testimage/18768.pgm (nonexistent)
+++ sim/testimage/18768.pgm (revision 6)
sim/testimage/18768.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/testimage/lenna.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sim/testimage/lenna.pgm
===================================================================
--- sim/testimage/lenna.pgm (nonexistent)
+++ sim/testimage/lenna.pgm (revision 6)
sim/testimage/lenna.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/testimage/4283.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sim/testimage/4283.pgm
===================================================================
--- sim/testimage/4283.pgm (nonexistent)
+++ sim/testimage/4283.pgm (revision 6)
sim/testimage/4283.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/testimage/4544.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sim/testimage/4544.pgm
===================================================================
--- sim/testimage/4544.pgm (nonexistent)
+++ sim/testimage/4544.pgm (revision 6)
sim/testimage/4544.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/testimage/test2.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sim/testimage/test2.pgm
===================================================================
--- sim/testimage/test2.pgm (nonexistent)
+++ sim/testimage/test2.pgm (revision 6)
sim/testimage/test2.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/testimage/2.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sim/testimage/2.pgm
===================================================================
--- sim/testimage/2.pgm (nonexistent)
+++ sim/testimage/2.pgm (revision 6)
sim/testimage/2.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/testimage/3.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sim/testimage/3.pgm
===================================================================
--- sim/testimage/3.pgm (nonexistent)
+++ sim/testimage/3.pgm (revision 6)
sim/testimage/3.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/testimage/mandrill.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sim/testimage/mandrill.pgm
===================================================================
--- sim/testimage/mandrill.pgm (nonexistent)
+++ sim/testimage/mandrill.pgm (revision 6)
sim/testimage/mandrill.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/testimage/4.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sim/testimage/4.pgm
===================================================================
--- sim/testimage/4.pgm (nonexistent)
+++ sim/testimage/4.pgm (revision 6)
sim/testimage/4.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/testimage/4376.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sim/testimage/4376.pgm
===================================================================
--- sim/testimage/4376.pgm (nonexistent)
+++ sim/testimage/4376.pgm (revision 6)
sim/testimage/4376.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/testimage/170.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sim/testimage/170.pgm
===================================================================
--- sim/testimage/170.pgm (nonexistent)
+++ sim/testimage/170.pgm (revision 6)
sim/testimage/170.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/testimage/180.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sim/testimage/180.pgm
===================================================================
--- sim/testimage/180.pgm (nonexistent)
+++ sim/testimage/180.pgm (revision 6)
sim/testimage/180.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/testimage/173.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sim/testimage/173.pgm
===================================================================
--- sim/testimage/173.pgm (nonexistent)
+++ sim/testimage/173.pgm (revision 6)
sim/testimage/173.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/testimage/carsandapcs.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sim/testimage/carsandapcs.pgm
===================================================================
--- sim/testimage/carsandapcs.pgm (nonexistent)
+++ sim/testimage/carsandapcs.pgm (revision 6)
sim/testimage/carsandapcs.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/testimage/18562.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sim/testimage/18562.pgm
===================================================================
--- sim/testimage/18562.pgm (nonexistent)
+++ sim/testimage/18562.pgm (revision 6)
sim/testimage/18562.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/testimage/18609.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sim/testimage/18609.pgm
===================================================================
--- sim/testimage/18609.pgm (nonexistent)
+++ sim/testimage/18609.pgm (revision 6)
sim/testimage/18609.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/testimage/jellybeans.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sim/testimage/jellybeans.pgm
===================================================================
--- sim/testimage/jellybeans.pgm (nonexistent)
+++ sim/testimage/jellybeans.pgm (revision 6)
sim/testimage/jellybeans.pgm
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sim/ppm.h
===================================================================
--- sim/ppm.h (nonexistent)
+++ sim/ppm.h (revision 6)
@@ -0,0 +1,75 @@
+#ifndef ppm_h
+#define ppm_h
+
+int writePPM(char* filename,unsigned char* im,unsigned long width,unsigned long height,int colour)
+{
+ int i,j;
+ FILE *output;
+ output=fopen(filename,"w");
+ if(output==NULL){printf("File not found!");return 1;}
+ if(colour)
+ {
+ fprintf(output,"P6\n%lu %lu\n255\n",width,height);
+ for(i=0;i image format.
+It reads an PGM input image and outputs a bounding boxes image "box_out.pgm".
+
+Simulation can be initiated by running simulation script in terminal window:
+ sh CCA.sh
+
+Test image can be specified in the "CCA.sh" script:
+ img="testimage/4283.pgm"
Index: sim/v2c.sh
===================================================================
--- sim/v2c.sh (nonexistent)
+++ sim/v2c.sh (revision 6)
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+starttime=$(date +%s)
+
+if test `ls -1 $1 | wc -l` -ne 1
+then printf "shtask: Input .v file error.\nusage:sh v2c \n"
+ exit
+fi
+
+fname="${1%%.*}"
+echo "input file:$fname"
+
+verilator -Wall --cc "$1" --exe sim_main.cpp
+cd obj_dir
+make -j -f V$fname.mk "V$fname"
+echo run with: obj_dir/V$fname
+
+endtime=$(date +%s)
+
+echo "Compile time : $(($endtime-$starttime))s"
+
+
Index: sim/CCLheader.c
===================================================================
--- sim/CCLheader.c (nonexistent)
+++ sim/CCLheader.c (revision 6)
@@ -0,0 +1,75 @@
+#include
+#include
+
+int main(int argc,char** argv)
+{
+ if(argc!=2){printf("usage: CCLheader \n"); return 1; }
+
+int latency=4; //latency to offset counter x, 4 if holes filling, else 3
+unsigned int imwidth;
+unsigned int imheight;
+
+ char fname[50];//="testimage/mandrill.ppm";
+ sprintf(fname,"testimage/%s",argv[1]);
+ printf("Input image: %s\n",fname);
+
+//////////////////////get image size from header///////////////////////////////
+ unsigned int i,j,maxPixValue,colour;
+ FILE *input;
+ char buffer;
+ input=fopen(fname,"r");if(input==NULL){printf("Image not found!\n");return 1;}
+
+ if(buffer=fgetc(input)!='P')
+ {printf("Wrong image format!\n");return 1;}
+ colour=fgetc(input)-'0'-5;
+
+ while(!isdigit(buffer=fgetc(input)))
+ if(buffer=='#') //skip comment
+ while(fgetc(input)!='\n');
+ imwidth=buffer-'0';
+ while(isdigit(buffer=fgetc(input)))
+ imwidth=imwidth*10+buffer-'0'; //imwidth
+
+ while(!isdigit(buffer=fgetc(input)))
+ if(buffer=='#') //skip comment
+ while(fgetc(input)!='\n');
+ imheight=buffer-'0';
+ while(isdigit(buffer=fgetc(input)))
+ imheight=imheight*10+buffer-'0'; //imheight
+ fclose(input);
+//////////////////////get image size from header (END)//////////////////////////
+
+int x_bit=(int)ceil(log2(imwidth));
+int y_bit=(int)ceil(log2(imheight));
+int address_bit=(int)ceil(log2(imwidth/2));
+int data_bit=2*(x_bit+y_bit);
+
+ FILE *foutput;
+ if((foutput=fopen("CCL.vh","w"))==NULL){printf("File not open.\n");return 1;}
+ fprintf(foutput,"`ifndef CCL_vh\n`define CCL_vh\n");
+ fprintf(foutput,"\tparameter imwidth=%d;\n",imwidth);
+ fprintf(foutput,"\tparameter imheight=%d;\n",imheight);
+ fprintf(foutput,"\tparameter x_bit=%d;\n",x_bit);
+ fprintf(foutput,"\tparameter y_bit=%d;\n",y_bit);
+ fprintf(foutput,"\tparameter address_bit=%d;\n",address_bit);
+ fprintf(foutput,"\tparameter data_bit=%d;\n",data_bit);
+ fprintf(foutput,"\tparameter latency=%d;\n",latency);
+ fprintf(foutput,"`endif");
+ fclose(foutput);
+
+ if((foutput=fopen("CCL.h","w"))==NULL){printf("File not open.\n");return 1;}
+ fprintf(foutput,"#ifndef CCL_h\n#define CCL_h\n");
+ fprintf(foutput,"\tchar fname[50]=\"%s\";\n",fname);
+ fprintf(foutput,"\tunsigned int imwidth=%d;\n",imwidth);
+ fprintf(foutput,"\tunsigned int imheight=%d;\n",imheight);
+ fprintf(foutput,"\tint x_bit=%d;\n",x_bit);
+ fprintf(foutput,"\tint y_bit=%d;\n",y_bit);
+ fprintf(foutput,"\tint address_bit=%d;\n",address_bit);
+ fprintf(foutput,"\tint data_bit=%d;\n",data_bit);
+ fprintf(foutput,"\tint latency=%d;\n",latency);
+ fprintf(foutput,"#endif");
+ fclose(foutput);
+
+ return 0;
+}
+
Index: sim/sim_main.cpp
===================================================================
--- sim/sim_main.cpp (nonexistent)
+++ sim/sim_main.cpp (revision 6)
@@ -0,0 +1,91 @@
+#include // Defines common routines
+#include "VLinkRunCCA.h" // From Verilator "Top.v"
+#include
+#include
+#include "sim.h"
+#include "ppm.h"
+
+VLinkRunCCA *top; // Instantiation of module
+unsigned int main_time = 0; // Current simulation time
+
+int x_bit=(int)ceil(log2(imwidth));
+int y_bit=(int)ceil(log2(imheight));
+int latency=4;
+
+int main(int argc, char** argv) {
+ clock_t time1,time2;
+ time1=clock();
+ Verilated::commandArgs(argc, argv); // Remember args
+ top = new VLinkRunCCA; // Create instance
+
+ FILE *finput,*foutput;
+ int i,j,object=0,minx,maxx,miny,maxy;
+ int m;int maskx=0,masky=0;
+ for(m=0;mclk = 0;
+ top->datavalid=0;
+ top->rst=1;
+ top->eval(); // Evaluate model
+ top->rst = 0; // Deassert reset
+
+ while (!Verilated::gotFinish())
+ {
+ if(cycle==imwidth*imheight+latency-1)break; //simulation end when all pixel are send + latency
+
+ top->datavalid=1;
+ if(cyclepix_in=im[cycle];
+ else top->pix_in=0;
+
+ top->clk = 1; // Toggle clock
+ top->eval(); // Evaluate model
+ top->clk = 0;
+ top->eval(); // Evaluate model
+
+ if(top->datavalid_out) //draw box and display output
+ {
+ object++;
+ box=top->box_out;
+ maxy=masky&(box);box=box>>y_bit;
+ miny=masky&(box);box=box>>y_bit;
+ maxx=maskx&(box);box=box>>x_bit;
+ minx=maskx&(box);
+ printf("minx: %-5umaxx: %-5uminy: %-5umaxy: %-5u ..produced at cycle %u\n",minx,maxx,miny,maxy,cycle); //Display
+
+ for(j=minx;j<=maxx;j++) //draw the box with pixel 2
+ { im[j+miny*imwidth]=2;im[j+maxy*imwidth]=2; }
+ for(j=miny;j<=maxy;j++)
+ { im[minx+j*imwidth]=2;im[maxx+j*imwidth]=2; }
+ }
+
+ cycle++;
+ }
+ top->final(); // Done simulating
+
+ printf("Total object: %d\nTotal Cycle: %u\n",object,cycle);
+
+ for(i=0;i