clc;
clear all;
close all;
%%
load DB
load svm
cl = {'open','close'};
dim = [30 60;
30 60
40 65];
delete(imaqfind)
vid=videoinput('winvideo',1);
triggerconfig(vid,'manual');
set(vid,'FramesPerTrigger',1 );
set(vid,'TriggerRepeat', Inf);
% start(vid);
% View the default color space used for the data � The value of the ReturnedColorSpace property indicates the color space of the image data.
color_spec=vid.ReturnedColorSpace;
% Modify the color space used for the data � To change the color space of the returned image data, set the value of the ReturnedColorSpace property.
if ~strcmp(color_spec,'rgb')
set(vid,'ReturnedColorSpace','rgb');
end
start(vid)
% Create a detector object
faceDetector = vision.CascadeObjectDetector;
faceDetectorLeye = vision.CascadeObjectDetector('EyePairBig');
faceDetectorM = vision.CascadeObjectDetector('Mouth');
tic
% Initialise vector
LC = 0; % Left eye closer
RC = 0; % Right eye closer
MC = 0; % Mouth closer
TF = 0; % Total frames
TC = 0; % Total closure
Feature = [];
c1p = 1;
species = 'Non-Fatigue';
for ii = 1:600
trigger(vid);
im=getdata(vid,1); % Get the frame in im
imshow(im)
subplot(3,4,[1 2 5 6 9 10]);
imshow(im)
% Detect faces
bbox = step(faceDetector, im);
if ~isempty(bbox);
bbox = bbox(1,:);
% Plot box
rectangle('Position',bbox,'edgecolor','r');
S = skin_seg2(im);
% Segment skin region
bw3 = cat(3,S,S,S);
% Multiply with original image and show the output
Iss = double(im).*bw3;
Ic = imcrop(im,bbox);
Ic1 = imcrop(Iss,bbox);
subplot(3,4,[3 4]);
imshow(uint8(Ic1))
bboxeye = step(faceDetectorLeye, Ic);
if ~isempty(bboxeye);
bboxeye = bboxeye(1,:);
Eeye = imcrop(Ic,bboxeye);
% Plot box
rectangle('Position',bboxeye,'edgecolor','y');
else
disp('Eyes not detected')
end
if isempty(bboxeye)
continue;
end
Ic(1:bboxeye(2)+2*bboxeye(4),:,:) = 0;
% Detect Mouth
bboxM = step(faceDetectorM, Ic);
if ~isempty(bboxM);
bboxMtemp = bboxM;
if ~isempty(bboxMtemp)
bboxM = bboxMtemp(1,:);
Emouth = imcrop(Ic,bboxM);
% Plot box
rectangle('Position',bboxM,'edgecolor','y');
else
disp('Mouth not detected')
continue;
end
else
disp('Mouth not detected')
continue;
end
[nre nce k ] = size(Eeye);
% Divide into two parts
Leye = Eeye(:,1:round(nce/2),:);
Reye = Eeye(:,round(nce/2+1):end,:);
subplot(3,4,7)
imshow(edge(rgb2gray(Leye),'sobel'));
subplot(3,4,8)
imshow(edge(rgb2gray(Reye),'sobel'));
Emouth3 = Emouth;
Leye = rgb2gray(Leye);
Reye = rgb2gray(Reye);
Emouth = rgb2gray(Emouth);
% K means clustering
X = Emouth(:);
[nr1 nc1 ] = size(Emouth);
cid = kmeans(double(X),2,'emptyaction','drop');
kout = reshape(cid,nr1,nc1);
subplot(3,4,[11,12]);
% Segment
Ism = zeros(nr1,nc1,3);
% Ism(:,:,3) = 255;
% Ism(:,:,3) = 125;
Ism(:,:,3) = 255;
bwm = kout-1;
bwm3 = cat(3,bwm,bwm,bwm);
Ism(logical(bwm3)) = Emouth3(logical(bwm3));
imshow(uint8(Ism));
% Template matching using correlation coefficient
% Left eye
% Resize to standard size
Leye = imresize(Leye,[dim(1,1) dim(1,2)]);
c1 =match_DB(Leye,DBL);
subplot(3,4,7)
title(cl{c1})
% Right eye
% Resize to standard size
Reye = imresize(Reye,[dim(2,1) dim(2,2)]);
c2 = match_DB(Reye,DBR);
subplot(3,4,8)
title(cl{c2})
% Mouth
% Resize to standard size
Emouth = imresize(Emouth,[dim(3,1) dim(3,2)]);
c3 = match_DB(Emouth,DBM);
subplot(3,4,[11,12]);
title(cl{c3})
if c1 == 2
LC = LC+1;
if c1p == 1
TC = TC+1;
end
end
if c2==2
RC = RC+1;
end
if c3 == 1
MC = MC + 1;
end
TF = TF + 1; % Total frames
toc
if toc>8
Feature = [LC/TF RC/TF MC/TF TC]
species = svmclassify(svmStruct,Feature);
tic
% Initialise vector
LC = 0; % Left eye closer
RC = 0; % Right eye closer
MC = 0; % Mouth closer
TF = 0; % Total frames
TC = 0; % Total closure
end
subplot(3,4,[1 2 5 6 9 10]);
if strcmpi(species,'Fatigue')
text(20,20,species,'fontsize',14,'color','r','Fontweight','bold')
beep;
else
text(20,20,species,'fontsize',14,'color','g','Fontweight','bold')
end
c1p = c1;
pause(0.00005)
end
end
没有合适的资源?快使用搜索试试~ 我知道了~
疲劳驾驶检测matlab图像处理Code.zip
共139个文件
bmp:113个
m:12个
db:8个
需积分: 49 64 下载量 8 浏览量
2020-02-25
17:08:59
上传
评论 6
收藏 741KB ZIP 举报
温馨提示
本基于MATLAB图像处理的疲劳驾驶检测提出了一种基于视觉信息和人工智能的驾驶员睡意自动检测模块。该系统的目的是对驾驶员的面部和眼睛进行定位、跟踪和分析,计算睡意指数,以防止事故的发生。人脸和眼睛的检测都是通过AdaBoost分类器来实现的。为了提高人脸跟踪的精度,提出了一种检测与目标跟踪相结合的方法。提出的人脸跟踪方法,还具有自校正能力。在找到眼睛区域后,利用局部二值模式(LBP)提取眼睛特征。利用这些特征,训练一个支持向量机分类器(SVM)进行眼睛状态分析。
资源推荐
资源详情
资源评论
收起资源包目录
疲劳驾驶检测matlab图像处理Code.zip (139个子文件)
136.bmp 4KB
155.bmp 3KB
125.bmp 3KB
145.bmp 3KB
157.bmp 3KB
144.bmp 3KB
123.bmp 3KB
105.bmp 3KB
128.bmp 3KB
154.bmp 3KB
131.bmp 3KB
165.bmp 3KB
156.bmp 3KB
139.bmp 3KB
127.bmp 3KB
132.bmp 3KB
164.bmp 3KB
107.bmp 3KB
140.bmp 3KB
129.bmp 3KB
101.bmp 3KB
113.bmp 3KB
150.bmp 3KB
102.bmp 3KB
100.bmp 3KB
143.bmp 3KB
110.bmp 3KB
108.bmp 3KB
121.bmp 3KB
160.bmp 3KB
103.bmp 3KB
124.bmp 3KB
142.bmp 3KB
109.bmp 3KB
141.bmp 3KB
134.bmp 3KB
106.bmp 3KB
146.bmp 3KB
161.bmp 3KB
149.bmp 3KB
104.bmp 3KB
158.bmp 3KB
135.bmp 3KB
133.bmp 3KB
163.bmp 3KB
111.bmp 3KB
162.bmp 3KB
153.bmp 3KB
159.bmp 3KB
137.bmp 3KB
130.bmp 3KB
151.bmp 3KB
126.bmp 3KB
114.bmp 3KB
119.bmp 3KB
112.bmp 3KB
115.bmp 3KB
120.bmp 3KB
152.bmp 3KB
116.bmp 3KB
102.bmp 3KB
106.bmp 3KB
103.bmp 3KB
101.bmp 3KB
104.bmp 3KB
106.bmp 3KB
103.bmp 3KB
145.bmp 3KB
104.bmp 3KB
143.bmp 3KB
102.bmp 3KB
101.bmp 3KB
142.bmp 3KB
110.bmp 3KB
117.bmp 3KB
100.bmp 3KB
105.bmp 3KB
140.bmp 3KB
161.bmp 3KB
113.bmp 3KB
159.bmp 3KB
132.bmp 3KB
111.bmp 3KB
141.bmp 3KB
155.bmp 3KB
107.bmp 3KB
100.bmp 3KB
112.bmp 3KB
160.bmp 3KB
109.bmp 3KB
162.bmp 3KB
144.bmp 3KB
108.bmp 3KB
131.bmp 3KB
107.bmp 3KB
105.bmp 3KB
117.bmp 3KB
134.bmp 3KB
148.bmp 3KB
146.bmp 3KB
共 139 条
- 1
- 2
资源评论
qq_30392381
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功