how can i feed the pre-recorded video to the following code instead of live video(from webcam)/ or how can i save the live video in a 'disk'

1 次查看(过去 30 天)
Greeting to the community, I am using matlab for image processing. anybody knows that how can i feed a pre-recorded video to the following code instead of live video(from webcam)?
I need to input pre-recroded video, or using live video but save the video in a folder first (using 'disk' instaed of 'memory') before proceeding the next stage (image processing).
a part of the code:
% Select video format
hws = imaqhwinfo ;
hw = imaqhwinfo(hws.InstalledAdaptors{end},1) ;
VideoFormat = hw.SupportedFormats;
% Select video format
hws = imaqhwinfo ;
hw = imaqhwinfo(hws.InstalledAdaptors{end},1) ;
VideoFormat = hw.SupportedFormats;
set(handles.text_vf, 'String', ['Video Format : ', 'YUY2_640x480']);
% set videoinput object
video = videoinput('winvideo',1,'YUY2_640x480');
set(video,'FramesPerTrigger',10);
set(video,'ReturnedColorSpace','grayscale');
set(video,'LoggingMode','memory');
triggerconfig(video,'immediate');
set(video,'FramesAcquiredFcnCount', 3);
set(video,'FramesAcquiredFcn', {@FramesAcquiredFcn,hObject});
% Preview UPDATE
vidRes = get(video, 'VideoResolution');
vidWin = image(zeros(vidRes(2), vidRes(1)),'Parent',handles.Preview);
preview(video,vidWin);

回答(1 个)

Mohammad Sami
Mohammad Sami 2020-9-4
You can use the VideoReader to read a video file.
v = VideoReader('xylophone.mp4');
while hasFrame(v)
frame = readFrame(v);
end
  2 个评论
Koohyar
Koohyar 2020-9-4
编辑:Koohyar 2020-9-4
Hi Mohammad, thanks for your suggestion. Unfortunetly it shows error! I imported the video from the Image Acquisition Tool, and saved in in the directory (.mp4), but it shows error when I call the video (based on your advice), as below:
Error using VideoReader/get
Property VideoResolution not found in class VideoReader, or is not present in all elements of the array of class VideoReader
Any advice you could give would be much appreciated!
thanks
Mohammad Sami
Mohammad Sami 2020-9-5
Video reader class does any property video Resolution. If you want resolution you will have to get Height and width properties.
Documentation of video reader is available here
https://www.mathworks.com/help/matlab/ref/videoreader.html

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by