face detection - off button gui not working

1 visualizzazione (ultimi 30 giorni)
Eliza Tham
Eliza Tham il 29 Gen 2015
Commentato: Geoff Hayes il 1 Feb 2015
Hi, i am working a face recognition system for my fyp but first i would like to ensure that the facial feature can be detected.
I have 2 question. I would like to add the video player into the gui but I am not sure which parts of the part i should amend. I try adding axes(handles.camerAxes) into my code and remove the videoplayer but face error.
Another question will be the off button. I want to off the videoplayer feature but there is error face.
Please help me as I am really new to matlab.
Thank you in advance.
function varargout = face_tracking(varargin)
% FACE_TRACKING MATLAB code for face_tracking.fig
% FACE_TRACKING, by itself, creates a new FACE_TRACKING or raises the existing
% singleton*.
%
% H = FACE_TRACKING returns the handle to a new FACE_TRACKING or the handle to
% the existing singleton*.
%
% FACE_TRACKING('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FACE_TRACKING.M with the given input arguments.
%
% FACE_TRACKING('Property','Value',...) creates a new FACE_TRACKING or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before face_tracking_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to face_tracking_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 face_tracking
% Last Modified by GUIDE v2.5 28-Jan-2015 00:39:01
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @face_tracking_OpeningFcn, ...
'gui_OutputFcn', @face_tracking_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 face_tracking is made visible.
function face_tracking_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 face_tracking (see VARARGIN)
% Choose default command line output for face_tracking
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes face_tracking wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = face_tracking_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 when figure1 is resized.
function figure1_ResizeFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in cameraon.
function cameraon_Callback(hObject, eventdata, handles)
% hObject handle to cameraon (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
faceDetector = vision.CascadeObjectDetector();
obj = imaq.VideoDevice('winvideo', 1, 'MJPG_320x240','ROI',[1 1 320 240]);
handles.vid=obj;
videoFrame = step(obj);
%Get a bounding box around the face
bbox = step(faceDetector, videoFrame);
%Check if something was detected, otherwise exit
if numel(bbox) == 0
errordlg('Face not detected. Please try again.');
end
%Show coordinates of tracked face
videoOut = insertObjectAnnotation(videoFrame,'rectangle',bbox,'Face');
release(obj);
[hueChannel,~,~] = rgb2hsv(videoFrame);
noseDetector = vision.CascadeObjectDetector('Nose');
faceImage = imcrop(videoFrame,bbox);
noseBBox = step(noseDetector,faceImage);
% The nose bounding box is defined relative to the cropped face image.
% Adjust the nose bounding box so that it is relative to the original video
% frame.
noseBBox(1:2) = noseBBox(1:2) + bbox(1:2);
% Create a tracker object.
tracker = vision.HistogramBasedTracker;
initializeObject(tracker, hueChannel, noseBBox);
ROI = get(obj,'ROI');
videoSize = [ROI(3) ROI(4)];
videoPlayer = vision.VideoPlayer('Position',[300 300 videoSize(1:2)+30]);
% Track the face over successive video frames until the video is finished.
%You could set here a finite number of frames to capture
while 1
% Extract the next video frame
videoFrame = step(obj);
% RGB -> HSV
hsv=rgb2hsv(videoFrame);
% Track using the Hue channel data
bbox = step(tracker, hsv(:,:,1));
% Insert a bounding box around the object being tracked
videoOut = insertObjectAnnotation(videoFrame,'rectangle',bbox,'Face');
% Display the annotated video frame using the video player object
step(videoPlayer, videoOut);
end
guidata(hObject,handles);
% Release resources
release(obj);
release(videoPlayer);
% --- Executes on button press in cameraoff.
function cameraoff_Callback(hObject, eventdata, handles)
% hObject handle to cameraoff (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
cameraoff=handles.vid;
delete(cameraoff);
% --- Executes on button press in startStopCamera.
function startStopCamera_Callback(hObject, eventdata, handles)
% hObject handle to startStopCamera (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
  1 Commento
Geoff Hayes
Geoff Hayes il 1 Feb 2015
Eliza - you mention that you are facing an error. Please describe the error and include all relevant text associated with the error.

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by