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

조회 수: 2 (최근 30일)
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

채택된 답변

Image Analyst
Image Analyst 2014년 2월 4일
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.
  댓글 수: 18
Image Analyst
Image Analyst 2020년 5월 6일
Did you install the webcam add-on? See the Add-ons tab. Home->Addons-> Get Addons -> MATLAB support package for USB webcams.
What does this show:
webcamlist % No semicolons.
mycam=webcam
Heloise BOTREL
Heloise BOTREL 2020년 5월 7일
Ans :
webcamlist % No semicolons.
mycam=webcam
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"

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Aude Menet
Aude Menet 2020년 5월 14일
편집: Aude Menet 2020년 5월 14일
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)
videoObject=videoinput('winvideo');
Can someone help me to fix these errors please ?
  댓글 수: 4
Image Analyst
Image Analyst 2020년 5월 15일
Have you downloaded the webcam add on? Use the Add-Ons explorer from the Home tab of the tool ribbon and type in webcam.
Aude Menet
Aude Menet 2020년 5월 15일
Yes I have dowloaded them since I'm trying to make my webcam work through matlab.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2020년 5월 15일
When you do this, do you get a live video window that pops up? I do
webcamlist
mycam = webcam
methods(mycam)
mycam.preview
  댓글 수: 2
Image Analyst
Image Analyst 2020년 5월 15일
Now try the snapshot() method:
% Display a list of installed cameras.
webcamlist
% Get an object linked to the webcam.
mycam = webcam
% Show what things this camera can do
methods(mycam)
properties(mycam)
% Open live video window.
mycam.preview
% 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)
return;
end
% Snap the photo.
rgbImage = mycam.snapshot;
% Close live video window.
mycam.closePreview
% Display image
imshow(rgbImage);
caption = sprintf('Here is the photo you snapped at %s', datestr(now));
title(caption, 'FontSize', 20);
% Maximize figure.
g = gcf;
g.WindowState = 'maximized';

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by