Helen
Helen

Reputation: 13

Matlab GUI face tracking function

Hi I am creating a Matlab GUI that allows the webcam to be able to detect a person's face once the Face Tracking function is executed. However, I can only detect the face, but it doesn't track the face.

% --- Executes on button press in Tracking.
function Tracking_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% 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)

% Create a cascade detector object.
faceDetector = vision.CascadeObjectDetector();

% Read a video frame and run the detector.
axes(handles.cameraAxes);    
frame  = getsnapshot(handles.vid); 
bbox   = step(faceDetector,frame);


% Draw the bounding box around the face.
rectangle('Position',bbox(1,:),'LineWidth',2,'EdgeColor',[1 1 0]);

%Track the face over successive video frames until the video is finished.
 while ~isDone(handles.vid)

% Extract the next video frame
frame = getsnapshot(handles.vid);
bbox   = step(faceDetector,frame);

% Insert a bounding box around the object being tracked
rectangle('Position',bbox(1,:),'LineWidth',2,'EdgeColor',[1 1 0]);


% Display the annotated video frame using the video player object
getsnapshot(handles.vid);

  end

 release(frame);
 release(handles.vid);

I'm using the Image Acquisition Toolbox, and visited several websites but I can't seem to solve the problem.

Any help is greatly appreciated!

Upvotes: 1

Views: 1335

Answers (1)

Related Questions