error when starting the camera of this gui code

1 view (last 30 days)
function varargout = gui_face_detect(varargin) % GUI_FACE_DETECT MATLAB code for gui_face_detect.fig % GUI_FACE_DETECT, by itself, creates a new GUI_FACE_DETECT or raises the existing % singleton*. % % H = GUI_FACE_DETECT returns the handle to a new GUI_FACE_DETECT or the handle to % the existing singleton*. % % GUI_FACE_DETECT('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GUI_FACE_DETECT.M with the given input arguments. % % GUI_FACE_DETECT('Property','Value',...) creates a new GUI_FACE_DETECT or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before gui_face_detect_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to gui_face_detect_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 gui_face_detect
% Last Modified by GUIDE v2.5 10-Sep-2018 11:35:14
% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @gui_face_detect_OpeningFcn, ... 'gui_OutputFcn', @gui_face_detect_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 gui_face_detect is made visible. function gui_face_detect_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 gui_face_detect (see VARARGIN)
% Choose default command line output for gui_face_detect handles.output = hObject;
% Update handles structure guidata(hObject, handles);
% UIWAIT makes gui_face_detect wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = gui_face_detect_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 button press in startcam. function startcam_Callback(hObject, eventdata, handles) % hObject handle to startcam (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %function start_camera global vid global Im2 vid = videoinput('winvideo',2); triggerconfig(vid,'manual'); set(vid,'FramePerTrigger',1); set(vid,'TriggerRepeat',Inf); set(vid,'ReturnedColorSpace','rgb'); start(vid); faceDetector = vision.CascadeObjectDetector(); while (1) try trigger(vid); temp = getdata(vid,1); axes(handles.axes1); imshow(temp); g = getsnapshot(vid); data = g; videoFrame = data; bb = step(faceDetector, videoFrame); [Im1,Im2] = separate(data,bb); axes(handles.axes2); imshow(Im2); pause(2); catch break; end end
% --- Executes on button press in capture_image. function capture_image_Callback(hObject, eventdata, handles) % hObject handle to capture_image (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %function capture_face global vid; global Im2; try stop(vid); end faceI = Im2; axes(handles.axes3); imshow(faceI)
% --- Executes on button press in train. function train_Callback(hObject, eventdata, handles) % hObject handle to train (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %function training global Im2 global className; try load dbs; feature = lbp_sir(rgb2gray(Im2)); dbs = [dbs; features]; f = find(classes == className); f = length(f); f = f + 1; fname = strcat(num2str(className),'_',num2str(f),'.png'); imwrite(Im2,fname,'png'); classes = [classes; className]; save dbs dbs classes; catch dbs = []; classes = []; feature = lbp_sir(rgb2gray(Im2)); dbs = [dbs; feature]; classes = [classes; className]; fname = strcat(num2str(className),'_',num2str(1),'.png'); imwrite(Im2,fname,'png'); save dbs dbs classes; end axes(handles.axes3); plot(feature);
% --- Executes on button press in test. function test_Callback(hObject, eventdata, handles) % hObject handle to test (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %function testing global vid; global Im2; stop(vid); %% extract face rectangle faceI = Im2; axes(handles.axes3); imshow(faceI); %recognize load dbs db = dir('*.png'); n = ceil(sqrt(length(db))); F = []; for(i = 1 : length(db)) im = imread(db(i).name); im = imresize(im,[128 128]); f = lbp_sir(rgb2gray(im)); F = [F;f]; title(num2str(classes(i))); end size(Im2) Im2 = imresize(Im2,[128 128]); ftest = lbp_sir(rgb2gray(Im2)); for(i = 1 : length(db)) D(i,:) = abs(F(i,:) - ftest); end score = Inf; match = -1; for(i = 1 : length(db)) s = sum(D(i,:)); if(s < score) match = i; score = s; end end match detected = classes(match); fname = db(match).name; axes(handles.axes3); imshow(imread(fname)); title(strcat('detected class is:',num2str(detected)));
% --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!