フィルターのクリア

How to capture video from webcam in MATLAB?

29 ビュー (過去 30 日間)
Nayana  Hammini
Nayana Hammini 2015 年 12 月 13 日
回答済み: Walter Roberson 2015 年 12 月 13 日
vid = videoinput('winvideo',1, 'YUY2_320x240');
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb');
% vid.FrameRate =30;
vid.FrameGrabInterval = 1; % distance between captured frames
start(vid)
aviObject = avifile('myVideo.avi'); % Create a new AVI file
for iFrame = 1:100 % Capture 100 frames
% ...
% You would capture a single image I from your webcam here
% ...
I=getsnapshot(vid);
%imshow(I);
F = im2frame(I); % Convert I to a movie frame
aviObject = addframe(aviObject,F); % Add the frame to the AVI file
end
aviObject = close(aviObject); % Close the AVI file
stop(vid);
For this code I'm getting error saying
Error using avi
Unexpected Error. Reason: Failed to open file.
Error in avifile (line 175)
aviobj.FileHandle = avi('open',filename);
Error in capture_vid (line 11)
aviObject = avifile('myVideo.avi'); % Create a new AVI file
My matlab version is R2012a
Videos captured from my webcam are stored with .mp4 format. Please help me to capture videos from webcam using MATLAB code. Thank u

採用された回答

Walter Roberson
Walter Roberson 2015 年 12 月 13 日
Use VideoWriter instead of avifile() unless you are using a version of MATLAB before R2010b.
Also watch out for the possibility that you are not in a directory that you have write access to. The directory when you start up MATLAB is often a directory where MATLAB is installed instead of being a user directory that you can write to.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by