function varargout = onlineBlinkDetection(varargin)
% ONLINEBLINKDETECTION MATLAB code for onlineBlinkDetection.fig
% ONLINEBLINKDETECTION, by itself, creates a new ONLINEBLINKDETECTION or raises the existing
% singleton*.
%
% H = ONLINEBLINKDETECTION returns the handle to a new ONLINEBLINKDETECTION or the handle to
% the existing singleton*.
%
% ONLINEBLINKDETECTION('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ONLINEBLINKDETECTION.M with the given input arguments.
%
% ONLINEBLINKDETECTION('Property','Value',...) creates a new ONLINEBLINKDETECTION or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before onlineBlinkDetection_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to onlineBlinkDetection_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help onlineBlinkDetection
% Last Modified by GUIDE v2.5 29-Oct-2018 14:31:56
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @onlineBlinkDetection_OpeningFcn, ...
'gui_OutputFcn', @onlineBlinkDetection_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before onlineBlinkDetection is made visible.
function onlineBlinkDetection_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to onlineBlinkDetection (see VARARGIN)
% Choose default command line output for onlineBlinkDetection
handles.output = hObject;
% (1)初始打开程序时,对下拉菜单device初始化其String属性为webcam列表
handles.device.String=webcamlist;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes onlineBlinkDetection wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = onlineBlinkDetection_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on selection change in device.
% 下拉菜单device的回调函数
function device_Callback(hObject, eventdata, handles)
% hObject handle to device (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns device contents as cell array
% contents{get(hObject,'Value')} returns selected item from device
% (2)单击device将产生以下回调事件:
% 1.定义webcam对象cam
% 2.设置下拉菜单resolution的String属性为当前webcam的支持分辨率列表
handles.cam = webcam(hObject.String{hObject.Value});
guidata(hObject, handles);
handles.resolution.String=handles.cam.AvailableResolutions;
% --- Executes during object creation, after setting all properties.
function device_CreateFcn(hObject, eventdata, handles)
% hObject handle to device (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in resolution.
% 下拉菜单resolution的回调函数
function resolution_Callback(hObject, eventdata, handles)
% hObject handle to resolution (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns resolution contents as cell array
% contents{get(hObject,'Value')} returns selected item from resolution
% (3)通过单击指定当前webcam的分辨率
handles.cam.Resolution=hObject.String{hObject.Value};
% --- Executes during object creation, after setting all properties.
function resolution_CreateFcn(hObject, eventdata, handles)
% hObject handle to resolution (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in exit.
% 退出按钮:(1)清理所有变量(2)关闭全部界面
function exit_Callback(hObject, eventdata, handles)
% hObject handle to exit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clear;
close all;
% --- Executes on button press in preview.
% 预览
function preview_Callback(hObject, eventdata, handles)
% hObject handle to preview (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.win.String='The Cam has been conformed! Showing now.';
%% 人眼检测
% 定义人脸检测器
faceDetector = vision.CascadeObjectDetector;
% 定义左眼检测器并指定在ROI下检测
EyePairSmallDetector = vision.CascadeObjectDetector('LeftEyeCART');
EyePairSmallDetector.UseROI=true;
% 选定1号坐标窗口
axes(handles.axes1);
% 高斯滤波卷积核
h3_5=fspecial('gaussian',3,0.5);
while isempty(handles.cam)==0%网络摄像头运行正常
if handles.exit.Value==1
break;
end
% 获取当前捕捉画面
shot=snapshot(handles.cam);
% 对画面高斯滤波
shot=imfilter(shot,h3_5);
% 在未使用klt追踪前,正常拍摄并捕捉人眼
if handles.klt.Value==0
% 定位人脸区域,并获取包围盒
facebbox=faceDetector(shot)
%[~,facebbox,~]=shotfacetrack(shot,faceDetector,[120 120],1);
% 如果检测到人脸
if isempty(facebbox)==0
% 标记人脸区域
detectedshot = insertObjectAnnotation(shot,'rectangle',facebbox,'Face','LineWidth',2);
% 定位人眼区域,并返回包围盒
eyesbbox=EyePairSmallDetector(shot,facebbox(1,:));
% 如果检测到人眼
if isempty(eyesbbox)==0
% 标记人眼区域
detectedshot = insertObjectAnnotation(detectedshot,'rectangle',eyesbbox(1,:),'Eyes','LineWidth',2,'Color','blue');
end
% 显示和刷新
imshow(detectedshot);
drawnow;
end
else
break;
end
end
%% KLT光流追踪
handles.win.String='The inital ROI to eyes has been located! Starting KLT-Track now .';
bboxPoints = bbox2points(eyesbbox(1, :));
points = detectMinEigenFeatures(rgb2gray(shot), 'ROI', eyesbbox(1,:));
imshow(detectedshot),hold on,plot(points),hold off;
% klt准备工作:提取眼部特征点并初始
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
onlineblinkdetectdion.zip (3个子文件)
onlineBlinkDetection.m 17KB
rectbbox.m 247B
onlineBlinkDetection.fig 101KB
共 3 条
- 1
资源评论
- 川川菜鸟2022-01-23你好,购买了,能留个联系方式吗,运行有点错误
- 与忘记2022-02-24楼主,这个程序运行出现报错的问题你解决了吗,恳请回复
- xintiao5552022-03-21用户下载后在一定时间内未进行评价,系统默认好评。
- 梦惊禅夜2022-03-16用户下载后在一定时间内未进行评价,系统默认好评。
Ephemeroptera
- 粉丝: 174
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功