How to create a bounding box in webcam preview and capture image in that bounding box?

37 views (last 30 days)
Explorer on 4 Feb 2014
Commented: Image Analyst on 15 May 2020
This is how I want to do it:
1. Determine positions in webcam preview
2. Create bounding box on that positions in webcam preview
3. Place hand in bounding box
4. Capture it

Accepted Answer

Image Analyst
Image Analyst on 4 Feb 2014
You can use ginput, rectangle(), imrect() or other functions to determine locations in the image. Then use plot() to create the box. Then call getsnapshot, which will get the full image but you then crop it with imcrop() to limit it to just the bounding box.
Heloise BOTREL
Heloise BOTREL on 7 May 2020
Ans :
webcamlist % No semicolons.
ans =
1×1 cell array
{'HP TrueVision HD'}
mycam =
webcam with properties:
Name: 'HP TrueVision HD'
AvailableResolutions: {1×6 cell}
Resolution: '640x480'
Exposure: -6
Sharpness: 2
Gain: 4
Contrast: 32
WhiteBalance: 4000
Saturation: 64
Hue: 0
Gamma: 120
ExposureMode: 'auto'
Brightness: 128
BacklightCompensation: 1
WhiteBalanceMode: 'auto'
I have this package and "Image Acquisition Toolbox Support Package for OS generic Video Interface" and 'Image Acquisition Toolbox"

Sign in to comment.

More Answers (2)

Aude Menet
Aude Menet on 14 May 2020
Edited: Aude Menet on 14 May 2020
Error using videoinpu (line 219)
Invalid ADAPTATORNAME specified. Type 'imaqhwinfo' for a list of available
ADAPTORNAMEs. Image acquisition adaptors may be available as downloadable
support packages. Open Add-Ons Explorer to install additional adaptors.
Error in cameratest (line 20)
Can someone help me to fix these errors please ?

Sign in to comment.

Image Analyst
Image Analyst on 15 May 2020
When you do this, do you get a live video window that pops up? I do
mycam = webcam
Image Analyst
Image Analyst on 15 May 2020
Now try the snapshot() method:
% Display a list of installed cameras.
% Get an object linked to the webcam.
mycam = webcam
% Show what things this camera can do
% Open live video window.
% Prompt user to snap a photo.
promptMessage = sprintf('Do you want to snap a photo,\nor Quit?');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Snap', 'Quit', 'Snap');
if contains(buttonText, 'Quit', 'IgnoreCase', true)
% Snap the photo.
rgbImage = mycam.snapshot;
% Close live video window.
% Display image
caption = sprintf('Here is the photo you snapped at %s', datestr(now));
title(caption, 'FontSize', 20);
% Maximize figure.
g = gcf;
g.WindowState = 'maximized';

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by