Tải bản đầy đủ - 0 (trang)
C. Xác định dấu phân cách trái / phải.

C. Xác định dấu phân cách trái / phải.

Tải bản đầy đủ - 0trang

for i = 1:MaxLaneNum

% Pick the column corresponding to the point closer to the top

if Pts(1, i) >= Pts(3, i)

ColNum = Pts(2, i);

else

ColNum = Pts(4, i);

end

if Count_ref(i) >= 5

centerDis = abs(Halfwidth - ColNum);

else

centerDis = Dis_inf;

end

if (Halfwidth - ColNum) >= 0 % left lane

if centerDis < Left_dis

Left_dis = centerDis;

Left_pts = Pts(:, i);

end

else



% right lane

if centerDis < Right_dis

Right_dis = centerDis;

Right_pts = Pts(:, i);

end



end

end



% Departure detection

if Left_dis < Dis_inf

TmpLeftPts = Left_pts;

else

TmpLeftPts = zeros(4, 1);

end

if Right_dis < Dis_inf

TmpRightPts = Right_pts;

else

TmpRightPts = zeros(4, 1);

end

TwoLanes = int32([TmpLeftPts TmpRightPts]);



88



% Check whether both lanes are valid

Check1 = (TwoLanes(1,:) ~= TwoLanes(3,:)) | ...

(TwoLanes(2,:) ~= TwoLanes(4,:));

Check2 = (abs(TwoLanes(1,:) - TwoLanes(3,:)) + ...

abs(TwoLanes(2,:) - TwoLanes(4,:))) >= 10;

TwoValidLanes = (Left_dis <= Dis_inf) && (Right_dis <= Dis_inf) && ...

all((TwoLanes(1,:)>=0) & Check1 & Check2);



Diswarn = Dis_inf * 0.4; % Distance threshold for departure warning

if Left_dis < Diswarn && Left_dis <= Right_dis

RawMsg = 2;

elseif Right_dis < Diswarn && Left_dis > Right_dis

RawMsg = 0;

else

RawMsg = 1;

end

% Meaning of Raw Masseage: 0 = Right lane departure,

%



1 = Normal driving, 2 = Left lane departure



% The following code combines left-right departure to left departure and

% right-left departure to right departure. It utilizes the fact that

there

% must be at least 4 frames of normal driving between a left departure

% warning and a right departure warning.

NumNormalDriving = NumNormalDriving + (RawMsg == 1);

RawMsg = int8(RawMsg);

if RawMsg == int8(1) || NumNormalDriving >= 4

OutMsg = RawMsg;

end % else keep old OutMsg



if RawMsg ~= int8(1)

NumNormalDriving = 0;

end



TwoLanes = TwoLanes([2 1 4 3], :);



D. Nút Start Webcam.

% hObject



handle to startwebcam_pushbutton (see GCBO)



89



% eventdata



reserved - to be defined in a future version of MATLAB



% handles



structure with handles and user data (see GUIDATA)



global vid

isTextStart = strcmp(get(hObject,'String'),'Start Webcam');

isTextStarted = strcmp(get(hObject,'String'),'Webcam Started');

axes(handles.webcam);

cla(handles.webcam);

guidata(hObject, handles);

set(handles.webcam);

vid = videoinput('winvideo', 1, 'YUY2_640x480');

vid.ReturnedColorSpace = 'rgb';

vidRes = get(vid, 'VideoResolution');

nBands = get(vid, 'NumberOfBands');

hImage = image( zeros(vidRes(2), vidRes(1), nBands));

preview(vid, hImage);

set(handles.startwebcam_pushbutton,'String','Webcam Started');

set(handles.startwebcam_pushbutton,'Enable','off');



E. Nút Detection & Tracking.

% hObject



handle to dentr_pushbutton5 (see GCBO)



% eventdata



reserved - to be defined in a future version of MATLAB



% handles



structure with handles and user data (see GUIDATA)



% Read the file into a MATLAB movie structure.



set(handles.dentr_pushbutton5,'String','Processing');

set(handles.dentr_pushbutton5,'Enable','off');

DrawPoly = 1;



% Set 0 de ve duong line.



NumRows = 120; % So hang trong vung anh xu ly.

MaxLaneNum = 20; % So lan duong toi da de tich luy.

ExpLaneNum = 2;

Rep_ref



% So lan duong duoc tim trong khung hinh.



= zeros(ExpLaneNum, MaxLaneNum); % Line luu tru.



Count_ref = zeros(1, MaxLaneNum);



% Dem mang luu tru.



TrackThreshold = 75; % Su thay doi toi da cho phep trong khoang cach giua

% hai lan duong.

LaneColors = single([0 0 0;1 1 0; 1 1 0; 1 1 1;1 1 1]);

% So khung anh toi thieu de nhan dang.

frameFound = 5;

% So khung anh toi da trong nhan dang.



90



frameLost = 20;



% Cho gia tri Rho 35:45

startIdxRho_R = 415;

NumRhos_R = 51;



% Cho gia tri Theta -90:-70deg

startIdxTheta_R = 1;

NumThetas_R = 21;



% Cho gia tri Rho 379:415

startIdxRho_L = 380;

NumRhos_L = 36;



% Cho gia tri Theta 55:85deg

startIdxTheta_L = 146;

NumThetas_L = 21;



% Hien thi duong line offset.

offset = int32([0, NumRows, 0, NumRows]);



%%

% Tao doi tuong |VideoFileReader| de doc video tu file.

hVideoSrc = imaq.VideoDevice('winvideo',2,'RGB24_640x480', ...

'ROI', [140 1 360 240], ...

'ReturnedColorSpace', 'rgb');



%imaq.VideoDevice('winvideo',2,'RGB24_640x480', ...

%vision.VideoFileReader('viplanedeparture.avi');

%%

% Tao doi tuong |ColorSpaceConverter| de chuyen anh RGB sang anh cuong

do.

hColorConv1 = vision.ColorSpaceConverter( ...

'Conversion', 'RGB to intensity');



%%



91



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

C. Xác định dấu phân cách trái / phải.

Tải bản đầy đủ ngay(0 tr)

×