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

조회 수: 9 (최근 30일)
Akira Chan
Akira Chan 2014년 5월 10일
댓글: pb 2021년 11월 14일
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

채택된 답변

Sanket Mishra
Sanket Mishra 2014년 7월 11일
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
pb
pb 2021년 11월 14일
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

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

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by