Help with Gui for real time webcam video input

3 次查看(过去 30 天)
I had a code for face detection using vision.CascadeObjectDetector in real time and i want to input the code into a gui with 1 start buttona and 1 axes. I had try by editing this code
if true
obj = imaq.VideoDevice('winvideo',1,'YUY2_320x240');
set(obj,'ReturnedColorSpace','rgb');
figure('menubar','none','tag','webcam');
% tell matlab to start the webcam on user request, not automatically
triggerconfig(obj, 'manual');
% we need this to know the image height and width
vidRes = get(obj, 'VideoResolution');
% image width
imWidth = vidRes(1);
% image height
imHeight = vidRes(2);
% number of bands of our image (should be 3 because it's RGB)
nBands = get(obj, 'NumberOfBands');
% create an empty image container and show it on axPreview
hImage = image(zeros(imHeight, imWidth, nBands), 'parent', handles.axPreview);
% begin the webcam preview
preview(obj, hImage);
end
into this
if true
obj = imaq.VideoDevice('winvideo',1,'YUY2_320x240');
set(obj,'ReturnedColorSpace','rgb');
figure('menubar','none','tag','webcam');
% tell matlab to start the webcam on user request, not automatically
triggerconfig(obj, 'manual');
while(true)
frame=step(obj);
%Detect faces.
bboxes = step(faceDetector,frame);
%Annotate detected faces.
IFaces = insertObjectAnnotation(frame,'rectangle',bboxes,'face');
hImage = image(IFaces,'border','tight', handles.axPreview);
% begin the webcam preview
preview(obj, hImage);
end
but failed. Could anyone teach me how to input both the webcam and the bounding box of the face in real time into the same axes? Thanks.

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by