• 大小: 185KB
    文件类型: .rar
    金币: 2
    下载: 3 次
    发布日期: 2021-05-27
  • 语言: Matlab
  • 标签: 疲劳检测  

资源简介

人眼检测、疲劳驾驶检测,MATLAB代码,有界面,亲测可用

资源截图

代码片段和文件信息


clc;
clear all;
close all;
%%
load DB
load svm
cl = {‘open‘‘close‘};

dim = [30 60;
        30 60
        40 65];
delete(imaqfind)
vid=webcam();
videoframe = snapshot(vid);
frameSize = size(videoframe);
videoPlayer = vision.VideoPlayer(‘Position‘ [100 100 [frameSize(2) frameSize(1)]+30]);

% 定位眼睛和嘴
faceDetector = vision.CascadeobjectDetector;   
faceDetectorLeye = vision.CascadeobjectDetector(‘EyePairBig‘); 
faceDetectorM = vision.CascadeobjectDetector(‘Mouth‘); 
tic% 保存当前时间,开始计时
% 初始向量
LC = 0; 
RC = 0; 
MC = 0; 
TF = 0; 
TC = 0; 
Feature = [];
c1p = 1;
species = ‘Non-Fatigue‘;%识别疲劳与否
for ii = 1:600 %设置频率为600帧
   
   
   im=snapshot(vid); % 采集图片
    imshow(im)
    
    subplot(34[1 2 5 6 9 10]);
    imshow(im)
    
    %脸部定位
    bbox = step(faceDetector im); 
    
    if ~isempty(bbox);
        bbox = bbox(1:);%循环,直到检测成功

        % 画框
        rectangle(‘Position‘bbox‘edgecolor‘‘r‘);

         S = skin_seg2(im);
        % 分离皮肤区域
        bw3 = cat(3SSS);

        % 原始图像与输出结果相乘
        Iss = double(im).*bw3;

        Ic = imcrop(imbbox);
        Ic1 = imcrop(Issbbox);%剪切
        subplot(34[3 4]);
        imshow(uint8(Ic1))
        
        bboxeye = step(faceDetectorLeye Ic); %同理定位眼睛
        
        if ~isempty(bboxeye);
            bboxeye = bboxeye(1:);

            Eeye = imcrop(Icbboxeye);
            %画框
            rectangle(‘Position‘bboxeye‘edgecolor‘‘y‘);
        else
            disp(‘Eyes not detected Please adapt to your posion‘)%输出
        end
        
        if isempty(bboxeye)
            continue;%循环
        end
       Ic(1:bboxeye(2)+2*bboxeye(4)::) = 0; 

        % 同理定位嘴
        bboxM = step(faceDetectorM Ic); 
        

        if ~isempty(bboxM);
            bboxMtemp = bboxM;
            
            if ~isempty(bboxMtemp)
            
                bboxM = bboxMtemp(1:);
                Emouth =  imcrop(IcbboxM);
                
                % 画框
                rectangle(‘Position‘bboxM‘edgecolor‘‘y‘);
            else
                disp(‘Mouth  not detected Please adapt your posion‘)
                continue;
            end
        else
            disp(‘Mouth not detected‘)
            continue;
        end
        
        [nrencek ] = size(Eeye);
        

        Leye = Eeye(:1:round(nce/2):);
        Reye = Eeye(:round(nce/2+1):end:);
              
        subplot(347)
        imshow(edge(rgb2gray(Leye)‘sobel‘));%sobel边缘算子
        subplot(348)
        imshow(edge(rgb2gray(Reye)‘sobel‘));
        
        Emouth3 = Emouth;
        
        
        Leye = rgb2gray(Leye);
        Reye = rgb2gray(Reye);
        Emouth = rgb2gray(Emouth);

       
        X = Emouth(:);
        [nr1 nc1 ] = size(Emouth);
        cid = kmeans(double(X)2‘emptyaction‘‘drop‘);
        
        kout = reshape(cidnr1nc1); %调整矩阵
        subplot(34[1112]);
  

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     185709  2016-11-01 22:05  matlab人眼疲劳\DB.mat

     文件       4935  2017-06-06 13:50  matlab人眼疲劳\main.m

     文件        509  2017-06-06 14:18  matlab人眼疲劳\match_DB.m

     文件        495  2017-06-06 14:17  matlab人眼疲劳\skin_seg2.m

     文件       1119  2016-11-01 22:05  matlab人眼疲劳\svm.mat

     目录          0  2018-06-06 20:37  matlab人眼疲劳

----------- ---------  ---------- -----  ----

               192767                    6


评论

共有 条评论