Académique Documents
Professionnel Documents
Culture Documents
WAQAS ALTAF
ZAFAR KHAN
FAHAD ALI KHAN
BCE-SP09-031
BCE-SP09-039
BCE-SP09-044
SPRING 2013
Department of Electrical Engineering
Acknowledgements
In the Name of ALLAH, the Most Kind and Most Merciful
We are grateful to the ALLAH Almighty who provides all the resources of every kind to us, so
that we make their proper use for the benefit of mankind. May He keep providing us with all the
resources, and the guidance to keep helping the humanity.
We would like to thank our parents who kept backing us up in all the times, both financially and
morally. We would also like to thank our supervisor Mr. Umair Ashiq for his guidance and
encouraging us to work hard and smart. We have found him very helpful while discussing the
optimization issues in this dissertation work. His critical comments on our work have certainly
made us think of new ideas and techniques in the fields of optimization and software simulation.
We are very thankful to all lab attendants who help us in the availability of labs for experiments.
Especially Mr. Saeed the lab attendant of VLSI lab, who cooperates with us very well.
Table of contents
1 INTRODUCTION............................................................................................................................. 6
1.1 BACKGROUND............................................................................................................................. 6
1.2 OVERVIEW OF IMPLEMENTATION ................................................................................................ 6
1.3 OBJECTIVES AND GOALS ............................................................................................................. 7
1.4 BLOCK DIAGRAM OF SYSTEM ...................................................................................................... 7
1.5 SCOPE OF THESIS ......................................................................................................................... 8
2 TECHNICAL APPROACHES ......................................................................................................... 9
2.1 VIDEO......................................................................................................................................... 9
2.2 FIELD PROGRAMMABLE GATE ARRAY (FPGA) ........................................................................... 9
2.2.1Spartan 3e............................................................................................................................. 9
2.3. IMAGE PROCESSING ..................................................................................................................... 10
2.3.1Edge detection.............................................................................................. 10
2.3.2 Hough Transform........................................................................................................ 10
2.4 Hardware Description Language............................................................................................ 11
2.4.1 Verilog...................................................................................................................... 11
2.4.2 VHDL.......................................................................................................... 11
2.5 User Constraint File................................................................................................................... 11
2.6 Xilinx ISE.11
2.7 Programming FPGA........................................................................................................... 12
2.8 FPGA Applications........................................................................................ 12
2.8.1 Video/Image Processing ................................................................................. 12
2.8.2 Control systems.................................................................................................................. 12
2.8.3 Embedded systems............................................................................................................ 12
..............................................................
List of Figures
Figure 2:1 Spartan 3e Board Photo .10
Introduction
1.1 Background
With the increase in population traffic also increases. But the implemented systems are still old
style .Which result in frequent congestions .Traffic is increasing day by day so we have to cope
with the congestion problem .implemented systems include timer based system, and in some
modern countries sensor based system are implemented .It is clear that timer based systems are
poor because whatever condition is they respond according to timer timings , in simple if one
route is empty and other is full, system will generate signals according to timer ,not according to
conditions. Other is sensor based system it is good but it is very expensive and complex need a lot
of maintenance .so we come with the currently researched methodology .using some image
processing techniques we can find congestion so generate signals according to current traffic
conditions( congested are not).
We have first made its software than try to implement it on fpga .Means in first part we
implemented over system in pc (matlab) than on fpga (Spartan 3e)
So over all system consist of video camera , Pc , Fpga later we will discuss some other
components and their usage.
2 TECHNICAL APPROACHES
2.1 Video
The process of electronically capturing, storing, transmitting and reconstructing a pattern of still
images that representing flow in motion.
2.2.1 Spartan 3e
The Spartan 3E Starter Board provides a powerful and highly advanced self-contained
development platform for designs targeting the Spartan 3E FPGA from Xilinx. It features a 500K
gate Spartan 3E FPGA with a 32 bit RISC processor and DDR interfaces.
The board also features a Xilinx Platform Flash, USB and JTAG parallel programming interfaces
with numerous FPGA configuration options via the onboard Intel Strata Flash and ST
Microelectronics Serial Flash. The board is fully compatible with all versions of the Xilinx ISE
tools including the free Web Pack. The board ships with a power supply and USB cable for
programming so designs can be implemented immediately with no hidden costs. The Spartan 3E
Starter board is also compatible with the MicroBlaze Embedded Development Kit (EDK) and
Pico Blaze from Xilinx.
2.4.1 Verilog
Verilog is called the Hardware description language, its a textual format foe implement a design
and then check out the simulations via test bench. Xilinx is used as an editor; we can implement
our design by using Verilog Instructions.
Verilog HDL is an IEEE standard-number 1364.
Its first version was published in 1995
A revised version came in 2005
IEE STD 1364 also defines the programming language interface (PLI).
2.4.2 VHDL
VHDL is also called the hardware description language and can be used to model a digital and
electronic system design. Its stands for VHSIC (very high speed integrated circuits) hardware
description language. VHDL can describe the behavioral, structural and timing of design.
3.2.2 Pre-processing
The image is converted from RGB to grey scale. The noise is removed and finally the edges are
detected.
>> Algorithm
>>Algorithm 2
3.2.5 Line detection
Lines are detected using Hough transform.
(Below step is for both algorithms)
3.2.6 Result
Finally result is displayed
3.3 Pre-processing
It has two main steps
(1) RGB to gray conversion.
(2) Canny edge detection
A block diagram of the Canny edge detection algorithm is shown in Figure 2.1. The input to the
detector can be either a color image or a grayscale image. The output is an image
containing only those edges that have been detected.
In (2.1), sigma is the standard deviation of the Gaussian filter, which describes the narrowness of
the peaked function, and x and y are spatial coordinates.
An example of the conversion of (2.1) to a 2-dimensional 5x5 discrete Gaussian filter
function is shown in equation (2.2). The function is obtained for sigma = 1.4 by substituting
integer values for x and y and renormalizing [8].
A is the 2-dimensional array of input pixel values and B is an output image. The
process of smoothing an image using an MxM block filter yields an image in which each
pixel value is a weighted average of the surrounding pixel values, with the pixel value at the
center weighted much more strongly than those at nearby points.
Image smoothing is done primarily to suppress noise and to get a continuous edge
contour during the non-maximum suppression process. The output thus obtained is a blurred
intermediate image. This blurred image is used by the next block to calculate the strength and
direction of the edges.
convolved with a 3x3 Sobel operator [1]. The Sobel operator is a discrete differential
operator that generates a gradient image. Horizontal and vertical Sobel operators that are
used to calculate the horizontal and vertical gradients, respectively
3.3.2.3 Thresholding
Thresholding is the last stage in canny edge detection, which is used
to eliminate spurious points and non-edge pixels from the results of non-maximum
Suppression. The input image for thresholding has gone through Image
Smoothing, Calculating edge strength and edge pixel, and the Non-maximum suppression
Stage to obtain thin edges in the image. Results of this stage should give us only the valid
Edges in the given image, which is performed by using the two threshold values, T1 (high) and
T2 (low), for the edge strength of the pixel of the image. Edge strength which is greater than T1 is
considered as a definite edge. Edge strength which is less than T2 is set to zero. The pixel with
edge strength between the thresholds T1 and T2 is considered only if there is a path from this
pixel to a pixel with edge strength above T1. The path must be entirely through pixels with edge
strength of at least T2. This process reduces the probability of streaking.
As the edge strength is dependent on the intensity of the pixel of the image,
thresholds T1 and T2 also depend on the intensity of the pixel of the image. Hence, the
thresholds T1 and T2 are calculated by the Canny edge detectors using adaptive algorithms, Or
we can set them by certain tests.
Thus all the edges in an image are detected using the canny edge detection.
The figure show the image passing through canny edge detection block
%Code
>> g = 125;
for k = 49 : 115;
p = 1;
while p < g;
i1 (k , p) = 0;
p = p + 1;
end
g = g - 2;
end
inc = 200;
g = 300;
for k = 49 : 130;
p = inc;
while p < g;
i1 ( k , p) = 0;
p = p + 1;
end
inc = inc + 1;
end
After applying this algorithm to real time image results are below
peaks = houghpeaks(H,50,'Threshold',30);
figure, imshow(G,[]), hold on
lines = Houghlines (E,theta,rho,peaks ,'FillGap',5,'MinLength',15);
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot (xy(:,1),xy(:,2),'Lin eWidth',1,'Color','r');
end
3.6 Result
We have total number of ones stored in variable. Take its percentage.
Now we have to set threshold value for congestion. After random experiments we choose
2.689.Any value above this will be considered as congestion and vice versa.
Matlab code for area detection is below
>>
hold on
if(percnt_o<=2.689)
text(10,10,strcat('\color{green}NO Conjestion Found:'))
else
hold on
end
(2)
(3)
(4)
(5)
(7)
(8)
(9)
(10)
(11)
(12)
(13)
(14)
(15)
(16)
(17)
(18)
(19)
(20)
(21)
(22)
(23)
As we have not finish with the fpga implementation here is what we have tried.
Explained in figure below.
4.2 Limitations
The image/frame should not blur, the image must be clear.
The algorithm fails to detect the traffic congestion if there is dark or very foggy condition.
Camera screen must be cleaned weekly.
Camera quality and positions are very important (for different cameras we have to set threshold
point accordingly).
5 References
[1] R. C. Gonzalez and R. E. Woods, Digital Image Processing Second Edition[M].
Upper Saddle River, NJ: Pearson Education Inc., 2002.
[2] J. Canny, A computational approach to edge detection, IEEE Trans. Pattern Anal.
and Mach. Intell., vol. 8, pp. 679-714, Nov. 1986.
[3] C. Sun and P. Vallotton, Fast linear feature detection using multiple directional
nonmaximum suppression, in Proc. Int. Conf. Pattern Recognition, Hong Kong, China,
2006, pp. 288-291.
[4] G. M. Schuster and A. K. Katsaggelos, Robust circle detection using a weighted
mseestimator, in Proc. Inter. Conf. Image Processing, Singapore, 2004, pp. 2111-2114
All data regarding Hough transform was taken from
PROF. WILLIAM HOFF
EGGN 512 computer vision
(COLORODO SCHOOL OF MINES ENGINEERING DIVISION)
APPENDIX A
library IEEE,STD;
use IEEE.Std_Logic_1164.all;
use IEEE.Numeric_Std.all;
--**-package UART_Def is
------------------------------------------------------------------------------ Converts unsigned Std_LOGIC_Vector to Integer, leftmost bit is MSB
-- Error message for unknowns (U, X, W, Z, -), converted to 0
-- Verifies whether vector is too long (> 16 bits)
----------------------------------------------------------------------------function ToInteger (
Invector : in Unsigned(3 downto 0))
return Integer;
end UART_Def; --==================== End of package header
======================-package body UART_Def is
function ToInteger (
InVector : in Unsigned(3 downto 0))
return Integer is
constant HeaderMsg : String := "To_Integer:";
constant MsgSeverity : Severity_Level := Warning;
variable Value : Integer := 0;
begin
for i in 0 to 3 loop
if (InVector(i) = '1') then
Value := Value + (2**I);
end if;
end loop;
return Value;
end ToInteger;
end UART_Def; --================ End of package body ================--=====================================================================
======---- S Y N T H E Z I A B L E miniUART C O R E
--- Design units : miniUART core for the OCRP-1
--- File name : TxUnit.vhd
--- Purpose : Implements an miniUART device for communication purposes
-- between the OR1K processor and the Host computer through
-- an RS-232 communication protocol.
--- Library : uart_lib.vhd
--
-- Dependencies : IEEE.Std_Logic_1164
--=====================================================================
======--------------------------------------------------------------------------------------------------------------------------------------------------------------- Description :
-------------------------------------------------------------------------------- Entity for the Tx Unit -------------------------------------------------------------------------------library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library work;
use work.Uart_Def.all;
-------------------------------------------------------------------------------- Transmitter unit
------------------------------------------------------------------------------entity TxUnit is
port (
Clk : in Std_Logic; -- Clock signal
Reset : in Std_Logic; -- Reset input
Enable : in Std_Logic; -- Enable input
Load : in Std_Logic; -- Load transmit data
TxD : out Std_Logic; -- RS-232 data output
TRegE : out Std_Logic; -- Tx register empty
TBufE : out Std_Logic; -- Tx buffer empty
DataO : in Std_Logic_Vector(7 downto 0));
end entity; --================== End of entity ==============================--------------------------------------------------------------------------------- Architecture for TxUnit
------------------------------------------------------------------------------architecture Behaviour of TxUnit is
------------------------------------------------------------------------------ Signals
----------------------------------------------------------------------------signal TBuff : Std_Logic_Vector(7 downto 0); -- transmit buffer
signal TReg : Std_Logic_Vector(7 downto 0); -- transmit register
signal BitCnt : Unsigned(3 downto 0); -- bit counter
signal tmpTRegE : Std_Logic; -signal tmpTBufE : Std_Logic; -begin
------------------------------------------------------------------------------ Implements the Tx unit
----------------------------------------------------------------------------process(Clk,Reset,Enable,Load,DataO,TBuff,TReg,tmpTRegE,tmpTBufE)
variable tmp_TRegE : Std_Logic;
constant CntOne : Unsigned(3 downto 0):="0001";
begin
if Rising_Edge(Clk) then
if Reset = '0' then
tmpTRegE <= '1'; tmpTBufE <= '1'; TxD <= '1'; BitCnt <= "0000"; elsif Load = '1' then TBuff <=
DataO; tmpTBufE <= '0'; elsif Enable = '1' then if ( tmpTBufE = '0') and (tmpTRegE = '1') then
TReg <= TBuff; tmpTRegE <= '0'; -- tmp_TRegE := '0'; tmpTBufE <= '1'; -- else -tmp_TRegE := tmpTRegE; end if; if tmpTRegE = '0' then case BitCnt is when "0000" =>
TxD <= '0'; BitCnt <= BitCnt + CntOne; when "0001" "0010" "0011" "0100" "0101" "0110"
"0111" "1000" =>
TxD <= TReg(0); TReg <= '1' & TReg(7 downto 1); BitCnt <= BitCnt + CntOne; when "1001"
=>
TxD <= '1'; TReg <= '1' & TReg(7 downto 1); BitCnt <= "0000"; tmpTRegE <= '1'; when others
=> null;
end case;
end if;
end if;
end if;
end process;
TRegE <= tmpTRegE; TBufE <= tmpTBufE; end Behaviour; --=================== End of
architecture ====================--=====================================================================
======---- S Y N T H E Z I A B L E miniUART C O R E
-- Design units : miniUART core for the OCRP-1
--- File name : RxUnit.vhd
--- Purpose : Implements an miniUART device for communication purposes
-- between the OR1K processor and the Host computer through
-- an RS-232 communication protocol.
--- Library : uart_lib.vhd
--- Dependencies : IEEE.Std_Logic_1164
--- Description : Implements the receive unit of the miniUART core. Samples
-- 16 times the RxD line and retain the value in the middle of
-- the time interval.
-------------------------------------------------------------------------------- Entity for Receive Unit - 9600 baudrate -------------------------------------------------------------------------------library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library work;
use work.UART_Def.all;
-------------------------------------------------------------------------------
-- Receive unit
------------------------------------------------------------------------------entity RxUnit is
port (
Clk : in Std_Logic; -- system clock signal
Reset : in Std_Logic; -- Reset input
Enable : in Std_Logic; -- Enable input
RxD : in Std_Logic; -- RS-232 data input
RD : in Std_Logic; -- Read data signal
FErr : out Std_Logic; -- Status signal
OErr : out Std_Logic; -- Status signal
DRdy : out Std_Logic; -- Status signal
DataIn : out Std_Logic_Vector(7 downto 0));
end entity; --================== End of entity ==============================--------------------------------------------------------------------------------- Architecture for receive Unit
------------------------------------------------------------------------------architecture Behaviour of RxUnit is
------------------------------------------------------------------------------ Signals
----------------------------------------------------------------------------signal Start : Std_Logic; -- Syncro signal
signal tmpRxD : Std_Logic; -- RxD buffer
signal tmpDRdy : Std_Logic; -- Data ready buffer
signal outErr : Std_Logic; -signal frameErr : Std_Logic; -signal BitCnt : Unsigned(3 downto 0); -signal SampleCnt : Unsigned(3 downto 0); -- samples on one bit counter
signal ShtReg : Std_Logic_Vector(7 downto 0); -signal DOut : Std_Logic_Vector(7 downto 0); -begin
---------------------------------------------------------------------- Receiver process
--------------------------------------------------------------------RcvProc : process(Clk,Reset,Enable,RxD)
variable tmpBitCnt : Integer range 0 to 15;
variable tmpSampleCnt : Integer range 0 to 15;
constant CntOne : Unsigned(3 downto 0):="0001";
begin
if Rising_Edge(Clk) then
tmpBitCnt := ToInteger(BitCnt);
tmpSampleCnt := ToInteger(SampleCnt);
if Reset = '0' then
BitCnt <= "0000";
SampleCnt <= "0000";
Start <= '0';
tmpDRdy <= '0';
frameErr <= '0';
outErr <= '0';
ShtReg <= "00000000"; --
end if;
end if;
end process;
DRdy <= tmpDRdy;
DataIn <= DOut;
FErr <= frameErr;
OErr <= outErr;
end Behaviour; --==================== End of architecture ====================--
APPENDIX B
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
USE ieee.std_logic_arith.all;
entity usrf_ram is
GENERIC (add_w: INTEGER :=4;
data_w: INTEGER :=8 );
port (
clk_WR : in STD_LOGIC;
clk_RD : in STD_LOGIC;
rst : in STD_LOGIC;
rc_srs : in STD_LOGIC:='0';
WR
: in STD_LOGIC;
RD
: in STD_LOGIC;
D
: in STD_LOGIC_VECTOR (data_w-1 downto 0);
Q
: out STD_LOGIC_VECTOR (data_w-1 downto 0);
empty : out STD_LOGIC;
q_fu : out STD_LOGIC;
h_fu : out STD_LOGIC;
a_fu : out STD_LOGIC;
full : out STD_LOGIC);
end entity;
architecture a of usrf_ram is
component binary2gray IS
GENERIC (size: INTEGER := 8);
PORT(
B : IN STD_LOGIC_VECTOR(size-1 DOWNTO 0);
G : out STD_LOGIC_VECTOR(size-1 DOWNTO 0)
);
end component;
component gray2binary IS
GENERIC (size: INTEGER := 8);
PORT(
end if;
end process;
full <= mi_ifull;
mi_ifull <= '0' when (mi_iempty = '1')
'0' when (mi_add_RD_WS /= mi_add_WR_GC) else
'1';
mi_mi_add_RD_CE <= '0' when (mi_iempty = '1') else
'0' when (RD = '0') else
'1';
n_mi_add_RD <= mi_add_RD + "01";
U2 : binary2gray
generic map (size => add_w+1)
port map(
B => n_mi_add_RD,
G => imi_add_RD_GC
);
iimi_add_RD_GCwc <= (not n_mi_add_RD(add_w)) & n_mi_add_RD(add_w-1
downto 0);
U3 : binary2gray
generic map (size => add_w+1)
port map(
B => iimi_add_RD_GCwc,
G => imi_add_RD_GCwc
);
process (clk_RD,rst)
begin
if (rst = '1') then
mi_add_RD <= (others => '0');
mi_add_WR_RS <= (others => '0');
mi_add_RD_GC <= (others => '0');
mi_add_RD_GCwc(add_w downto add_w-1) <= "11";
mi_add_RD_GCwc(add_w-2 downto 0) <= (others => '0');
dmi_iempty <= '1';
elsif (rising_edge(clk_RD)) then
mi_add_WR_RS <= mi_add_WR_GC;
dmi_iempty <= mi_iempty;
if (srst_r = '1') then
mi_add_RD <= (others => '0');
process (clk_WR,rst)
begin
if (rst = '1') then
srs_w <= '0';
isrs_r <= '0';
elsif (rising_edge(clk_WR)) then
srs_w <= isrs_w;
if (srs_w = '1') then
isrs_r <= '1';
elsif (srs_w = '0') then
isrs_r <= '0';
end if;
end if;
end process;
process (clk_RD,rst)
begin
if (rst = '1') then
srst_r <= '0';
isrs_w <= '0';
elsif (rising_edge(clk_RD)) then
srst_r <= rc_srs;
if (rc_srs = '1') then
isrs_w <= '1';
elsif (isrs_r = '1') then
isrs_w <= '0';
end if;
end if;
end process;
end architecture;
APPENDIX C
library ieee,xilinxcorelib,unisim;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
use ieee.std_logic_1164.all;
use ieee.img_edge.all;
entity edge is
end edge;
architecture IMG_ARCHITECTURE of edge is
component detection
port(
clk : in std_logic;
reset : in std_logic;
imgEdge : in std_logic;
no_edge : in std_logic_vector(1 downto 0);
Mono : in std_logic;
ImgColumns : in std_logic_vector(9 downto 0);
ImgRows : in std_logic_vector(8 downto 0);
edge_formating : out std_logic;
ProcessRGB : in std_logic;
ProcessingRGB : out std_logic;
imgRed : in std_logic_vector(7 downto 0);
imgGreen : in std_logic_vector(7 downto 0);
imgBlue : in std_logic_vector(7 downto 0);
address: out std_logic_VECTOR(15 downto 0);
datain: out std_logic_VECTOR(7 downto 0);
we_tool: out std_logic);
end component;
signal clk : std_logic;
signal reset : std_logic;
signal imgEdge : std_logic;
signal no_edge : std_logic_vector(1 downto 0);
signal Mono : std_logic;
signal ImgColumns : std_logic_vector(9 downto 0);
signal ImgRows : std_logic_vector(8 downto 0);
signal ProcessRGB : std_logic;
signal imgRed : std_logic_vector(7 downto 0);
signal imgGreen : std_logic_vector(7 downto 0);
signal imgBlue : std_logic_vector(7 downto 0);
signal edge_formating : std_logic;
signal ProcessingRGB : std_logic;
signal address : std_logic_vector(15 downto 0);
signal datain : std_logic_vector(7 downto 0);
signal we_tool : std_logic;
type ByteT is
(c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17,c18,c19,c20,c21,c22,c23,c24,c25
,c26,c27,c28,c29,c30,c31,c32,c33,c34,c35,c36,c37,c38,c39,c40,c41,c42,c43,c44,c45,c46,c47,c48,
c49,c50,c51,c52,c53,c54,c55,c56,c57,c58,c59,c60,c61,c62,c63,c64,c65,c66,c67,c68,c69,c70,c71,
c72,c73,c74,c75,c76,c77,c78,c79,c80,c81,c82,c83,c84,c85,c86,c87,c88,c89,c90,c91,c92,c93,c94,
c95,c96,c97,c98,c99,c100,c101,c102,c103,c104,c105,c106,c107,c108,c109,c110,c111,c112,c113,
c114,c115,c116,c117,c118,c119,c120,c121,c122,c123,c124,c125,c126,c127,c128,c129,c130,c131,
c132,c133,c134,c135,c136,c137,c138,c139,c140,c141,c142,c143,c144,c145,c146,c147,c148,c149
,c150,c151,c152,c153,c154,c155,c156,c157,c158,c159,c160,c161,c162,c163,c164,c165,c166,c16
7,c168,c169,c170,c171,c172,c173,c174,c175,c176,c177,c178,c179,c180,c181,c182,c183,c184,c1
85,c186,c187,c188,c189,c190,c191,c192,c193,c194,c195,c196,c197,c198,c199,c200,c201,c202,c
203,c204,c205,c206,c207,c208,c209,c210,c211,c212,c213,c214,c215,c216,c217,c218,c219,c220,
c221,c222,c223,c224,c225,c226,c227,c228,c229,c230,c231,c232,c233,c234,c235,c236,c237,c238
,c239,c240,c241,c242,c243,c244,c245,c246,c247,c248,c249,c250,c251,c252,c253,c254,c255);
subtype Byte is ByteT;
type ByteFileType is file of Byte;
file infile : ByteFileType open read_mode is "1.tif";
end if;
end if;
end process Data;
end IMG_ARCHITECTURE;
configuration TESTBENCH_FOR_gs of edge is
for IMG_ARCHITECTURE
for UUT : compressor
use entity work.compressor(jpg);
end for;
end for;
end TESTBENCH_FOR_gs;