Sie sind auf Seite 1von 3

Atmega code

/**************************************************************************************
HEADER FILE
***************************************************************************************/
#include<avr/io.h>

/**************************************************************************************
VARIABLE DECLARATION
***************************************************************************************/
volatile char Rec_Data;

/**************************************************************************************
MAIN FUNCTION
***************************************************************************************/
int main()
{
DDRD = 0X02; /* PD0(RX)-I/P, PD1(TX)-O/P */
UCSRA = 0X00; /* Clears TXC & RXC Flag Bit */
UCSRB = 0X18; /* Transmission & Reception Enable (TXEN=1, RXEN=1) */
UCSRC = 0X86; /* URSEL=1,UMSEL=0,UCSZ1=1,UCSZ0=0 */
UBRRL = 103; /* Serial Baudrate=9600 */
UDR = '0'; /* Transmit a charcter */
while((UCSRA & 0X20)!=0X20); /* UDRE Flag Bit Check */

while(1)
{
while((UCSRA & 0X80)!=0X80); /* RXC is set when unread data is in receive buffer */
Rec_Data=UDR; /* Store the received character */
UDR = Rec_Data; /* Transmit the received character */
while((UCSRA & 0X20)!=0X20); /* Wait here till UDR is empty */
}
}

/**************************************************************************************
END
***************************************************************************************/

Matlab code to send data to proteus

s=serial('COM4','BaudRate',9600);
fopen(s);
fprintf(s,'3');fopen(s);
idn = fscanf(s);
fclose(s);
matlab code to take image analys it and get number of objects

%camList = webcamlist
cam = webcam(2)
%preview(cam);
img1 = snapshot(cam);
MV2=imresize(img1,[600 600]);
imwrite(MV2,'backgnd.png');
% Display the frame in a figure window.
%image(img);
clear cam;
image(img1);
pause(30);

for e=1:2
%camList = webcamlist
cam = webcam(2)
%preview(cam);
img = snapshot(cam);
image(img);
MV=imresize(img,[600 600]);
% Display the frame in a figure window.
%image(img);
clear cam
MV1 = imread('backgnd.png');
%MV=imresize(MV,[600 600]);
%MV1=imresize(MV1,[600 600]);

A = double(rgb2gray(MV));%convert to gray
B= double(rgb2gray(MV1));%convert 2nd image to gray
[height width] = size(A); %image size?
h1 = figure(1);
%Foreground Detection
thresh=11;
fr_diff = abs(A-B);
for j = 1:width
for k = 1:height
if (fr_diff(k,j)>thresh)
fg(k,j) = A(k,j);
else
fg(k,j) = 0;
end
end
end
subplot(2,2,1) , imagesc(MV), title (['Orignal Frame']);
subplot(2,2,2) , imshow(mat2gray(A)), title ('converted Frame');
subplot(2,2,3) , imshow(mat2gray(B)), title ('BACKGND Frame ');
sd=imadjust(fg);% adjust the image intensity values to the color map
level=graythresh(sd);
m=imnoise(sd,'gaussian',0,0.025);% apply Gaussian noise

k=wiener2(m,[5,5]);%filtering using Weiner filter


bw=im2bw(k,level);
bw2=imfill(bw,'holes');
bw3 = bwareaopen(bw2,5000);
labeled = bwlabel(bw3,8);
cc=bwconncomp(bw3)
Densityoftraffic = cc.NumObjects/(size(bw3,1)*size(bw3,2));
blobMeasurements = regionprops(labeled,'all');
numberofcars = size(blobMeasurements, 1);
subplot(2,2,4) , imagesc(labeled), title (['Foreground']);
hold off;
disp(numberofcars);% display number of cars
disp(Densityoftraffic);%display number of vehicle
pause(30)
end

Das könnte Ihnen auch gefallen