Hello Vardhit,
To achieve live human detection using a webcam in MATLAB, you can use the webcam function to capture the video feed and the Computer Vision Toolbox for detecting humans. You can then process each frame to detect humans and save the video when a human is detected. Below is a step-by-step guide and a sample code to get you started:Steps to Implement Live Human Detection
- Set Up Webcam:
- Use MATLAB's webcam function to access your webcam.
2. Load Pre-trained Detector:
- Use a pre-trained object detector, such as peopleDetectorACF from the Computer Vision Toolbox, to detect humans.
3. Process Video Frames:
- Capture frames from the webcam, detect humans, and annotate the frames.
4. Record Video:
- Start recording when a human is detected and save the video to the hard disk.
5 . Display Video:
- Use imshow to display the video feed with annotations in real-time.
Example Code:
videoPlayer = vision.VideoPlayer('Position', [100, 100, 680, 520]);
videoWriter = VideoWriter('DetectedVideo.avi');
peopleDetector = peopleDetectorACF();
bboxes = peopleDetector(frame);
annotatedFrame = insertObjectAnnotation(frame, 'rectangle', bboxes, 'Human');
step(videoPlayer, annotatedFrame);
disp('Recording started...');
writeVideo(videoWriter, annotatedFrame);
disp('Recording stopped.');
I hope it helps!