How can I make a buzzer when face is detected?

Current project is creating face detector using matlab with buzzer when it detect a face, my code is here:
faceDetector = vision.CascadeObjectDetector();
%Get the input device using image acquisition toolbox,resolution = 640x480 to improve performance obj =imaq.VideoDevice('winvideo', 1, 'YUYV_640x480','ROI', [1 1 640 480]); set(obj,'ReturnedColorSpace', 'rgb'); figure('menubar','none','tag','webcam');
while (true) frame=step(obj); bbox=step(faceDetector,frame);
boxInserter = vision.ShapeInserter('BorderColor','Custom',...
'CustomBorderColor',[255 255 0]);
videoOut = step(boxInserter, frame,bbox);
imshow(videoOut,'border','tight');
f=findobj('tag','webcam');
if (isempty(f));
[hueChannel,~,~] = rgb2hsv(frame);
% Display the Hue Channel data and draw the bounding box around the face. figure, imshow(hueChannel), title('Hue channel data');
rectangle('Position',bbox,'EdgeColor','r','LineWidth',1) hold off noseDetector = vision.CascadeObjectDetector('Nose'); faceImage = imcrop(frame,bbox); imshow(faceImage) noseBBox = step(noseDetector,faceImage);
noseBBox(1:1) = noseBBox(1:1) + bbox(1:1); videoInfo = info(obj); ROI=get(obj,'ROI'); VideoSize = [ROI(3) ROI(4)];
videoPlayer = vision.VideoPlayer('Position',[300 300 VideoSize+30]); tracker = vision.HistogramBasedTracker; initializeObject(tracker, hueChannel, bbox);
while (1)
% Extract the next video frame frame = step(obj); % RGB -> HSV [hueChannel,~,~] = rgb2hsv(frame);
% Track using the Hue channel data
bbox = step(tracker, hueChannel);
% Insert a bounding box around the object being tracked
videoOut = step(boxInserter, frame, bbox);
%Insert text coordinates
% Display the annotated video frame using the video player object
step(videoPlayer, videoOut);
pause (.2)
end
% Release resources release(obj); release(videoPlayer);
close(gcf)
break
end
pause(0.05)
end
release(obj)
I don't know where to put the code when the face is detected, it will buzz using arduino.

Answers (4)

Attach a buzzer to your Arduino, then send a signal to that pin when you want. I assume you already know how to talk to your Arduino.
We didn't look over your code, but you can fix that by reading this link to format it properly.
Here is John's favorite way to indicate success, like at finding a particular face:
s = load('handel.mat')
soundsc(s.y, s.Fs); % Make sure your speakers are turned way up.
Not an Arduino method though.
hey can you please help me how can i send a data after face detection in matlab to arduino so that my arduino has to open a stepper motor
boxInserter = vision.ShapeInserter('BorderColor','Custom',... 'CustomBorderColor',[255 255 0]); videoOut = step(boxInserter, frame,bbox); imshow(videoOut,'border','tight'); f=findobj('tag','webcam'); if (isempty(f)); [hueChannel,~,~] = rgb2hsv(frame); % Track using the Hue channel data bbox = step(tracker, hueChannel); % Insert a bounding box around the object being tracked videoOut = step(boxInserter, frame, bbox); %Insert text coordinates % Display the annotated video frame using the video player object step(videoPlayer, videoOut); pause (.2) end

Asked:

on 27 May 2018

Answered:

on 5 Oct 2020

Community Treasure Hunt

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

Start Hunting!