Controlling the frame rate of a image acquisition program in MATLAB.

19 views (last 30 days)
vid = videoinput('winvideo', 1, 'RGB24_320x240'); %select input device
hvpc = vision.VideoPlayer; %create video player object
src = getselectedsource(vid);
vid.FramesPerTrigger =1;
vid.TriggerRepeat = Inf;
vid.ReturnedColorspace = 'rgb';
src.FrameRate = '30';
start(vid)
%start main loop for image acquisition
for t=1:500
imgO=getdata(vid,1,'uint8'); %get image from camera
hvpc.step(imgO); %see current image in player
end
Alright, so I got this code from some place from a guy named Jorge. I went in and put my codes into my codes to have the high frame per second so that the video acquisition of my program will be faster. However, I have encountered some problems:
What does this means and how do I solve this problem? Thank you very much.
Regards,
Akira

Accepted Answer

Sanket Mishra
Sanket Mishra on 11 Jul 2014
The error message on your machine is caused by the delay between the device and MATLAB, which is not a constant value and this related to your system and device driver. This is the reason why it happens at random iterations. Due to the delay, there are no available frames when the time exceeds the Timeout value. To ensure that you are getting data from the camera, you have two options:
1. Setting a larger Timeout value for the object
set(vid,'Timeout',50); %set the Timeout property of VIDEOINPUT object 'vid' to 50 seconds
2. Before GETDATA, wait until there's an available frame
while get(vid,'FramesAvailable')<1 %Wait until at least 1 frame is available
unavailable=1;
end
  1 Comment
pb
pb on 14 Nov 2021
Sanket, going to take a stab at commenting here in case you still get a notification from this thread. Could you advise - what exactly is the difference between a video source and a video input object? I read this - https://www.mathworks.com/help/imaq/accessing-devices-and-video-sources.html, and it seems that video input is the device itself - but the way Matlab is set up is that you cannot make changes to the device's properties, it must be made to the device "source." I guess there might be devices out there, as is shown in that example, that have multiple sources? (I haven't wrapped my head around this yet as I haven't seen that).
Also, how come in Matlab's method of accessing webcam one doesn't get all the properties they get, for example, by running the code in this question? See below
cam = webcam(1) %this is what I am referring to, creating a webcam connection like this

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!