SlideShare a Scribd company logo
1 of 4
clear all ;close all;clc
pic1_prv=imread('street_crossing_0536-scaled.png');
pic1_cur=imread('street_crossing_0538-scaled.png'); %imread('MovingCar273.JPG');
pic2_prv=imread('street_crossing_0540-scaled.png');% imread('MovingCar274.JPG');
pic2_cur=imread('street_crossing_0544-scaled.png'); %imread('MovingCar275.JPG');
h=[1,1,1;1,1,1;1,1,1];
gh=h./9;
a=0.000001;
b=1-a;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pic1_prv_g=rgb2gray(pic1_prv);
pic1_cur_g=rgb2gray(pic1_cur);
pic1_prv_gf=imfilter(pic1_prv_g,gh);
pic1_cur_gf=imfilter(pic1_cur_g,gh);
pic1_B0=pic1_prv_gf;
pic1_I0=pic1_prv_gf;
pic1_I1=pic1_cur_gf;
pic1_B1=(b*pic1_B0)-(a*pic1_I1);
pic1_D1=pic1_I1-pic1_B0;
pic1_D1t= im2bw(pic1_D1,0.15);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pic2_prv_g=rgb2gray(pic2_prv);
pic2_cur_g=rgb2gray(pic2_cur);
pic2_prv_gf=imfilter(pic2_prv_g,gh);
pic2_cur_gf=imfilter(pic2_cur_g,gh);
pic2_B0=pic2_prv_gf;
pic2_I0=pic2_prv_gf;
pic2_I1=pic2_cur_gf;
pic2_B1=(b*pic2_B0)-(a*pic2_I1);
pic2_D1=pic2_I1-pic2_B0;
pic2_D1t= im2bw(pic2_D1,0.15);
%%%%%%%%%%%%%%%%%%%%%%%%%
%Section 2
%delete unwanted fake lights
%1{
[L_p1_hgt,N_p1_hgt]=bwlabel(pic1_D1t);
pic1_D1t_hgt = pic1_D1t;
if N_p1_hgt > 0
for i=1:N_p1_hgt,
[r_p1_hgt,c_p1_hgt]=find(L_p1_hgt==i);
lightheight=(max(r_p1_hgt));
%display(lightheight);
if ( lightheight <45)
pic1_D1t_hgt = bwareaopen(pic1_D1t,18);
%display(lightheight);
end
end
end
[L_p1_ar,N_p1_ar]=bwlabel(pic1_D1t_hgt);
pic1_D1t_ar = pic1_D1t_hgt;
if N_p1_ar > 0
for i=1:N_p1_ar,
[r_p1_ar,c_p1_ar]=find(L_p1_ar==i);
pic1_labelsize=size(c_p1_ar,1);
if (pic1_labelsize <30)
pic1_D1t_ar = bwareaopen(pic1_D1t_hgt,15);
end
end
end
pic1_D1t2 = pic1_D1t_ar;
%1}
%2{
[L_p2_hgt,N_p2_hgt]=bwlabel(pic2_D1t);
pic2_D1t_hgt = pic2_D1t;
if N_p2_hgt > 0
for i=1:N_p2_hgt,
[r_p2_hgt,c_p2_hgt]=find(L_p2_hgt==i);
lightheight=(max(r_p2_hgt));
%display(lightheight);
if ( lightheight <45)
pic2_D1t_hgt = bwareaopen(pic2_D1t,18);
%display(lightheight);
end
end
end
[L_p2_ar,N_p2_ar]=bwlabel(pic2_D1t_hgt);
pic2_D1t_ar = pic2_D1t_hgt;
if N_p2_ar > 0
for i=1:N_p2_ar,
[r_p2_ar,c_p2_ar]=find(L_p2_ar==i);
pic2_labelsize=size(c_p2_ar,1);
if (pic2_labelsize <30)
pic2_D1t_ar = bwareaopen(pic2_D1t_hgt,15);
end
end
end
pic2_D1t2 = pic2_D1t_ar;
%2}
%now all the small fake lights are removed
%Section 3
%display output after the threshold
%{
for debugging
figure; imshow (pic1_D1t);
figure; imshow (pic2_D1t);
figure; imshow (pic1_D1t2);
figure; imshow (pic2_D1t2);
%}
%Section 4
% the following commands will draw bounding box around the headlights
% and label them
%section 4a draw headlights
%section 4b draw car
pic1_back=pic1_B1;
pic1_cur=pic1_I1;
figure; imshow(pic1_I1);hold on;
[pic1_L,pic1_N]=bwlabel(pic1_D1t2);
[pic2_L,pic2_N]=bwlabel(pic2_D1t2);
%Section 4a: draw headlights
if pic1_N > 0
for i=1:2:pic1_N,
[pic1_r_lb1,pic1_c_lb1]=find(pic1_L==i);
[pic1_r_lb2,pic1_c_lb2]=find(pic1_L==i+1);
pic1_area_lb1=size(pic1_c_lb1,1);
pic1_area_lb2=size(pic1_c_lb2,1);
if ((pic1_area_lb1 > 10) && (pic1_area_lb2 > 10)) % && (area <50)) PLEASE
EDIT IN FINAL ROUND
pic1_ctop_lb1 =(min(pic1_c_lb1));
pic1_rtop_lb1 =(min(pic1_r_lb1));
pic1_cbottom_lb1=(max(pic1_c_lb1));
pic1_rbottom_lb1=(max(pic1_r_lb1));
pic1_c_min_lb1 = (min(pic1_c_lb1));
pic1_c_min_lb2 = (min(pic1_c_lb2));
pic1_r_min_lb1 = (min(pic1_r_lb1));
pic1_r_min_lb2 = (min(pic1_r_lb2));
plot([pic1_ctop_lb1 pic1_ctop_lb1 pic1_cbottom_lb1 pic1_cbottom_lb1
pic1_ctop_lb1], [pic1_rtop_lb1 pic1_rbottom_lb1 pic1_rbottom_lb1 pic1_rtop_lb1
pic1_rtop_lb1],'r')
H=text(pic1_cbottom_lb1-5,pic1_rtop_lb1-9, '1' );
set(H,'color',[1 0 0]);
set(H,'fontsize',12);
[pic2_r_lb1,pic2_c_lb1] =find(pic2_L==i);
[pic2_r_lb2,pic2_c_lb2] =find(pic2_L==i+1);
pic2_area_lb1 = size(pic2_c_lb1,1);
pic2_area_lb2 = size(pic2_c_lb2,1);
if ((pic2_area_lb1 > 10) && (pic2_area_lb2 > 10)) % && (area <220))
pic2_c_min_lb1 =( min(pic2_c_lb1) );
pic2_c_min_lb2 =( min(pic2_c_lb2) );
pic2_r_min_lb1 =( min(pic2_r_lb1) );
pic2_r_min_lb2 =( min(pic2_r_lb2) );
dir_horiz_lb1 = abs( pic2_c_min_lb1 - pic1_c_min_lb1 );
dir_horiz_lb2 = abs( pic2_c_min_lb2 - pic1_c_min_lb2 );
dir_vert_lb1 = abs( pic2_r_min_lb1 - pic1_r_min_lb1 );
dir_vert_lb2 = abs( pic2_r_min_lb2 - pic1_r_min_lb2 );
display (dir_horiz_lb1);
display (dir_vert_lb1);
display (dir_horiz_lb2);
display (dir_vert_lb2);
%section 4b draw car
%left to right
if (( dir_horiz_lb1 > dir_vert_lb1) && (dir_horiz_lb2 >
dir_vert_lb2))
carlength= abs ( (min(pic1_c_lb2))- (min(pic1_c_lb1)) );
display(carlength);
if ( (carlength < 65) && (carlength > 50))
pic1_ctop_outer=pic1_ctop_lb1;
pic1_rtop_outer= pic1_rtop_lb1-15;
pic1_cbottom_outer= max(pic1_c_lb2); %trial use:
pic2_cbottom;
pic1_cbottom+60;
pic1_rbottom_outer=pic1_rbottom_lb1;
plot([pic1_ctop_outer pic1_ctop_outer pic1_cbottom_outer
pic1_cbottom_outer pic1_ctop_outer],[pic1_rtop_outer pic1_rbottom_outer
pic1_rbottom_outer pic1_rtop_outer pic1_rtop_outer],'g')
end
%end
%bottom to up (vertical)
else
carwidth= abs ( (min(pic1_r_lb2))- (min(pic1_r_lb1)) );
display(carwidth);
%{
if ( (carwidth < 30) && (carwidth > 25))
pic1_ctop_outer=pic1_ctop_lb1;
pic1_rtop_outer= pic1_rtop_lb1-15;
pic1_cbottom_outer= max(pic1_c_lb2);
pic1_rbottom_outer=pic1_rbottom_lb1;
plot([pic1_ctop_outer pic1_ctop_outer pic1_cbottom_outer
pic1_cbottom_outer pic1_ctop_outer],[pic1_rtop_outer pic1_rbottom_outer
pic1_rbottom_outer pic1_rtop_outer pic1_rtop_outer],'g')
end
%}
[L,N]=bwlabel(pic1_D1t2);
if N > 0
for i=1:N,
[ri,ci]=find(L==i);
rci=[ri, ci];
area=size(ci,1);
for k=(i+1):N;
[rk,ck]=find(L==k);
rck=[rk, ck];
dist= abs((min(ci)) - (min(ck))) ;
display (dist);
if ( (dist<30) && (dist>23) )
ctop_outer=(max(ck));
rtop_outer=(min(rk)*1.1); %.2;
cbottom_outer=(min(ci));
rbottom_outer=(max(ri)*0.8);
plot([ctop_outer ctop_outer cbottom_outer
cbottom_outer ctop_outer],[rtop_outer rbottom_outer rbottom_outer rtop_outer
rtop_outer],'g')
H=text(cbottom_outer+25,rtop_outer-9, '' );
set(H,'color',[0 1 0]);
set(H,'fontsize',12);
end
end
end
end %
end
end
end
end
end

More Related Content

What's hot

What's hot (6)

C basics
C basicsC basics
C basics
 
Include
IncludeInclude
Include
 
Swadeshi Microprocessor Quiz 2020 (Start-up India)
Swadeshi Microprocessor Quiz 2020 (Start-up India)Swadeshi Microprocessor Quiz 2020 (Start-up India)
Swadeshi Microprocessor Quiz 2020 (Start-up India)
 
Matlab code for crout method
Matlab code for crout methodMatlab code for crout method
Matlab code for crout method
 
Informatica
InformaticaInformatica
Informatica
 
C programs pbq final
C programs pbq finalC programs pbq final
C programs pbq final
 

Recently uploaded

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Recently uploaded (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

MOVING OBJECT DETECTION CODE

  • 1. clear all ;close all;clc pic1_prv=imread('street_crossing_0536-scaled.png'); pic1_cur=imread('street_crossing_0538-scaled.png'); %imread('MovingCar273.JPG'); pic2_prv=imread('street_crossing_0540-scaled.png');% imread('MovingCar274.JPG'); pic2_cur=imread('street_crossing_0544-scaled.png'); %imread('MovingCar275.JPG'); h=[1,1,1;1,1,1;1,1,1]; gh=h./9; a=0.000001; b=1-a; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% pic1_prv_g=rgb2gray(pic1_prv); pic1_cur_g=rgb2gray(pic1_cur); pic1_prv_gf=imfilter(pic1_prv_g,gh); pic1_cur_gf=imfilter(pic1_cur_g,gh); pic1_B0=pic1_prv_gf; pic1_I0=pic1_prv_gf; pic1_I1=pic1_cur_gf; pic1_B1=(b*pic1_B0)-(a*pic1_I1); pic1_D1=pic1_I1-pic1_B0; pic1_D1t= im2bw(pic1_D1,0.15); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% pic2_prv_g=rgb2gray(pic2_prv); pic2_cur_g=rgb2gray(pic2_cur); pic2_prv_gf=imfilter(pic2_prv_g,gh); pic2_cur_gf=imfilter(pic2_cur_g,gh); pic2_B0=pic2_prv_gf; pic2_I0=pic2_prv_gf; pic2_I1=pic2_cur_gf; pic2_B1=(b*pic2_B0)-(a*pic2_I1); pic2_D1=pic2_I1-pic2_B0; pic2_D1t= im2bw(pic2_D1,0.15); %%%%%%%%%%%%%%%%%%%%%%%%% %Section 2 %delete unwanted fake lights %1{ [L_p1_hgt,N_p1_hgt]=bwlabel(pic1_D1t); pic1_D1t_hgt = pic1_D1t; if N_p1_hgt > 0 for i=1:N_p1_hgt, [r_p1_hgt,c_p1_hgt]=find(L_p1_hgt==i); lightheight=(max(r_p1_hgt)); %display(lightheight); if ( lightheight <45) pic1_D1t_hgt = bwareaopen(pic1_D1t,18); %display(lightheight); end end end [L_p1_ar,N_p1_ar]=bwlabel(pic1_D1t_hgt); pic1_D1t_ar = pic1_D1t_hgt; if N_p1_ar > 0 for i=1:N_p1_ar, [r_p1_ar,c_p1_ar]=find(L_p1_ar==i); pic1_labelsize=size(c_p1_ar,1); if (pic1_labelsize <30) pic1_D1t_ar = bwareaopen(pic1_D1t_hgt,15); end end end pic1_D1t2 = pic1_D1t_ar; %1}
  • 2. %2{ [L_p2_hgt,N_p2_hgt]=bwlabel(pic2_D1t); pic2_D1t_hgt = pic2_D1t; if N_p2_hgt > 0 for i=1:N_p2_hgt, [r_p2_hgt,c_p2_hgt]=find(L_p2_hgt==i); lightheight=(max(r_p2_hgt)); %display(lightheight); if ( lightheight <45) pic2_D1t_hgt = bwareaopen(pic2_D1t,18); %display(lightheight); end end end [L_p2_ar,N_p2_ar]=bwlabel(pic2_D1t_hgt); pic2_D1t_ar = pic2_D1t_hgt; if N_p2_ar > 0 for i=1:N_p2_ar, [r_p2_ar,c_p2_ar]=find(L_p2_ar==i); pic2_labelsize=size(c_p2_ar,1); if (pic2_labelsize <30) pic2_D1t_ar = bwareaopen(pic2_D1t_hgt,15); end end end pic2_D1t2 = pic2_D1t_ar; %2} %now all the small fake lights are removed %Section 3 %display output after the threshold %{ for debugging figure; imshow (pic1_D1t); figure; imshow (pic2_D1t); figure; imshow (pic1_D1t2); figure; imshow (pic2_D1t2); %} %Section 4 % the following commands will draw bounding box around the headlights % and label them %section 4a draw headlights %section 4b draw car pic1_back=pic1_B1; pic1_cur=pic1_I1; figure; imshow(pic1_I1);hold on; [pic1_L,pic1_N]=bwlabel(pic1_D1t2); [pic2_L,pic2_N]=bwlabel(pic2_D1t2); %Section 4a: draw headlights if pic1_N > 0 for i=1:2:pic1_N, [pic1_r_lb1,pic1_c_lb1]=find(pic1_L==i); [pic1_r_lb2,pic1_c_lb2]=find(pic1_L==i+1); pic1_area_lb1=size(pic1_c_lb1,1); pic1_area_lb2=size(pic1_c_lb2,1); if ((pic1_area_lb1 > 10) && (pic1_area_lb2 > 10)) % && (area <50)) PLEASE EDIT IN FINAL ROUND pic1_ctop_lb1 =(min(pic1_c_lb1)); pic1_rtop_lb1 =(min(pic1_r_lb1)); pic1_cbottom_lb1=(max(pic1_c_lb1)); pic1_rbottom_lb1=(max(pic1_r_lb1)); pic1_c_min_lb1 = (min(pic1_c_lb1)); pic1_c_min_lb2 = (min(pic1_c_lb2)); pic1_r_min_lb1 = (min(pic1_r_lb1)); pic1_r_min_lb2 = (min(pic1_r_lb2));
  • 3. plot([pic1_ctop_lb1 pic1_ctop_lb1 pic1_cbottom_lb1 pic1_cbottom_lb1 pic1_ctop_lb1], [pic1_rtop_lb1 pic1_rbottom_lb1 pic1_rbottom_lb1 pic1_rtop_lb1 pic1_rtop_lb1],'r') H=text(pic1_cbottom_lb1-5,pic1_rtop_lb1-9, '1' ); set(H,'color',[1 0 0]); set(H,'fontsize',12); [pic2_r_lb1,pic2_c_lb1] =find(pic2_L==i); [pic2_r_lb2,pic2_c_lb2] =find(pic2_L==i+1); pic2_area_lb1 = size(pic2_c_lb1,1); pic2_area_lb2 = size(pic2_c_lb2,1); if ((pic2_area_lb1 > 10) && (pic2_area_lb2 > 10)) % && (area <220)) pic2_c_min_lb1 =( min(pic2_c_lb1) ); pic2_c_min_lb2 =( min(pic2_c_lb2) ); pic2_r_min_lb1 =( min(pic2_r_lb1) ); pic2_r_min_lb2 =( min(pic2_r_lb2) ); dir_horiz_lb1 = abs( pic2_c_min_lb1 - pic1_c_min_lb1 ); dir_horiz_lb2 = abs( pic2_c_min_lb2 - pic1_c_min_lb2 ); dir_vert_lb1 = abs( pic2_r_min_lb1 - pic1_r_min_lb1 ); dir_vert_lb2 = abs( pic2_r_min_lb2 - pic1_r_min_lb2 ); display (dir_horiz_lb1); display (dir_vert_lb1); display (dir_horiz_lb2); display (dir_vert_lb2); %section 4b draw car %left to right if (( dir_horiz_lb1 > dir_vert_lb1) && (dir_horiz_lb2 > dir_vert_lb2)) carlength= abs ( (min(pic1_c_lb2))- (min(pic1_c_lb1)) ); display(carlength); if ( (carlength < 65) && (carlength > 50)) pic1_ctop_outer=pic1_ctop_lb1; pic1_rtop_outer= pic1_rtop_lb1-15; pic1_cbottom_outer= max(pic1_c_lb2); %trial use: pic2_cbottom; pic1_cbottom+60; pic1_rbottom_outer=pic1_rbottom_lb1; plot([pic1_ctop_outer pic1_ctop_outer pic1_cbottom_outer pic1_cbottom_outer pic1_ctop_outer],[pic1_rtop_outer pic1_rbottom_outer pic1_rbottom_outer pic1_rtop_outer pic1_rtop_outer],'g') end %end %bottom to up (vertical) else carwidth= abs ( (min(pic1_r_lb2))- (min(pic1_r_lb1)) ); display(carwidth); %{ if ( (carwidth < 30) && (carwidth > 25)) pic1_ctop_outer=pic1_ctop_lb1; pic1_rtop_outer= pic1_rtop_lb1-15; pic1_cbottom_outer= max(pic1_c_lb2); pic1_rbottom_outer=pic1_rbottom_lb1; plot([pic1_ctop_outer pic1_ctop_outer pic1_cbottom_outer pic1_cbottom_outer pic1_ctop_outer],[pic1_rtop_outer pic1_rbottom_outer pic1_rbottom_outer pic1_rtop_outer pic1_rtop_outer],'g') end %}
  • 4. [L,N]=bwlabel(pic1_D1t2); if N > 0 for i=1:N, [ri,ci]=find(L==i); rci=[ri, ci]; area=size(ci,1); for k=(i+1):N; [rk,ck]=find(L==k); rck=[rk, ck]; dist= abs((min(ci)) - (min(ck))) ; display (dist); if ( (dist<30) && (dist>23) ) ctop_outer=(max(ck)); rtop_outer=(min(rk)*1.1); %.2; cbottom_outer=(min(ci)); rbottom_outer=(max(ri)*0.8); plot([ctop_outer ctop_outer cbottom_outer cbottom_outer ctop_outer],[rtop_outer rbottom_outer rbottom_outer rtop_outer rtop_outer],'g') H=text(cbottom_outer+25,rtop_outer-9, '' ); set(H,'color',[0 1 0]); set(H,'fontsize',12); end end end end % end end end end end